@sap_oss/wdio-qmate-service 2.7.2 → 2.7.3

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 (77) hide show
  1. package/docs/sections/bestPractices/selectors.md +1 -1
  2. package/docs/sections/features/selectors.md +2 -2
  3. package/lib/index.js.map +1 -1
  4. package/lib/reuse/authenticator/authHandler.js.map +1 -1
  5. package/lib/reuse/authenticator/basicUrlAuthenticator.js.map +1 -1
  6. package/lib/reuse/authenticator/customAuthenticator.js.map +1 -1
  7. package/lib/reuse/authenticator/formAuthenticator.js.map +1 -1
  8. package/lib/reuse/authenticator/plainAuthenticator.js.map +1 -1
  9. package/lib/reuse/helper/clientsideUI5scripts.js.map +1 -1
  10. package/lib/reuse/helper/elementHighlight.js.map +1 -1
  11. package/lib/reuse/helper/elementResolving.js.map +1 -1
  12. package/lib/reuse/helper/errorHandler.js.map +1 -1
  13. package/lib/reuse/helper/inputValidation.js.map +1 -1
  14. package/lib/reuse/helper/jsDocGen.js.map +1 -1
  15. package/lib/reuse/helper/jsonDocGen.js.map +1 -1
  16. package/lib/reuse/modules/common/constants/date.constants.js +1 -1
  17. package/lib/reuse/modules/common/constants/date.constants.js.map +1 -1
  18. package/lib/reuse/modules/common/constants/userInteraction.constants.js +1 -1
  19. package/lib/reuse/modules/common/constants/userInteraction.constants.js.map +1 -1
  20. package/lib/reuse/modules/common/date.js.map +1 -1
  21. package/lib/reuse/modules/common/navigation.js.map +1 -1
  22. package/lib/reuse/modules/common/userInteraction.js.map +1 -1
  23. package/lib/reuse/modules/nonUi5/assertion.js.map +1 -1
  24. package/lib/reuse/modules/nonUi5/element.js.map +1 -1
  25. package/lib/reuse/modules/nonUi5/navigation.js.map +1 -1
  26. package/lib/reuse/modules/nonUi5/session.js.map +1 -1
  27. package/lib/reuse/modules/nonUi5/userInteraction.js.map +1 -1
  28. package/lib/reuse/modules/service/odata.d.ts +74 -48
  29. package/lib/reuse/modules/service/odata.js +167 -134
  30. package/lib/reuse/modules/service/odata.js.map +1 -1
  31. package/lib/reuse/modules/service/rest.js.map +1 -1
  32. package/lib/reuse/modules/ui5/assertion.js +9 -0
  33. package/lib/reuse/modules/ui5/assertion.js.map +1 -1
  34. package/lib/reuse/modules/ui5/constants/mockserver.constants.js +1 -1
  35. package/lib/reuse/modules/ui5/constants/mockserver.constants.js.map +1 -1
  36. package/lib/reuse/modules/ui5/control.js.map +1 -1
  37. package/lib/reuse/modules/ui5/date.d.ts +1 -1
  38. package/lib/reuse/modules/ui5/date.js +1 -1
  39. package/lib/reuse/modules/ui5/date.js.map +1 -1
  40. package/lib/reuse/modules/ui5/element.js.map +1 -1
  41. package/lib/reuse/modules/ui5/mockserver.js.map +1 -1
  42. package/lib/reuse/modules/ui5/navigation.js.map +1 -1
  43. package/lib/reuse/modules/ui5/navigationBar.js.map +1 -1
  44. package/lib/reuse/modules/ui5/qunit.js.map +1 -1
  45. package/lib/reuse/modules/ui5/session.js.map +1 -1
  46. package/lib/reuse/modules/ui5/table.js.map +1 -1
  47. package/lib/reuse/modules/ui5/userInteraction.js.map +1 -1
  48. package/lib/reuse/modules/util/browser.js.map +1 -1
  49. package/lib/reuse/modules/util/component.js.map +1 -1
  50. package/lib/reuse/modules/util/console.js.map +1 -1
  51. package/lib/reuse/modules/util/constants/formatter.constants.js +1 -1
  52. package/lib/reuse/modules/util/constants/formatter.constants.js.map +1 -1
  53. package/lib/reuse/modules/util/data.js.map +1 -1
  54. package/lib/reuse/modules/util/file.js.map +1 -1
  55. package/lib/reuse/modules/util/formatter.js.map +1 -1
  56. package/lib/reuse/modules/util/function.js.map +1 -1
  57. package/lib/reuse/modules/util/system.js.map +1 -1
  58. package/lib/reuse/runner/runner.js.map +1 -1
  59. package/lib/scripts/clientsideUI5scripts.js.map +1 -1
  60. package/lib/scripts/dataExchange/dataExchange.js.map +1 -1
  61. package/lib/scripts/dataExchange/dataExchangeUtil.js.map +1 -1
  62. package/lib/scripts/hooks/beforeSession.js.map +1 -1
  63. package/lib/scripts/hooks/onPrepare.js.map +1 -1
  64. package/lib/scripts/hooks/utils/addLocatorCommands.js.map +1 -1
  65. package/lib/scripts/hooks/utils/browserLog.js.map +1 -1
  66. package/lib/scripts/hooks/utils/cycle.js.map +1 -1
  67. package/lib/scripts/hooks/utils/dataExchangeCommands.js.map +1 -1
  68. package/lib/scripts/hooks/utils/decryption.js.map +1 -1
  69. package/lib/scripts/hooks/utils/lib.js.map +1 -1
  70. package/lib/scripts/hooks/utils/locatorCommands.js.map +1 -1
  71. package/lib/scripts/locators/qmateLocator.js.map +1 -1
  72. package/lib/scripts/locators/uiveri5Locator.js.map +1 -1
  73. package/package.json +12 -12
  74. package/test/reuse/service/odata/get.spec.js +4 -10
  75. package/test/reuse/service/odata/getEntitySet.spec.js +2 -8
  76. package/test/reuse/util/browser/getBrowserName.spec.js +1 -1
  77. package/tsconfig.json +0 -1
