@cap-js/ord 1.3.7 → 1.3.9
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/defaults.js +39 -1
- package/lib/index.js +1 -0
- package/lib/{ord-service.mjs → ord-service.js} +6 -4
- package/lib/templates.js +14 -1
- package/package.json +4 -3
- package/lib/es-module.mjs +0 -6
package/lib/defaults.js
CHANGED
|
@@ -12,6 +12,26 @@ const packageTypes = [
|
|
|
12
12
|
{ tag: "-dataProduct", type: "Data Products" },
|
|
13
13
|
];
|
|
14
14
|
|
|
15
|
+
const stringTypeCheck = (value) => typeof value === "string";
|
|
16
|
+
const arrayTypeCheck = (value) => Array.isArray(value);
|
|
17
|
+
|
|
18
|
+
// see ref: https://pages.github.tools.sap/CentralEngineering/open-resource-discovery-specification/spec-v1/interfaces/document#package
|
|
19
|
+
const packageTypeChecks = {
|
|
20
|
+
policyLevels: arrayTypeCheck,
|
|
21
|
+
packageLinks: arrayTypeCheck,
|
|
22
|
+
links: arrayTypeCheck,
|
|
23
|
+
licenseType: stringTypeCheck,
|
|
24
|
+
supportInfo: stringTypeCheck,
|
|
25
|
+
vendor: stringTypeCheck,
|
|
26
|
+
countries: arrayTypeCheck,
|
|
27
|
+
lineOfBusiness: arrayTypeCheck,
|
|
28
|
+
industry: arrayTypeCheck,
|
|
29
|
+
runtimeRestriction: stringTypeCheck,
|
|
30
|
+
tags: arrayTypeCheck,
|
|
31
|
+
labels: arrayTypeCheck,
|
|
32
|
+
documentationLabels: arrayTypeCheck,
|
|
33
|
+
};
|
|
34
|
+
|
|
15
35
|
const regexWithRemoval = (name) => {
|
|
16
36
|
return name?.replace(/[^a-zA-Z0-9]/g, "");
|
|
17
37
|
};
|
|
@@ -36,6 +56,22 @@ const generateUniquePackageOrdId = (ordNamespace, name, tag, visibility) => {
|
|
|
36
56
|
return `${ordNamespace}:package:${regexWithRemoval(name)}${tag}${visibilitySuffix}:v1`;
|
|
37
57
|
};
|
|
38
58
|
|
|
59
|
+
const mapEnvPackageInfo = (packageConfig) => {
|
|
60
|
+
if (!packageConfig) {
|
|
61
|
+
return { vendor: undefined };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const filteredEnv = {};
|
|
65
|
+
for (const key in packageConfig) {
|
|
66
|
+
const value = packageConfig[key];
|
|
67
|
+
const checkFunction = packageTypeChecks[key];
|
|
68
|
+
if (value && checkFunction && checkFunction(value)) {
|
|
69
|
+
filteredEnv[key] = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return filteredEnv;
|
|
73
|
+
};
|
|
74
|
+
|
|
39
75
|
/**
|
|
40
76
|
* Module containing default configuration for ORD Document.
|
|
41
77
|
* @module defaults
|
|
@@ -58,7 +94,7 @@ module.exports = {
|
|
|
58
94
|
const name = appConfig.appName;
|
|
59
95
|
const ordNamespace = appConfig.ordNamespace;
|
|
60
96
|
const productsOrdId = appConfig.existingProductORDId || appConfig.products?.[0]?.ordId;
|
|
61
|
-
const vendor = appConfig
|
|
97
|
+
const { vendor, ...envValues } = mapEnvPackageInfo(appConfig?.env?.packages?.[0]);
|
|
62
98
|
if (hasSAPPolicyLevel(appConfig.policyLevels)) {
|
|
63
99
|
return _.uniqBy(
|
|
64
100
|
packageTypes.flatMap(({ tag, type }) =>
|
|
@@ -69,6 +105,7 @@ module.exports = {
|
|
|
69
105
|
version: "1.0.0",
|
|
70
106
|
...(productsOrdId && { partOfProducts: [productsOrdId || defaultProductOrdId(name)] }),
|
|
71
107
|
vendor: vendor || "customer:vendor:Customer:",
|
|
108
|
+
...envValues,
|
|
72
109
|
})),
|
|
73
110
|
),
|
|
74
111
|
"ordId",
|
|
@@ -82,6 +119,7 @@ module.exports = {
|
|
|
82
119
|
version: "1.0.0",
|
|
83
120
|
...(productsOrdId && { partOfProducts: [productsOrdId || defaultProductOrdId(name)] }),
|
|
84
121
|
vendor: vendor || "customer:vendor:Customer:",
|
|
122
|
+
...envValues,
|
|
85
123
|
},
|
|
86
124
|
];
|
|
87
125
|
}
|
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/templates.js
CHANGED
|
@@ -189,6 +189,13 @@ const createGroupsTemplateForService = (serviceName, serviceDefinition, appConfi
|
|
|
189
189
|
return undefined;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
const visibility = _handleVisibility(ordExtensions, serviceDefinition, appConfig.env?.defaultVisibility);
|
|
193
|
+
if (visibility === RESOURCE_VISIBILITY.private) {
|
|
194
|
+
// If the visibility of the service is private, do not create a group
|
|
195
|
+
Logger.debug("Skipping group creation for private service:", serviceName);
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
192
199
|
const groupId = _getGroupID(serviceDefinition, defaults.groupTypeId, appConfig);
|
|
193
200
|
return {
|
|
194
201
|
groupId: groupId,
|
|
@@ -257,7 +264,13 @@ function _handleVisibility(ordExtensions, definition, defaultVisibility = RESOUR
|
|
|
257
264
|
let visibility;
|
|
258
265
|
//check for supported custom visibility value in defaultVisibility variable
|
|
259
266
|
if (!ALLOWED_VISIBILITY.includes(defaultVisibility)) {
|
|
260
|
-
Logger.warn(
|
|
267
|
+
Logger.warn(
|
|
268
|
+
"Default visibility",
|
|
269
|
+
defaultVisibility,
|
|
270
|
+
"is not supported. Using",
|
|
271
|
+
RESOURCE_VISIBILITY.public,
|
|
272
|
+
"as fallback.",
|
|
273
|
+
);
|
|
261
274
|
defaultVisibility = RESOURCE_VISIBILITY.public;
|
|
262
275
|
}
|
|
263
276
|
// Determine visibility
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/ord",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
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
|
},
|
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";
|