@cap-js/ord 1.1.0 → 1.2.0

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/constants.js CHANGED
@@ -1,25 +1,39 @@
1
- const ORD_RESOURCE_TYPE = Object.freeze(
2
- {
3
- "service": "service",
4
- "entity": "entity",
5
- "event": "event",
6
- "api": "api"
7
- });
8
-
9
- const COMPILER_TYPES = Object.freeze(
10
- {
11
- "oas3": "oas3",
12
- "asyncapi2": "asyncapi2",
13
- "edmx": "edmx"
14
- });
1
+ const COMPILER_TYPES = Object.freeze({
2
+ oas3: "oas3",
3
+ asyncapi2: "asyncapi2",
4
+ edmx: "edmx",
5
+ });
15
6
 
16
7
  const CONTENT_MERGE_KEY = "ordId";
17
8
 
9
+ const DESCRIPTION_PREFIX = "Description for ";
10
+
11
+ const OPEN_RESOURCE_DISCOVERY_VERSION = "1.9";
12
+
18
13
  const ORD_EXTENSIONS_PREFIX = "@ORD.Extensions.";
19
14
 
15
+ const ORD_RESOURCE_TYPE = Object.freeze({
16
+ service: "service",
17
+ entity: "entity",
18
+ event: "event",
19
+ api: "api",
20
+ });
21
+
22
+ const RESOURCE_VISIBILITY = Object.freeze({
23
+ public: "public",
24
+ internal: "internal",
25
+ private: "private",
26
+ });
27
+
28
+ const SHORT_DESCRIPTION_PREFIX = "Short description for ";
29
+
20
30
  module.exports = {
21
- ORD_RESOURCE_TYPE,
22
31
  COMPILER_TYPES,
23
32
  CONTENT_MERGE_KEY,
24
- ORD_EXTENSIONS_PREFIX
33
+ DESCRIPTION_PREFIX,
34
+ OPEN_RESOURCE_DISCOVERY_VERSION,
35
+ ORD_EXTENSIONS_PREFIX,
36
+ ORD_RESOURCE_TYPE,
37
+ RESOURCE_VISIBILITY,
38
+ SHORT_DESCRIPTION_PREFIX,
25
39
  };