@@ -1,3 +1,9 @@
1
+ interface IHeaders {
2
+ [key: string]: string;
3
+ }
4
+ interface IParams {
5
+ [key: string]: string;
6
+ }
1
7
  /**
2
8
  * @class odata
3
9
  * @memberof service
@@ -11,48 +17,58 @@ export declare class OData {
11
17
  /**
12
18
  * @function init
13
19
  * @memberOf service.odata
14
- * @description Initializes The service to work with.
20
+ * @description Initializes the OData Service.
15
21
  * XCSRF-Token will be automatically fetched and stored in the service instance.
16
22
  * Cookies will also automatically assembled and stored in the service instance.
17
- * @param {String} url - The base url of the service
18
- * @param {String} username - The username.
23
+ * @param {String} url - The base url of the service.
24
+ * @param {String} username - The username to authenticate the service.
19
25
  * @param {String} password - The password of the username.
20
- * @param {boolean} [loggingEnabled=false] - The boolean param to control whether user wants to see logs during build run
21
- * @param {Object} [params={}] - JSON object with key-value pairs of parameter names and corresponding values
22
- * by default we send {
26
+ * @param {Boolean} [loggingEnabled=false] - The boolean param to control whether user wants to see logs during build run.
27
+ * @param {Object} [params={}] - JSON object with key-value pairs of parameter names and corresponding values.
28
+ * By default we send {
23
29
  * "client": "715",
24
30
  * "documentation": ["heading", "quickinfo"],
25
31
  * "language": "EN"
26
32
  * }
27
- * These can be overridden by sending params as JSON object with additional params as shown in example
33
+ * These can be overridden by sending params as JSON object with additional params as shown in example.
28
34
  * @param {String} [authType] - authentication type, in case you want to override the default
29
35
  * SAML authentication. Set this to "basic", to use basic authentication for communication users for whom SAML login doesn't work.
30
36
  * Or "none" for no authentication.
37
+ * @param {Object} [headers=undefined] - JSON object with key-value pairs of optional headers.
31
38
  * @returns {Object} The initialized service object.
32
39
  * @example const url = "<urlToSystem>/sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/";
33
40
  * const params = {
34
41
  * "saml2": "disabled",
35
42
  * "language": "de"
36
43
  * }
37
- * srv = await service.odata.init(url, user, password, false, params);
44
+ * const srv = await service.odata.init(url, user, password, false, params);
45
+ * @example const base64Credentials = Buffer.from(`${user}:${password}`).toString("base64");
46
+ * const authHeaders = {
47
+ * "Authorization": `Basic ${base64Credentials}`,
48
+ * "DwC-Tenant": tenant
49
+ * };
50
+ *
51
+ * const srv = await service.odata.init(url, user, password, true, params, "headers", authHeaders);
38
52
  */
39
- init(url: string, username: string, password: string, loggingEnabled?: boolean, params?: {}, authType?: string): Promise<any>;
53
+ init(url: string, username: string, password: string, loggingEnabled?: boolean, params?: {}, authType?: string, headers?: any): Promise<any>;
40
54
  /**
41
55
  * @function get
42
56
  * @memberOf service.odata
43
- * @description makes a GET request.
44
- * @param {Object} srv - Instance of the service
45
- * @param {String} entitySet - The entitySet you want to GET from.
46
- * @param {Object} keys - The required keys for the GET-request.
47
- * @param {Boolean} raw - Response includes all header contents.
57
+ * @description Sends a GET request to retrieve data from the specified OData entity set.
58
+ * @param {Object} srv - An instance of the service.
59
+ * @param {String} entitySet - The entity set from which data is to be retrieved.
60
+ * @param {Object} keys - The required keys for the GET request.
61
+ * @param {Boolean} [raw=false] - Specifies whether the response should include all header contents.
62
+ * @param {Object} [headers] - Optional headers to be included in the request.
63
+ * @returns {Promise} A Promise that resolves to the response data.
48
64
  * @example const url = "<baseUrl>/sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/";
49
- * srv = await service.odata.init(url, user, password);
65
+ * const srv = await service.odata.init(url, user, password);
50
66
  * const keys = {
51
67
  * PurchaseOrder: "4100000000"
52
68
  * };
53
69
  * const res = await service.odata.get(srv, "A_PurchaseOrder", keys);
54
70
  */
