@cap-js/ord 1.3.6 → 1.3.7

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.
@@ -1,7 +1,7 @@
1
1
  const cds = require("@sap/cds");
2
2
  const { AUTHENTICATION_TYPE, BASIC_AUTH_HEADER_KEY, AUTH_TYPE_ORD_ACCESS_STRATEGY_MAP } = require("./constants");
3
3
  const { Logger } = require("./logger");
4
- const bcrypt = require("bcrypt");
4
+ const bcrypt = require("bcryptjs");
5
5
 
6
6
  /**
7
7
  * Compares a plain text password with a hashed password
package/lib/ord.js CHANGED
@@ -80,10 +80,7 @@ function _triageCsnDefinitions(csn) {
80
80
  const apiEndpoints = new Set();
81
81
  const pendingEventServiceNames = new Set();
82
82
  const entityTypeTargets = [];
83
- const pendingServiceNames = [];
84
- const serviceNames = Object.keys(csn.definitions).filter(
85
- (key) => csn.definitions[key].kind === CDS_ELEMENT_KIND.service,
86
- );
83
+ const serviceNames = Object.keys(csn.definitions).filter((key) => _isValidService(key, csn.definitions[key]));
87
84
 
88
85
  for (const definitionKey of Object.keys(csn.definitions)) {
89
86
  const definitionObj = csn.definitions[definitionKey];
@@ -91,12 +88,11 @@ function _triageCsnDefinitions(csn) {
91
88
  definitionKey.includes(BLOCKED_SERVICE_NAME.MTXServices) ||
92
89
  definitionKey.includes(BLOCKED_SERVICE_NAME.OpenResourceDiscoveryService)
93
90
  ) {
94
- Logger.warn(`ORD service name "${definitionKey}" is blocked.`);
91
+ Logger.warn("ORD service name", definitionKey, "is blocked.");
95
92
  continue;
96
93
  }
97
94
  switch (definitionObj.kind) {
98
95
  case CDS_ELEMENT_KIND.service: {
99
- pendingServiceNames.push(definitionKey);
100
96
  const apiResourceName = _handleApiResource(definitionKey, definitionObj);
101
97
  if (apiResourceName) pendingApiResourceNames.push(apiResourceName);
102
98
  break;
@@ -110,13 +106,13 @@ function _triageCsnDefinitions(csn) {
110
106
  break;
111
107
  }
112
108
  case CDS_ELEMENT_KIND.event: {
113
- const event = _handleEvent(serviceNames, definitionKey);
109
+ const event = _handleEvent(serviceNames, definitionKey, definitionObj);
114
110
  if (event) pendingEventServiceNames.add(event);
115
111
  break;
116
112
  }
117
113
  case CDS_ELEMENT_KIND.action:
118
114
  case CDS_ELEMENT_KIND.function: {
119
- const apiEndpoint = _handleActionOrFunction(definitionKey);
115
+ const apiEndpoint = _handleActionOrFunction(definitionKey, definitionObj);
120
116
  if (apiEndpoint) apiEndpoints.add(apiEndpoint);
121
117
  break;
122
118
  }
@@ -124,7 +120,7 @@ function _triageCsnDefinitions(csn) {
124
120
  }
125
121
 
126
122
  return {
127
- serviceNames: pendingServiceNames,
123
+ serviceNames,
128
124
  apiResourceNames: pendingApiResourceNames,
129
125
  apiEndpoints: Array.from(apiEndpoints),
130
126
  eventServiceNames: [...pendingEventServiceNames],
@@ -133,7 +129,10 @@ function _triageCsnDefinitions(csn) {
133
129
  }
134
130
 
135
131
  function _handleApiResource(apiResourceName, serviceDefinition) {
136
- if (_shouldSkipIfServiceOnlyContainsEvents(serviceDefinition) || serviceDefinition["@cds.external"]) {
132
+ if (
133
+ _shouldSkipIfServiceOnlyContainsEvents(serviceDefinition) ||
134
+ !_isValidService(apiResourceName, serviceDefinition)
135
+ ) {
137
136
  return null;
138
137
  }
139
138
  return apiResourceName;
@@ -151,8 +150,32 @@ function _shouldSkipIfServiceOnlyContainsEvents(serviceDefinition) {
151
150
  return false;
152
151
  }
153
152
 
153
+ function _shouldNotSkipIfServiceProtocolIsNone(keyDefinition) {
154
+ if (keyDefinition["_service"] && keyDefinition["_service"]["@protocol"] === "none") {
155
+ return false;
156
+ }
157
+ return true;
158
+ }
159
+
160
+ function _isBlockedServiceName(key) {
161
+ const blockedServices = [BLOCKED_SERVICE_NAME.MTXServices, BLOCKED_SERVICE_NAME.OpenResourceDiscoveryService];
162
+ return blockedServices.some((blocked) => key.includes(blocked));
163
+ }
164
+
165
+ function _isValidService(key, definition) {
166
+ const isExternalService = Object.keys(cds).includes("requires") ? Object.keys(cds.requires).includes(key) : false;
167
+
168
+ return (
169
+ definition.kind === CDS_ELEMENT_KIND.service &&
170
+ !definition["@cds.external"] &&
171
+ definition["@protocol"] !== "none" &&
172
+ !isExternalService &&
173
+ !_isBlockedServiceName(key)
174
+ );
175
+ }
176
+
154
177
  function _handleEntity(key, keyDefinition) {
155
- if (!key.includes(".texts")) {
178
+ if (!key.includes(".texts") && _shouldNotSkipIfServiceProtocolIsNone(keyDefinition)) {
156
179
  const apiEndpoint = key;
157
180
  const entityTypeTarget =
158
181
  keyDefinition[ORD_ODM_ENTITY_NAME_ANNOTATION] || keyDefinition[ENTITY_RELATIONSHIP_ANNOTATION]
@@ -163,16 +186,22 @@ function _handleEntity(key, keyDefinition) {
163
186
  return null;
164
187
  }
165
188
 
166
- function _handleEvent(serviceNames, key) {
167
- for (const serviceName of serviceNames) {
168
- if (key.startsWith(serviceName + ".")) {
169
- return serviceName;
189
+ function _handleEvent(serviceNames, key, keyDefinition) {
190
+ if (_shouldNotSkipIfServiceProtocolIsNone(keyDefinition)) {
191
+ for (const serviceName of serviceNames) {
192
+ if (key.startsWith(serviceName + ".")) {
193
+ return serviceName;
194
+ }
170
195
  }
171
196
  }
197
+ return null;
172
198
  }
173
199
 
174
- function _handleActionOrFunction(key) {
175
- return key;
200
+ function _handleActionOrFunction(key, keyDefinition) {
201
+ if (_shouldNotSkipIfServiceProtocolIsNone(keyDefinition)) {
202
+ return key;
203
+ }
204
+ return null;
176
205
  }
177
206
 
178
207
  const _getPolicyLevels = (appConfig) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/ord",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "description": "CAP Plugin for generating ORD document.",
5
5
  "repository": "cap-js/ord",
6
6
  "author": "SAP SE (https://www.sap.com)",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@cap-js/asyncapi": "^1.0.3",
36
36
  "@cap-js/openapi": "^1.2.1",
37
- "bcrypt": "^5.1.1",
37
+ "bcryptjs": "3.0.2",
38
38
  "cli-progress": "^3.12.0",
39
39
  "lodash": "^4.17.21"
40
40
  },