@cap-js/ord 1.3.6 → 1.3.8
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/lib/authentication.js +1 -1
- package/lib/index.js +1 -0
- package/lib/{ord-service.mjs → ord-service.js} +6 -4
- package/lib/ord.js +46 -17
- package/package.json +5 -4
- package/lib/es-module.mjs +0 -6
package/lib/authentication.js
CHANGED
|
@@ -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("
|
|
4
|
+
const bcrypt = require("bcryptjs");
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Compares a plain text password with a hashed password
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const cds = require("@sap/cds");
|
|
2
|
+
const { ord, getMetadata, defaults, authentication, Logger } = require("./index.js");
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
class OpenResourceDiscoveryService extends cds.ApplicationService {
|
|
5
5
|
init() {
|
|
6
6
|
cds.app.get(`${this.path}`, cds.middlewares.before, (_, res) => {
|
|
7
7
|
return res.status(200).send(defaults.baseTemplate);
|
|
@@ -22,7 +22,7 @@ export class OpenResourceDiscoveryService extends cds.ApplicationService {
|
|
|
22
22
|
const { contentType, response } = await getMetadata(req.url);
|
|
23
23
|
return res.status(200).contentType(contentType).send(response);
|
|
24
24
|
} catch (error) {
|
|
25
|
-
|
|
25
|
+
Logger.error(error, "Error while processing the resource definition document");
|
|
26
26
|
return res.status(500).send(error.message);
|
|
27
27
|
}
|
|
28
28
|
});
|
|
@@ -30,3 +30,5 @@ export class OpenResourceDiscoveryService extends cds.ApplicationService {
|
|
|
30
30
|
return super.init();
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
module.exports = { OpenResourceDiscoveryService };
|
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
|
|
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(
|
|
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
|
|
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 (
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
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,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/ord",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"description": "CAP Plugin for generating ORD document.",
|
|
5
5
|
"repository": "cap-js/ord",
|
|
6
6
|
"author": "SAP SE (https://www.sap.com)",
|
|
7
7
|
"homepage": "https://cap.cloud.sap/",
|
|
8
8
|
"license": "Apache-2.0",
|
|
9
9
|
"workspaces": [
|
|
10
|
-
"xmpl"
|
|
10
|
+
"xmpl",
|
|
11
|
+
"xmpl_java"
|
|
11
12
|
],
|
|
12
13
|
"main": "cds-plugin.js",
|
|
13
14
|
"files": [
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
"cds:version": "cds v -i"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"eslint": "^
|
|
27
|
+
"eslint": "^9.2.0",
|
|
27
28
|
"jest": "^29.7.0",
|
|
28
29
|
"prettier": "3.5.3"
|
|
29
30
|
},
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@cap-js/asyncapi": "^1.0.3",
|
|
36
37
|
"@cap-js/openapi": "^1.2.1",
|
|
37
|
-
"
|
|
38
|
+
"bcryptjs": "3.0.2",
|
|
38
39
|
"cli-progress": "^3.12.0",
|
|
39
40
|
"lodash": "^4.17.21"
|
|
40
41
|
},
|
package/lib/es-module.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// matches commonjs.js to es-module so that we can use the same code in cap services
|
|
2
|
-
export { default as defaults } from "./defaults.js";
|
|
3
|
-
export { default as getMetadata } from "./metaData.js";
|
|
4
|
-
export { default as ord } from "./ord.js";
|
|
5
|
-
export { default as authentication } from "./authentication.js";
|
|
6
|
-
export { default as logger } from "./logger.js";
|