55
- get(srv: any, entitySet: string, keys: any, raw?: boolean): Promise<any>;
71
+ get(srv: any, entitySet: string, keys: any, raw?: boolean, headers?: IHeaders): Promise<any>;
56
72
  /**
57
73
  * @function getEntitySet
58
74
  * @memberOf service.odata
@@ -62,7 +78,7 @@ export declare class OData {
62
78
  * @param {String} [filterString] - The filters to be applied on get query
63
79
  * @param {String} [selectionFields] - comma separated list of fields to be selected
64
80
  * @param {Object} [queryParams] - JSON object of key value pairs of custom query parameters.
65
- * @returns {Array} - Result set array
81
+ * @returns {Promise} A Promise that resolves to the response data.
66
82
  * @example
67
83
  * const url = "<baseUrl>/sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/";
68
84
  * srv = await service.odata.init(url, user, password);
@@ -80,73 +96,69 @@ export declare class OData {
80
96
  * let res = await service.odata.getEntitySet(srv, "A_PurchaseOrder", filterString, select, queryParams);
81
97
  */
82
98
  getEntitySet(srv: any, entitySet: string, filterString?: string, selectionFields?: string, queryParams?: any): Promise<any>;
83
- /**
84
- * @function isFeatureToggleActivated
85
- * @memberOf service.odata
86
- * @description checks if a feature toggle is switched on or off
87
- * @param {Object} srv - Instance of the service
88
- * @param {String} featureName - The name of the feature you want know the status of.
89
- * @example const url = browser.params.systemUrl + "/sap/opu/odata/SAP/CA_FM_FEATURE_TOGGLE_STATUS_SRV/";
90
- * const srv = await service.odata.init(url, user, password);
91
- * let isFeatureActive = await service.odata.isFeatureToggleActivated(srv, "MM_PUR_PO_BATCHES_IN_MANAGE_PO");
92
- */
93
- isFeatureToggleActivated(srv: any, featureName: string): Promise<boolean>;
94
99
  /**
95
100
  * @function post
96
101
  * @memberOf service.odata
97
- * @description makes a POST request.
102
+ * @description Sends a POST request to retrieve data from the specified OData entity set for the given payload.
98
103
  * @param {Object} srv - Instance of the service
99
104
  * @param {String} entitySet - The entitySet you want to POST against.
100
- * @param {Object} payload - The payload for the POST-request.
101
- * @param {Boolean} raw - Response includes all header contents.
105
+ * @param {Object} payload - The payload of the POST request.
106
+ * @param {Boolean} [raw=false] - Specifies whether the response should include all header contents.
107
+ * @param {Object} [headers] - Optional headers to be included in the request.
108
+ * @returns {Promise} A Promise that resolves to the response data.
102
109
  * @example
103
- * let payload = {
110
+ * const payload = {
104
111
  * "PurchaseOrder": "4500007108",
105
112
  * "DraftUUID": "00000000-0000-0000-0000-000000000000",
106
113
  * "IsActiveEntity": "true"
107
114
  * };
108
- * let res = await service.odata.post(srv, "A_PurchaseOrder", payload);
115
+ * const res = await service.odata.post(srv, "A_PurchaseOrder", payload);
109
116
  */
110
- post(srv: any, entitySet: string, payload: any, raw?: boolean): Promise<any>;
117
+ post(srv: any, entitySet: string, payload: any, raw?: boolean, headers?: IHeaders): Promise<any>;
111
118
  /**
112
119
  * @function merge
113
120
  * @memberOf service.odata
114
- * @description makes a MERGE request.
121
+ * @description @description Sends a MERGE request to merge data from the specified OData entity set for the given payload.
115
122
  * @param {Object} srv - Instance of the service
116
123
  * @param {String} entitySet - The entitySet you want to MERGE in.
117
- * @param {Object} payload - The payload for the MERGE-request.
124
+ * @param {Object} payload - The payload of the MERGE request.
125
+ * @param {Object} [headers] - Optional headers to be included in the request.
126
+ * @returns {Promise} A Promise that resolves to the response data.
118
127
  * @example
119
- * let res = await service.odata.merge(srv, "A_PurchaseOrderScheduleLine", {
128
+ * const res = await service.odata.merge(srv, "A_PurchaseOrderScheduleLine", {
120
129
  * "PurchasingDocument": "4500007108",
121
130
  * "PurchasingDocumentItem": "10",
122
131
  * "ScheduleLine": "1",
123
132
  * "ScheduleLineDeliveryDate": new Date()
124
133
  * };
125
134
  */