package/lib/date.js ADDED
@@ -0,0 +1,22 @@
1
+ function getRFC3339Date(includeOffset = true) {
2
+ const now = new Date();
3
+ const year = now.getUTCFullYear();
4
+ const month = String(now.getUTCMonth() + 1).padStart(2, '0');
5
+ const day = String(now.getUTCDate()).padStart(2, '0');
6
+ const hours = String(now.getUTCHours()).padStart(2, '0');
7
+ const minutes = String(now.getUTCMinutes()).padStart(2, '0');
8
+ const seconds = String(now.getUTCSeconds()).padStart(2, '0');
9
+
10
+ if (includeOffset) {
11
+ const offsetHours = '01';
12
+ const offsetMinutes = '00';
13
+ const offsetSign = '+';
14
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${offsetSign}${offsetHours}:${offsetMinutes}`;
15
+ } else {
16
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}Z`;
17
+ }
18
+ }
19
+
20
+ module.exports = {
21
+ getRFC3339Date
22
+ };
package/lib/defaults.js CHANGED
@@ -1,3 +1,5 @@
1
+ const { OPEN_RESOURCE_DISCOVERY_VERSION } = require("./constants");
2
+
1
3
  const regexWithRemoval = (name) => {
2
4
  if (name) {
3
5
  return name.replace(/[^a-zA-Z0-9]/g, "");
@@ -27,7 +29,7 @@ const defaultProductOrdId = (name) => `customer:product:${nameWithDot(name)}:`;
27
29
  module.exports = {
28
30
  $schema:
29
31
  "https://sap.github.io/open-resource-discovery/spec-v1/interfaces/Document.schema.json",
30
- openResourceDiscovery: "1.9",
32
+ openResourceDiscovery: OPEN_RESOURCE_DISCOVERY_VERSION,
31
33
  policyLevel: "none",
32
34
  description: "this is an application description",
33
35
  products: (name) => [
@@ -63,10 +65,11 @@ module.exports = {
63
65
  return [createPackage(name, ":v1")];
64
66
  }
65
67
  },
66
- consumptionBundles: (name) => [
68
+ consumptionBundles: (appConfig) => [
67
69
  {
68
- ordId: `${regexWithRemoval(name)}:consumptionBundle:unknown:v1`,
70
+ ordId: `${regexWithRemoval(appConfig.appName)}:consumptionBundle:noAuth:v1`,
69
71
  version: "1.0.0",
72
+ lastUpdate: appConfig.lastUpdate,
70
73
  title: "Unprotected resources",
71
74
  shortDescription:
72
75
  "If we have another protected API then it will be another object",
@@ -1,8 +1,9 @@
1
- const path = require("path");
1
+ const { CONTENT_MERGE_KEY } = require("./constants");
2
2
  const cds = require("@sap/cds");
3
- const _ = require('lodash');
4
- const { CONTENT_MERGE_KEY } = require('./constants');
5
-
3
+ const fs = require("fs");
4
+ const { Logger } = require("./logger");
5
+ const path = require("path");
6
+ const _ = require("lodash");
6
7
 
7
8
  function cleanNullProperties(obj) {
8
9
  for (const key in obj) {
@@ -28,12 +29,13 @@ function patchGeneratedOrdResources(destinationObj, sourceObj) {
28
29
  return cleanNullProperties(Object.values(destObj));
29
30
  }
30
31
 
31
- function compareAndHandleCustomORDContentWithExistingContent(ordContent, customORDContent, logger) {
32
+ function compareAndHandleCustomORDContentWithExistingContent(ordContent, customORDContent) {
32
33
  const clonedOrdContent = structuredClone(ordContent);
33
34
  for (const key in customORDContent) {
34
35
  const propertyType = typeof customORDContent[key];
35
36
  if (propertyType !== 'object' && propertyType !== 'array') {
36
- logger.warn('Found ord top level primitive ord property in customOrdFile:', key, ', please define it in .cdsrc.json.');
37
+ Logger.warn('Found ord top level primitive ord property in customOrdFile:', key, '. Please define it in .cdsrc.json.');
38
+
37
39
  continue;
38
40
  }
39
41
  if (key in ordContent) {
@@ -46,20 +48,17 @@ function compareAndHandleCustomORDContentWithExistingContent(ordContent, customO
46
48
  }
47
49
 
48
50
  function getCustomORDContent(appConfig) {
49
- if (appConfig.env?.customOrdContentFile) {
50
- const customORDContent = require(path.join(cds.root, appConfig.env.customOrdContentFile));
51
- return customORDContent;
51
+ if (!appConfig.env?.customOrdContentFile) return;
52
+ const pathToCustomORDContent = path.join(cds.root, appConfig.env?.customOrdContentFile);
53
+ if (fs.existsSync(pathToCustomORDContent)) {
54
+ Logger.error('Custom ORD content file not found at', pathToCustomORDContent);
55
+ return require(pathToCustomORDContent);
52
56
  }
53
- return {};
54
57
  }
55
58
 
56
- function extendCustomORDContentIfExists(appConfig, ordContent, logger) {
59
+ function extendCustomORDContentIfExists(appConfig, ordContent) {
57
60
  const customORDContent = getCustomORDContent(appConfig);
58
-
59
- if (customORDContent) {
60
- ordContent = compareAndHandleCustomORDContentWithExistingContent(ordContent, customORDContent, logger);
61
- }
62
- return ordContent;
61
+ return customORDContent ? compareAndHandleCustomORDContentWithExistingContent(ordContent, customORDContent) : ordContent;
63
62
  }
64
63
 
65
64
  module.exports = {
package/lib/logger.js ADDED
@@ -0,0 +1,11 @@
1
+ const cds = require("@sap/cds");
2
+
3
+ const Logger = cds.log("ord-plugin", {
4
+ level: cds.env.DEBUG || process.env.DEBUG
5
+ ? cds.log.levels?.DEBUG
6
+ : cds.log.levels?.WARN,
7
+ });
8
+
9
+ module.exports = {
10
+ Logger,
11
+ };
package/lib/metaData.js CHANGED
@@ -2,6 +2,7 @@ const cds = require('@sap/cds/lib');
2
2
  const { compile: openapi } = require('@cap-js/openapi')
3
3
  const { compile: asyncapi } = require('@cap-js/asyncapi');
4
4
  const { COMPILER_TYPES } = require('./constants');
5
+ const { Logger } = require('./logger');
5
6
 
6
7
  module.exports = async (data) => {
7
8
  const parts = data?.split("/").pop().replace(/\.json$/, '').split(".");
@@ -16,7 +17,7 @@ module.exports = async (data) => {
16
17
  try {
17
18
  responseFile = openapi(csn, options);
18
19
  } catch (error) {
19
- console.error("OpenApi error:", error.message);
20
+ Logger.error('OpenApi error:', error.message);
20
21
  throw error;
21
22
  }
22
23
  break;
@@ -24,7 +25,7 @@ module.exports = async (data) => {
24
25
  try {
25
26
  responseFile = asyncapi(csn, options);
26
27
  } catch (error) {
27
- console.error("AsyncApi error:", error.message);
28
+ Logger.error('AsyncApi error:', error.message);
28
29
  throw error;
29
30
  }
30
31
  break;
@@ -32,7 +33,7 @@ module.exports = async (data) => {
32
33
  try {
33
34
  responseFile = await cds.compile(csn).to["edmx"](options);
34
35
  } catch (error) {
35
- console.error("Edmx error:", error.message);
36
+ Logger.error('Edmx error:', error.message);
36
37
  throw error;
37
38
  }
38
39
  }
package/lib/ord.js CHANGED
@@ -1,24 +1,23 @@
1
- const path = require("path");
2
- const cds = require("@sap/cds");
3
- const { exists } = cds.utils;
4
- const _ = require("lodash");
5
- const defaults = require("./defaults");
1
+ const { ORD_RESOURCE_TYPE } = require('./constants');
6
2
  const {
7
3
  createAPIResourceTemplate,
4
+ createEntityTypeTemplate,
8
5
  createEventResourceTemplate,
9
- createGroupsTemplateForService,
10
- createEntityTypeTemplate
6
+ createGroupsTemplateForService
11
7
  } = require('./templates');
12
8
  const { extendCustomORDContentIfExists } = require('./extendOrdWithCustom');
13
- const { ORD_RESOURCE_TYPE } = require('./constants');
14
-
15
- const logger = cds.log('ord-plugin');
9
+ const { getRFC3339Date } = require('./date');
10
+ const { Logger } = require('./logger');
11
+ const _ = require("lodash");
12
+ const cds = require("@sap/cds");
13
+ const defaults = require("./defaults");
14
+ const path = require("path");
16
15
 
17
16
  const initializeAppConfig = (csn) => {
18
- let packagejsonPath = path.join(cds.root, 'package.json')
17
+ let packageJsonPath = path.join(cds.root, 'package.json')
19
18
  let packageJson;
20
- if (exists(packagejsonPath)) {
21
- packageJson = require(packagejsonPath);
19
+ if (cds.utils.exists(packageJsonPath)) {
20
+ packageJson = require(packageJsonPath);
22
21
  } else {
23
22
  throw new Error(`package.json not found in the project root directory`);
24
23
  }
@@ -27,16 +26,15 @@ const initializeAppConfig = (csn) => {
27
26
  const modelKeys = Object.keys(csn.definitions);
28
27
  const events = [];
29
28
  const serviceNames = [];
29
+ const lastUpdate = getRFC3339Date();
30
30
  let odmEntity = [];
31
31
 
32
- // namespace variable value if present in cdsrc.json take it there or else from package.json
33
- //if cdsrc.json does not have applicationNamespace, then use just the namespace
34
32
  const vendorNamespace = "customer";
35
33
  const ordNamespace = cds.env["ord"]?.namespace || `${vendorNamespace}.${packageName.replace(/[^a-zA-Z0-9]/g, "")}`;
36
34
  const eventApplicationNamespace = cds.env?.export?.asyncapi?.applicationNamespace;
37
35
 
38
36
  if (eventApplicationNamespace && ordNamespace !== eventApplicationNamespace) {
39
- console.warn("ORD and AsyncAPI namespaces should be the same.");
37
+ Logger.warn('ORD and AsyncAPI namespaces should be the same.');
40
38
  }
41
39
 
42
40
  for (const key of modelKeys) {
@@ -63,6 +61,7 @@ const initializeAppConfig = (csn) => {
63
61
 
64
62
  return {
65
63
  env: cds.env["ord"],
64
+ lastUpdate,
66
65
  appName,
67
66
  events,
68
67
  serviceNames,
@@ -97,17 +96,24 @@ const _getPackages = (policyLevel, appConfig) =>
97
96
 
98
97
  const _getAPIResources = (csn, appConfig, packageIds) => {
99
98
  return appConfig.serviceNames
100
- .flatMap((serviceName) => createAPIResourceTemplate(serviceName, csn.definitions[serviceName], appConfig, packageIds) || [])
101
- .filter((resource) => !!resource);
99
+ .flatMap((serviceName) => createAPIResourceTemplate(serviceName, csn.definitions[serviceName], appConfig, packageIds))
102
100
  };
103
101
 
104
102
  const _getEventResources = (csn, appConfig, packageIds) => {
105
103
  if (appConfig.events.length === 0) return [];
106
104
  return appConfig.serviceNames
107
105
  .filter((serviceName) => appConfig.events.some((eventName) => eventName.startsWith(serviceName)))
108
- .flatMap((serviceName) => createEventResourceTemplate(serviceName, csn.definitions[serviceName], appConfig, packageIds) || []);
106
+ .flatMap((serviceName) => createEventResourceTemplate(serviceName, csn.definitions[serviceName], appConfig, packageIds));
109
107
  };
110
108
 
109
+ function _getOpenResourceDiscovery(appConfig) {
110
+ return appConfig.env?.openResourceDiscovery || defaults.openResourceDiscovery;
111
+ }
112
+
113
+ function _getConsumptionBundles(appConfig) {
114
+ return appConfig.env?.consumptionBundles || defaults.consumptionBundles(appConfig);
115
+ }
116
+
111
117
  function validateNamespace(appConfig) {
112
118
  const validateSystemNamespace = new RegExp(`^${appConfig.eventApplicationNamespace}\\.[^.]+\\..+$`);
113
119
  if (
@@ -117,7 +123,7 @@ function validateNamespace(appConfig) {
117
123
  let error = new Error(
118
124
  `Namespace is not defined in cdsrc.json or it is not in the format of ${appConfig.eventApplicationNamespace}.<appName>.<service>`
119
125
  );
120
- console.error("Namespace error:", error.message);
126
+ Logger.error('Namespace error:', error.message);
121
127
  throw error;
122
128
  }
123
129
  }
@@ -125,11 +131,12 @@ function validateNamespace(appConfig) {
125
131
  function createDefaultORDDocument(linkedCsn, appConfig) {
126
132
  let ordDocument = {
127
133
  $schema: "https://sap.github.io/open-resource-discovery/spec-v1/interfaces/Document.schema.json",
128
- openResourceDiscovery: "1.9",
134
+ openResourceDiscovery: _getOpenResourceDiscovery(appConfig),
129
135
  policyLevel: _getPolicyLevel(appConfig),
130
136
  description: _getDescription(appConfig),
131
137
  products: _getProducts(appConfig),
132
138
  groups: _getGroups(linkedCsn, appConfig),
139
+ consumptionBundles: _getConsumptionBundles(appConfig),
133
140
  };
134
141
 
135
142
  if (_getAPIResources(linkedCsn, appConfig).length && _getEventResources(linkedCsn, appConfig).length) {
@@ -139,9 +146,9 @@ function createDefaultORDDocument(linkedCsn, appConfig) {
139
146
  }
140
147
 
141
148
  function extractPackageIds(ordDocument) {
142
- const packageIds = new Set();
149
+ const packageIds = [];
143
150
  if (ordDocument.packages) {
144
- ordDocument.packages.map((pkg) => packageIds.add(pkg.ordId));
151
+ ordDocument.packages.map((pkg) => packageIds.push(pkg.ordId));
145
152
  }
146
153
  return packageIds;
147
154
  }
@@ -153,14 +160,9 @@ module.exports = (csn) => {
153
160
 
154
161
  let ordDocument = createDefaultORDDocument(linkedCsn, appConfig);
155
162
  const packageIds = extractPackageIds(ordDocument);
156
- // TODO: add testcase without apiResources or event, no empty package
157
163
  ordDocument.apiResources = _getAPIResources(linkedCsn, appConfig, packageIds);
158
- const eventResources = _getEventResources(linkedCsn, appConfig, packageIds);
159
- if (eventResources.length) {
160
- ordDocument.eventResources = eventResources;
161
- }
162
-
163
- ordDocument = extendCustomORDContentIfExists(appConfig, ordDocument, logger);
164
+ ordDocument.eventResources = _getEventResources(linkedCsn, appConfig, packageIds);
165
+ ordDocument = extendCustomORDContentIfExists(appConfig, ordDocument);
164
166
 
165
167
  return ordDocument;
166
168
  };
package/lib/plugin.js CHANGED
@@ -1,5 +1,7 @@
1
- const { ord, getMetadata, defaults } = require("./");
2
1
  const cds = require("@sap/cds");
2
+ const { Logger } = require("./logger");
3
+ const { ord, getMetadata, defaults } = require("./");
4
+
3
5
 
4
6
  cds.on("bootstrap", (app) => {
5
7
  app.use("/.well-known/open-resource-discovery", async (req, res) => {
@@ -10,8 +12,7 @@ cds.on("bootstrap", (app) => {
10
12
  const { contentType, response } = await getMetadata(req.url);
11
13
  res.status(200).contentType(contentType).send(response);
12
14
  } catch (error) {
13
- console.log(error);
14
- console.log('Error while generating metadata');
15
+ Logger.error(error, 'Error while generating metadata');
15
16
  res.status(500).send(error.message);
16
17
  }
17
18
  }
@@ -23,8 +24,7 @@ cds.on("bootstrap", (app) => {
23
24
  const data = ord(csn);
24
25
  return res.status(200).send(data);
25
26
  } catch (error) {
26
- console.log(error);
27
- console.log('Error while creating ORD document');
27
+ Logger.error(error, 'Error while creating ORD document');
28
28
  return res.status(500).send(error.message);
29
29
  }
30
30
  });
package/lib/templates.js CHANGED
@@ -1,7 +1,14 @@
1
- const defaults = require("./defaults");
2
1
  const cds = require("@sap/cds");
2
+ const defaults = require("./defaults");
3
3
  const _ = require("lodash");
4
- const { ORD_EXTENSIONS_PREFIX } = require("./constants");
4
+ const {
5
+ DESCRIPTION_PREFIX,
6
+ ORD_EXTENSIONS_PREFIX,
7
+ ORD_RESOURCE_TYPE,
8
+ RESOURCE_VISIBILITY,
9
+ SHORT_DESCRIPTION_PREFIX
10
+ } = require("./constants");
11
+ const { Logger } = require("./logger");
5
12
 
6
13
  function unflatten(flattedObject) {
7
14
  let result = {}
@@ -40,12 +47,12 @@ const _generatePaths = (srv, srvDefinition) => {
40
47
  //removing instances of graphql protocol from paths
41
48
  for (var index = paths.length - 1; index >= 0; index--) {
42
49
  if (paths[index].kind === "graphql") {
43
- console.warn("Graphql protocol is not supported.");
50
+ Logger.warn('Graphql protocol is not supported.');
44
51
  paths.splice(index, 1);
45
52
  }
46
53
  }
47
54
 
48
- //putting default as odata in case no supported protcol is there
55
+ //putting OData as default in case of non-supported protocol
49
56
  if (paths.length === 0) {
50
57
  srvDefinition["@odata"] = true;
51
58
  paths.push({ kind: "odata", path: protocols.path4(srvDefinition) });
@@ -100,7 +107,7 @@ const createGroupsTemplateForService = (serviceName, serviceDefinition, appConfi
100
107
  const ordExtensions = readORDExtensions(serviceDefinition);
101
108
 
102
109
  if (!serviceDefinition) {
103
- console.warn("Unable to find service definition:", serviceName)
110
+ Logger.warn('Unable to find service definition:', serviceName)
104
111
  return undefined
105
112
  }
106
113
 
@@ -114,7 +121,8 @@ const createGroupsTemplateForService = (serviceName, serviceDefinition, appConfi
114
121
 
115
122
  /**
116
123
  * This is a template function to create API Resource object for API Resource Array.
117
- *
124
+ * Properties of an API resource can be overwritten by the ORD extensions. Example: visibility.
125
+
118
126
  * @param {string} serviceName The name of the service.
119
127
  * @param {object} serviceDefinition The definition of the service
120
128
  * @returns {Array} An array of objects for the API Resources.
@@ -150,13 +158,14 @@ const createAPIResourceTemplate = (serviceName, serviceDefinition, appConfig, pa
150
158
  serviceDefinition["@title"] ??
151
159
  serviceDefinition["@Common.Label"] ??
152
160
  serviceName,
153
- shortDescription: serviceName,
161
+ shortDescription: SHORT_DESCRIPTION_PREFIX + serviceName,
154
162
  description:
155
163
  serviceDefinition["@Core.Description"] ??
156
- serviceName,
164
+ DESCRIPTION_PREFIX + serviceName,
157
165
  version: "1.0.0",
158
- visibility: "public",
159
- partOfPackage: _getPackageID(appConfig.ordNamespace, packageIds, "api"),
166
+ lastUpdate: appConfig.lastUpdate,
167
+ visibility: RESOURCE_VISIBILITY.public,
168
+ partOfPackage: _getPackageID(appConfig.ordNamespace, packageIds, ORD_RESOURCE_TYPE.api),
160
169
  partOfGroups: [_getGroupID(serviceName, defaults.groupTypeId, appConfig)],
161
170
  releaseStatus: "active",
162
171
  apiProtocol:
@@ -167,33 +176,43 @@ const createAPIResourceTemplate = (serviceName, serviceDefinition, appConfig, pa
167
176
  supported: "no",
168
177
  },
169
178
  entityTypeMappings: [{ entityTypeTargets: appConfig.odmEntity }],
170
-
171
179
  ...ordExtensions,
172
180
  };
173
181
 
174
- apiResources.push(obj);
182
+ if (obj.visibility === RESOURCE_VISIBILITY.public) apiResources.push(obj);
175
183
  });
176
184
 
177
- if (apiResources.length > 0) return apiResources;
185
+ return apiResources;
178
186
  };
179
187
 
180
- const createEventResourceTemplate = (serviceName, eventDefinition, appConfig, packageIds) => {
181
- const ordExtensions = readORDExtensions(eventDefinition);
182
- return {
188
+ /**
189
+ * This is a template function to create Event Resource object for Event Resource Array.
190
+ * There can be only one event resource per service because all events are using the same protocol, they are always Cloud Events.
191
+ * Properties of an event resource can be overwritten by the ORD extensions. Example: visibility.
192
+ *
193
+ * @param {string} serviceName The name of the service.
194
+ * @param {object} serviceDefinition The definition of the service
195
+ * @returns {Array} An single-item array of objects for the Event Resources.
196
+ */
197
+ const createEventResourceTemplate = (serviceName, serviceDefinition, appConfig, packageIds) => {
198
+ const ordExtensions = readORDExtensions(serviceDefinition);
199
+ if (!!ordExtensions.visibility && ordExtensions.visibility !== RESOURCE_VISIBILITY.public) return [];
200
+ return [{
183
201
  ordId: `${appConfig.ordNamespace}:eventResource:${serviceName}:v1`,
184
202
  title:
185
- eventDefinition["@title"] ??
186
- eventDefinition["@Common.Label"] ??
203
+ serviceDefinition["@title"] ??
204
+ serviceDefinition["@Common.Label"] ??
187
205
  `ODM ${appConfig.appName.replace(/[^a-zA-Z0-9]/g, "")} Events`,
188
206
  shortDescription: `${serviceName} event resource`,
189
207
  description:
190
- eventDefinition['@description'] ?? eventDefinition['@Core.Description'] ??
208
+ serviceDefinition['@description'] ?? serviceDefinition['@Core.Description'] ??
191
209
  "CAP Event resource describing events / messages.",
192
210
  version: "1.0.0",
211
+ lastUpdate: appConfig.lastUpdate,
193
212
  releaseStatus: "active",
194
- partOfPackage: _getPackageID(appConfig.ordNamespace, packageIds, 'event'),
213
+ partOfPackage: _getPackageID(appConfig.ordNamespace, packageIds, ORD_RESOURCE_TYPE.event),
195
214
  partOfGroups: [_getGroupID(serviceName, defaults.groupTypeId, appConfig)],
196
- visibility: "public",
215
+ visibility: RESOURCE_VISIBILITY.public,
197
216
  resourceDefinitions: [
198
217
  {
199
218
  type: "asyncapi-v2",
@@ -209,14 +228,13 @@ const createEventResourceTemplate = (serviceName, eventDefinition, appConfig, pa
209
228
  extensible: { supported: "no" },
210
229
 
211
230
  ...ordExtensions
212
- };
231
+ }]
213
232
  };
214
233
 
215
234
  function _getPackageID(namespace, packageIds, resourceType) {
216
- //TODO: without this check, it will be failed in ordPackageJson.test.js, need to check why it is failing
217
- if (!(packageIds instanceof Set)) return;
218
- const packageIdsArray = Array.from(packageIds);
219
- return packageIdsArray.find((pkg) => pkg.includes("-" + resourceType)) || packageIdsArray.find((pkg) => pkg.includes(namespace));
235
+ if (!packageIds) return;
236
+
237
+ return packageIds.find((id) => id.includes("-" + resourceType)) || packageIds.find((id) => id.includes(namespace));
220
238
  }
221
239
 
222
240
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/ord",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "CAP Plugin for generating ORD document.",
5
5
  "repository": "cap-js/ord",
6
6
  "author": "SAP SE (https://www.sap.com)",