126
- merge(srv: any, entitySet: string, payload: any): Promise<any>;
135
+ merge(srv: any, entitySet: string, payload: any, headers?: IHeaders): Promise<any>;
127
136
  /**
128
137
  * @function delete
129
138
  * @memberOf service.odata
130
- * @description makes a DELETE request.
131
- * @param {Object} srv - Instance of the service
139
+ * @description Sends a DELETE request to the specified OData entity set.
140
+ * @param {Object} srv - Instance of the service.
132
141
  * @param {String} entitySet - The entitySet you want to DELETE.
133
- * @param {Object} options - The options for the DELETE-request.
142
+ * @param {Object} options - The options for the DELETE request.
143
+ * @param {Object} [headers] - Optional headers to be included in the request.
144
+ * @returns {Promise} A Promise that resolves to the response data.
134
145
  * @example
135
- * let options = {
146
+ * const options = {
136
147
  * "PurchaseOrder": "",
137
148
  * "DraftUUID": draftUUID,
138
149
  * "IsActiveEntity": false
139
150
  * };
140
- * await service.odata.delete(srv, "C_PurchaseOrderTP", options);
151
+ * const res = await service.odata.delete(srv, "C_PurchaseOrderTP", options);
141
152
  */
142
- delete(srv: any, entitySet: string, options: any): Promise<any>;
153
+ delete(srv: any, entitySet: string, options: any, headers?: IHeaders): Promise<any>;
143
154
  /**
144
155
  * @function callFunctionImport
145
156
  * @memberOf service.odata
146
- * @description makes a function import request on an OData service.
147
- * @param {Object} srv - Instance of the service
148
- * @param {String} functionImportName - Name of Function Import
149
- * @param {Object} options - parameters for function import
157
+ * @description Sends a function import request to the OData service instance.
158
+ * @param {Object} srv - Instance of the service.
159
+ * @param {String} functionImportName - Name of Function Import.
160
+ * @param {Object} options - Parameters for function import.
161
+ * @returns {Promise} A Promise that resolves to the response data.
150
162
  * @example
151
163
  * const options = {
152
164
  * CentralRequestForQuotation : "7500000026",
@@ -155,6 +167,18 @@ export declare class OData {
155
167
  * const res = await service.odata.callFunctionImport(srv, "Cancel", options);
156
168
  */
157
169
  callFunctionImport(srv: any, functionImportName: string, options: any): Promise<any>;
170
+ /**
171
+ * @function isFeatureToggleActivated
172
+ * @memberOf service.odata
173
+ * @description Checks if a feature toggle is switched on or off.
174
+ * @param {Object} srv - Instance of the service
175
+ * @param {String} featureName - The name of the feature you want know the status of.
176
+ * @returns {Promise} A Promise that resolves to a bool value.
177
+ * @example const url = browser.params.systemUrl + "/sap/opu/odata/SAP/CA_FM_FEATURE_TOGGLE_STATUS_SRV/";
178
+ * const srv = await service.odata.init(url, user, password);
179
+ * let isFeatureActive = await service.odata.isFeatureToggleActivated(srv, "MM_PUR_PO_BATCHES_IN_MANAGE_PO");
180
+ */
181
+ isFeatureToggleActivated(srv: any, featureName: string): Promise<boolean>;
158
182
  /**
159
183
  * @function getOutputManagementPdfStream
160
184
  * @memberOf service.odata
@@ -186,6 +210,8 @@ export declare class OData {
186
210
  */
187
211
  readPdfFromDirectUrl(url: string, username: string, password: string, isSaml?: boolean): Promise<any>;
188
212
  _doRequest(url: string, username: string, password: string, isSaml: boolean): Promise<any>;
213
+ _applyHeaders(entity: any, headers: IHeaders): any;
214
+ _applyQueryParameters(entity: any, params: IParams): any;
189
215
  }
190
216
  declare const _default: OData;
191
217
  export default _default;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OData = void 0;
4
+ // =================================== CONSTANTS ================================
5
+ const SERVICE_INIT_ERROR = "Service instance not found. Make sure the service is initialized and passed to the request.";
6
+ const entitySetError = (entitySet) => `Entity Set "${entitySet}" not found in service.`;
7
+ // =================================== MAIN =====================================
4
8
  /**
5
9
  * @class odata
6
10
  * @memberof service
@@ -20,32 +24,40 @@ class OData {
20
24
  /**
21
25
  * @function init
22
26
  * @memberOf service.odata
23
- * @description Initializes The service to work with.
27
+ * @description Initializes the OData Service.
24
28
  * XCSRF-Token will be automatically fetched and stored in the service instance.
25
29
  * Cookies will also automatically assembled and stored in the service instance.
26
- * @param {String} url - The base url of the service
27
- * @param {String} username - The username.
30
+ * @param {String} url - The base url of the service.
31
+ * @param {String} username - The username to authenticate the service.
28
32
  * @param {String} password - The password of the username.
29
- * @param {boolean} [loggingEnabled=false] - The boolean param to control whether user wants to see logs during build run
30
- * @param {Object} [params={}] - JSON object with key-value pairs of parameter names and corresponding values
31
- * by default we send {
33
+ * @param {Boolean} [loggingEnabled=false] - The boolean param to control whether user wants to see logs during build run.
34
+ * @param {Object} [params={}] - JSON object with key-value pairs of parameter names and corresponding values.
35
+ * By default we send {
32
36
  * "client": "715",
33
37
  * "documentation": ["heading", "quickinfo"],
34
38
  * "language": "EN"
35
39
  * }
36
- * These can be overridden by sending params as JSON object with additional params as shown in example
40
+ * These can be overridden by sending params as JSON object with additional params as shown in example.
37
41
  * @param {String} [authType] - authentication type, in case you want to override the default
38
42
  * SAML authentication. Set this to "basic", to use basic authentication for communication users for whom SAML login doesn't work.
39
43
  * Or "none" for no authentication.
44
+ * @param {Object} [headers=undefined] - JSON object with key-value pairs of optional headers.
40
45
  * @returns {Object} The initialized service object.
41
46
  * @example const url = "<urlToSystem>/sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/";
42
47
  * const params = {
43
48
  * "saml2": "disabled",
44
49
  * "language": "de"
45
50
  * }
46
- * srv = await service.odata.init(url, user, password, false, params);
51
+ * const srv = await service.odata.init(url, user, password, false, params);
52
+ * @example const base64Credentials = Buffer.from(`${user}:${password}`).toString("base64");
53
+ * const authHeaders = {
54
+ * "Authorization": `Basic ${base64Credentials}`,
55
+ * "DwC-Tenant": tenant
56
+ * };
57
+ *
58
+ * const srv = await service.odata.init(url, user, password, true, params, "headers", authHeaders);
47
59
  */
48
- async init(url, username, password, loggingEnabled = false, params = {}, authType = "") {
60
+ async init(url, username, password, loggingEnabled = false, params = {}, authType = "", headers) {
49
61
  const logger = {
50
62
  trace: () => { },
51
63
  debug: console.debug,
@@ -54,26 +66,25 @@ class OData {
54
66
  error: console.error
55
67
  };
56
68
  const parameters = {
57
- "sap-client": "715",
58
- "sap-documentation": ["heading", "quickinfo"],
59
- "sap-language": "EN"
69
+ ...params,
70
+ ...{
71
+ "sap-client": "715",
72
+ "sap-documentation": ["heading", "quickinfo"],
73
+ "sap-language": "EN"
74
+ }
60
75
  };
61
- if (params) {
62
- // @ts-ignore
63
- Object.keys(params).forEach((key) => (parameters[key] = params[key]));
64
- }
65
76
  const auth = {
66
- username: username,
67
- password: password
77
+ type: authType ?? "",
78
+ username,
79
+ password
68
80
  };
69
- if (authType) {
70
- auth["type"] = authType;
71
- }
81
+ if (headers && Object.entries(headers).length > 0)
82
+ auth.headers = headers;
72
83
  const srv = new this.Service({
73
84
  logger: loggingEnabled ? logger : "",
74
- url: url,
75
- auth: auth,
76
- parameters: parameters,
85
+ url,
86
+ auth,
87
+ parameters, // Define initial request by $metadata?sap-client=<client-number>&sap-documentation=&sap-language=EN
77
88
  strict: false // ignore non critical errors, e.g. orphaned annotations
78
89
  });
79
90
  await srv.init;
@@ -82,31 +93,37 @@ class OData {
82
93
  /**
83
94
  * @function get
84
95
  * @memberOf service.odata
85
- * @description makes a GET request.
86
- * @param {Object} srv - Instance of the service
87
- * @param {String} entitySet - The entitySet you want to GET from.
88
- * @param {Object} keys - The required keys for the GET-request.
89
- * @param {Boolean} raw - Response includes all header contents.
96
+ * @description Sends a GET request to retrieve data from the specified OData entity set.
97
+ * @param {Object} srv - An instance of the service.
98
+ * @param {String} entitySet - The entity set from which data is to be retrieved.
99
+ * @param {Object} keys - The required keys for the GET request.
100
+ * @param {Boolean} [raw=false] - Specifies whether the response should include all header contents.
101
+ * @param {Object} [headers] - Optional headers to be included in the request.
102
+ * @returns {Promise} A Promise that resolves to the response data.
90
103
  * @example const url = "<baseUrl>/sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/";
91
- * srv = await service.odata.init(url, user, password);
104
+ * const srv = await service.odata.init(url, user, password);
92
105
  * const keys = {
93
106
  * PurchaseOrder: "4100000000"
94
107
  * };
95
108
  * const res = await service.odata.get(srv, "A_PurchaseOrder", keys);
96
109
  */
97
- async get(srv, entitySet, keys, raw = false) {
98
- const entity = srv[entitySet];
99
- if (!entity) {
100
- throw new Error(`No entity set '${entitySet}' available in service`);
101
- }
102
- if (raw === true) {
103
- return entity.raw().get(keys);
110
+ async get(srv, entitySet, keys, raw = false, headers) {
111
+ if (!srv)
112
+ throw new Error(SERVICE_INIT_ERROR);
113
+ let entity = srv[entitySet];
114
+ if (!entity)
115
+ throw new Error(entitySetError(entitySet));
116
+ if (headers)
117
+ entity = this._applyHeaders(entity, headers);
118
+ if (raw)
119
+ entity = entity.raw();
120
+ if (keys && Object.entries(keys).length > 0) {
121
+ return entity.get(keys);
104
122
  }
105
123
  else {
106
- return entity.get(keys);
124
+ return entity.get();
107
125
  }
108
126
  }
109
- ;
110
127
  /**
111
128
  * @function getEntitySet
112
129
  * @memberOf service.odata
@@ -116,7 +133,7 @@ class OData {
116
133
  * @param {String} [filterString] - The filters to be applied on get query
117
134
  * @param {String} [selectionFields] - comma separated list of fields to be selected
118
135
  * @param {Object} [queryParams] - JSON object of key value pairs of custom query parameters.
119
- * @returns {Array} - Result set array
136
+ * @returns {Promise} A Promise that resolves to the response data.
120
137
  * @example
121
138
  * const url = "<baseUrl>/sap/opu/odata/sap/API_PURCHASEORDER_PROCESS_SRV/";
122
139
  * srv = await service.odata.init(url, user, password);
@@ -133,136 +150,112 @@ class OData {
133
150
  * };
134
151
  * let res = await service.odata.getEntitySet(srv, "A_PurchaseOrder", filterString, select, queryParams);
135
152
  */
136
- async getEntitySet(srv, entitySet, filterString = "", selectionFields = "", queryParams = {}) {
137
- if (!srv) {
138
- throw new Error("Service is not defined. Please make sure to initialize and pass the service.");
139
- }
140
- else {
141
- let entity = srv[entitySet];
142
- if (!entity) {
143
- throw new Error(`No entity set '${entitySet}' available in service`);
144
- }
145
- if (filterString) {
146
- entity = entity.filter(filterString);
147
- }
148
- if (selectionFields) {
149
- entity = entity.select(selectionFields.split(","));
150
- }
151
- if (queryParams) {
152
- Object.keys(queryParams).forEach((key) => {
153
- entity = entity.queryParameter(key, queryParams[key]);
154
- });
155
- }
156
- const res = entity.get();
157
- return res;
158
- }
159
- }
160
- /**
161
- * @function isFeatureToggleActivated
162
- * @memberOf service.odata
163
- * @description checks if a feature toggle is switched on or off
164
- * @param {Object} srv - Instance of the service
165
- * @param {String} featureName - The name of the feature you want know the status of.
166
- * @example const url = browser.params.systemUrl + "/sap/opu/odata/SAP/CA_FM_FEATURE_TOGGLE_STATUS_SRV/";
167
- * const srv = await service.odata.init(url, user, password);
168
- * let isFeatureActive = await service.odata.isFeatureToggleActivated(srv, "MM_PUR_PO_BATCHES_IN_MANAGE_PO");
169
- */
170
- async isFeatureToggleActivated(srv, featureName) {
171
- const res = await this.getEntitySet(srv, "ToggleStatusSet");
172
- for (const featureEntity of Object.values(res)) {
173
- // @ts-ignore
174
- if (featureEntity.Featureid === featureName) {
175
- //feature toggle is disabled if found
176
- util.console.info(`Feature Toggle "${featureName}" is disabled.`);
177
- return false;
178
- }
179
- }
180
- //feature toggle is enabled if NOT found
181
- util.console.info(`Feature Toggle "${featureName}" is enabled.`);
182
- return true;
153
+ async getEntitySet(srv, entitySet, filterString = "", selectionFields = "", queryParams) {
154
+ if (!srv)
155
+ throw new Error(SERVICE_INIT_ERROR);
156
+ let entity = srv[entitySet];
157
+ if (!entity)
158
+ throw new Error(entitySetError(entitySet));
159
+ if (filterString)
160
+ entity = entity.filter(filterString);
161
+ if (selectionFields)
162
+ entity = entity.select(selectionFields.split(","));
163
+ if (queryParams)
164
+ entity = this._applyQueryParameters(entity, queryParams);
165
+ return entity.get();
183
166
  }
184
167
  /**
185
168
  * @function post
186
169
  * @memberOf service.odata
187
- * @description makes a POST request.
170
+ * @description Sends a POST request to retrieve data from the specified OData entity set for the given payload.
188
171
  * @param {Object} srv - Instance of the service
189
172
  * @param {String} entitySet - The entitySet you want to POST against.
190
- * @param {Object} payload - The payload for the POST-request.
191
- * @param {Boolean} raw - Response includes all header contents.
173
+ * @param {Object} payload - The payload of the POST request.
174
+ * @param {Boolean} [raw=false] - Specifies whether the response should include all header contents.
175
+ * @param {Object} [headers] - Optional headers to be included in the request.
176
+ * @returns {Promise} A Promise that resolves to the response data.
192
177
  * @example
193
- * let payload = {
178
+ * const payload = {
194
179
  * "PurchaseOrder": "4500007108",
195
180
  * "DraftUUID": "00000000-0000-0000-0000-000000000000",
196
181
  * "IsActiveEntity": "true"
197
182
  * };
198
- * let res = await service.odata.post(srv, "A_PurchaseOrder", payload);
183
+ * const res = await service.odata.post(srv, "A_PurchaseOrder", payload);
199
184
  */
200
- async post(srv, entitySet, payload, raw = false) {
201
- const entity = srv[entitySet];
202
- if (!entity) {
203
- throw new Error(`No entity set '${entitySet}' available in service`);
204
- }
205
- if (raw === true) {
206
- return entity.raw().post(payload);
207
- }
208
- else {
209
- return entity.post(payload);
210
- }
185
+ async post(srv, entitySet, payload, raw = false, headers) {
186
+ if (!srv)
187
+ throw new Error(SERVICE_INIT_ERROR);
188
+ let entity = srv[entitySet];
189
+ if (!entity)
190
+ throw new Error(entitySetError(entitySet));
191
+ if (headers)
192
+ entity = this._applyHeaders(entity, headers);
193
+ if (raw)
194
+ entity = entity.raw();
195
+ return entity.post(payload);
211
196
  }
212
- ;
213
197
  /**
214
198
  * @function merge
215
199
  * @memberOf service.odata
216
- * @description makes a MERGE request.
200
+ * @description @description Sends a MERGE request to merge data from the specified OData entity set for the given payload.
217
201
  * @param {Object} srv - Instance of the service
218
202
  * @param {String} entitySet - The entitySet you want to MERGE in.
219
- * @param {Object} payload - The payload for the MERGE-request.
203
+ * @param {Object} payload - The payload of the MERGE request.
204
+ * @param {Object} [headers] - Optional headers to be included in the request.
205
+ * @returns {Promise} A Promise that resolves to the response data.
220
206
  * @example
221
- * let res = await service.odata.merge(srv, "A_PurchaseOrderScheduleLine", {
207
+ * const res = await service.odata.merge(srv, "A_PurchaseOrderScheduleLine", {
222
208
  * "PurchasingDocument": "4500007108",
223
209
  * "PurchasingDocumentItem": "10",
224
210
  * "ScheduleLine": "1",
225
211
  * "ScheduleLineDeliveryDate": new Date()
226
212
  * };
227
213
  */
228
- async merge(srv, entitySet, payload) {
229
- const entity = srv[entitySet];
230
- if (!entity) {
231
- throw new Error(`No entity set '${entitySet}' available in service`);
232
- }
233
- const res = await entity.merge(payload);
234
- return res;
214
+ async merge(srv, entitySet, payload, headers) {
215
+ if (!srv)
216
+ throw new Error(SERVICE_INIT_ERROR);
217
+ let entity = srv[entitySet];
218
+ if (!entity)
219
+ throw new Error(entitySetError(entitySet));
220
+ if (headers)
221
+ entity = this._applyHeaders(entity, headers);
222
+ return await entity.merge(payload);
235
223
  }
236
224
  /**
237
225
  * @function delete
238
226
  * @memberOf service.odata
239
- * @description makes a DELETE request.
240
- * @param {Object} srv - Instance of the service
227
+ * @description Sends a DELETE request to the specified OData entity set.
228
+ * @param {Object} srv - Instance of the service.
241
229
  * @param {String} entitySet - The entitySet you want to DELETE.
242
- * @param {Object} options - The options for the DELETE-request.
230
+ * @param {Object} options - The options for the DELETE request.
231
+ * @param {Object} [headers] - Optional headers to be included in the request.
232
+ * @returns {Promise} A Promise that resolves to the response data.
243
233
  * @example
244
- * let options = {
234
+ * const options = {
245
235
  * "PurchaseOrder": "",
246
236
  * "DraftUUID": draftUUID,
247
237
  * "IsActiveEntity": false
248
238
  * };
249
- * await service.odata.delete(srv, "C_PurchaseOrderTP", options);
239
+ * const res = await service.odata.delete(srv, "C_PurchaseOrderTP", options);
250
240
  */
251
- async delete(srv, entitySet, options) {
252
- const entity = srv[entitySet];
253
- if (!entity) {
254
- throw new Error(`No entity set '${entitySet}' available in service`);
255
- }
256
- const res = await entity.delete(options);
257
- return res;
241
+ async delete(srv, entitySet, options, headers) {
242
+ if (!srv)
243
+ throw new Error(SERVICE_INIT_ERROR);
244
+ let entity = srv[entitySet];
245
+ if (!entity)
246
+ throw new Error(entitySetError(entitySet));
247
+ if (headers)
248
+ entity = this._applyHeaders(entity, headers);
249
+ return await entity.delete(options);
258
250
  }
259
251
  /**
260
252
  * @function callFunctionImport
261
253
  * @memberOf service.odata
262
- * @description makes a function import request on an OData service.
263
- * @param {Object} srv - Instance of the service
264
- * @param {String} functionImportName - Name of Function Import
265
- * @param {Object} options - parameters for function import
254
+ * @description Sends a function import request to the OData service instance.
255
+ * @param {Object} srv - Instance of the service.
256
+ * @param {String} functionImportName - Name of Function Import.
257
+ * @param {Object} options - Parameters for function import.
258
+ * @returns {Promise} A Promise that resolves to the response data.
266
259
  * @example
267
260
  * const options = {
268
261
  * CentralRequestForQuotation : "7500000026",
@@ -271,10 +264,39 @@ class OData {
271
264
  * const res = await service.odata.callFunctionImport(srv, "Cancel", options);
272
265
  */
273
266
  async callFunctionImport(srv, functionImportName, options) {
267
+ if (!srv)
268
+ throw new Error(SERVICE_INIT_ERROR);
274
269
  const functionImport = srv.functionImports[functionImportName];
275
- const res = await functionImport.call(options);
276
- return res;
270
+ return await functionImport.call(options);
277
271
  }
272
+ /**
273
+ * @function isFeatureToggleActivated
274
+ * @memberOf service.odata
275
+ * @description Checks if a feature toggle is switched on or off.
276
+ * @param {Object} srv - Instance of the service
277
+ * @param {String} featureName - The name of the feature you want know the status of.
278
+ * @returns {Promise} A Promise that resolves to a bool value.
279
+ * @example const url = browser.params.systemUrl + "/sap/opu/odata/SAP/CA_FM_FEATURE_TOGGLE_STATUS_SRV/";
280
+ * const srv = await service.odata.init(url, user, password);
281
+ * let isFeatureActive = await service.odata.isFeatureToggleActivated(srv, "MM_PUR_PO_BATCHES_IN_MANAGE_PO");
282
+ */
283
+ async isFeatureToggleActivated(srv, featureName) {
284
+ if (!srv)
285
+ throw new Error(SERVICE_INIT_ERROR);
286
+ const res = await this.getEntitySet(srv, "ToggleStatusSet");
287
+ for (const featureEntity of Object.values(res)) {
288
+ // @ts-ignore
289
+ if (featureEntity.Featureid === featureName) {
290
+ //feature toggle is disabled if found
291
+ util.console.info(`Feature Toggle "${featureName}" is disabled.`);
292
+ return false;
293
+ }
294
+ }
295
+ //feature toggle is enabled if NOT found
296
+ util.console.info(`Feature Toggle "${featureName}" is enabled.`);
297
+ return true;
298
+ }
299
+ // =================================== PDF ======================================
278
300
  /**
279
301
  * @function getOutputManagementPdfStream
280
302
  * @memberOf service.odata
@@ -317,8 +339,7 @@ class OData {
317
339
  if (url === undefined || url === null) {
318
340
  throw new Error("Function 'readPdfFromDirectUrl' Failed. Please provide valid url as first parameter");
319
341
  }
320
- const res = await this._doRequest(url, username, password, isSaml);
321
- return res;
342
+ return await this._doRequest(url, username, password, isSaml);
322
343
  }
323
344
  // =================================== HELPER ===================================
324
345
  async _doRequest(url, username, password, isSaml) {
@@ -364,6 +385,18 @@ class OData {
364
385
  });
365
386
  });
366
387
  }
388
+ _applyHeaders(entity, headers) {
389
+ for (const [key, value] of Object.entries(headers)) {
390
+ entity.header(key, value);
391
+ }
392
+ return entity;
393
+ }
394
+ _applyQueryParameters(entity, params) {
395
+ for (const [key, value] of Object.entries(params)) {
396
+ entity.queryParameter(key, value);
397
+ }
398
+ return entity;
399
+ }
367
400
  }
368
401
  exports.OData = OData;
369
402
  exports.default = new OData();