@oondemand/oon-core-back 0.4.0 → 0.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oondemand/oon-core-back",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oondemand/oon-platform.git",
@@ -12,10 +12,34 @@ const SUPPORTED_APP_KINDS = Object.freeze(["root-central", "member-central", "po
12
12
  const SUPPORTED_MODULES = Object.freeze([
13
13
  "collections", "documents", "pipelines", "integrations", "omie", "assistants", "currencies",
14
14
  ]);
15
+ const SUPPORTED_TENANCY_MODELS = Object.freeze(["none", "single_tenant", "multi_tenant"]);
16
+ const SUPPORTED_AVAILABILITIES = Object.freeze(["system", "common", "licensed"]);
17
+ const SUPPORTED_ACCESS_POLICIES = Object.freeze(["tenant_members", "explicit_users", "rbac"]);
18
+ const SUPPORTED_DEPLOYMENT_MODES = Object.freeze(["singleton", "shared", "dedicated", "hybrid"]);
15
19
  const APP_KIND_ROLE = Object.freeze({
16
20
  "root-central": "root",
17
21
  "member-central": "member",
18
- "portal-cockpit": "portal",
22
+ "portal-cockpit": "member",
23
+ });
24
+ const APP_KIND_DIMENSIONS = Object.freeze({
25
+ "root-central": Object.freeze({
26
+ tenancyModel: "none",
27
+ availability: "system",
28
+ accessPolicy: "rbac",
29
+ deploymentMode: "singleton",
30
+ }),
31
+ "member-central": Object.freeze({
32
+ tenancyModel: "single_tenant",
33
+ availability: "licensed",
34
+ accessPolicy: "rbac",
35
+ deploymentMode: "dedicated",
36
+ }),
37
+ "portal-cockpit": Object.freeze({
38
+ tenancyModel: "multi_tenant",
39
+ availability: "common",
40
+ accessPolicy: "tenant_members",
41
+ deploymentMode: "shared",
42
+ }),
19
43
  });
20
44
 
21
45
  class AppManifestError extends Error {
@@ -105,14 +129,32 @@ function validateActivation(activation, issues) {
105
129
  }
106
130
  }
107
131
 
132
+ function validateDimension(value, field, supported, issues) {
133
+ if (value === undefined) return;
134
+ if (!supported.includes(value)) {
135
+ addIssue(issues, field, `deve ser um de: ${supported.join(", ")}.`);
136
+ }
137
+ }
138
+
139
+ function dimensionsFor(manifest) {
140
+ const defaults = APP_KIND_DIMENSIONS[manifest.appKind] || APP_KIND_DIMENSIONS["member-central"];
141
+ return {
142
+ tenancyModel: manifest.tenancyModel || defaults.tenancyModel,
143
+ availability: manifest.availability || defaults.availability,
144
+ accessPolicy: manifest.accessPolicy || defaults.accessPolicy,
145
+ deploymentMode: manifest.deploymentMode || defaults.deploymentMode,
146
+ };
147
+ }
148
+
108
149
  function validateAppManifest(input, { coreVersion = corePackage.version } = {}) {
109
150
  const issues = [];
110
151
  if (!isPlainObject(input)) {
111
152
  throw new AppManifestError("central.app.json inválido.", [{ path: "$", message: "deve conter um objeto JSON." }]);
112
153
  }
113
154
  const allowedTopLevel = new Set([
114
- "$schema", "schemaVersion", "id", "name", "slug", "appKind", "modules", "capabilities",
115
- "compatibility", "activation", "rbac",
155
+ "$schema", "schemaVersion", "id", "name", "slug", "appKind",
156
+ "tenancyModel", "availability", "accessPolicy", "deploymentMode",
157
+ "modules", "capabilities", "compatibility", "activation", "rbac",
116
158
  ]);
117
159
  for (const key of Object.keys(input)) {
118
160
  if (!allowedTopLevel.has(key)) addIssue(issues, key, "propriedade não suportada.");
@@ -130,6 +172,10 @@ function validateAppManifest(input, { coreVersion = corePackage.version } = {})
130
172
  if (!SUPPORTED_APP_KINDS.includes(input.appKind)) {
131
173
  addIssue(issues, "appKind", `deve ser um de: ${SUPPORTED_APP_KINDS.join(", ")}.`);
132
174
  }
175
+ validateDimension(input.tenancyModel, "tenancyModel", SUPPORTED_TENANCY_MODELS, issues);
176
+ validateDimension(input.availability, "availability", SUPPORTED_AVAILABILITIES, issues);
177
+ validateDimension(input.accessPolicy, "accessPolicy", SUPPORTED_ACCESS_POLICIES, issues);
178
+ validateDimension(input.deploymentMode, "deploymentMode", SUPPORTED_DEPLOYMENT_MODES, issues);
133
179
  if (!isPlainObject(input.modules)) {
134
180
  addIssue(issues, "modules", "deve ser um objeto.");
135
181
  } else {
@@ -165,13 +211,17 @@ function resolveAppManifestPath(cwd = process.cwd()) {
165
211
  }
166
212
 
167
213
  function appManifestToConfig(manifest, manifestPath) {
214
+ const dimensions = dimensionsFor(manifest);
168
215
  return {
169
216
  serviceName: manifest.slug,
170
217
  name: manifest.name,
171
218
  slug: manifest.slug,
172
219
  appCode: manifest.id,
173
220
  appKind: manifest.appKind,
174
- ecosystem: { role: APP_KIND_ROLE[manifest.appKind] },
221
+ ecosystem: {
222
+ role: APP_KIND_ROLE[manifest.appKind],
223
+ ...dimensions,
224
+ },
175
225
  activation: manifest.activation || {
176
226
  enabled: manifest.appKind !== "portal-cockpit",
177
227
  configurationVersion: 1,
@@ -208,9 +258,15 @@ module.exports = {
208
258
  APP_MANIFEST_SCHEMA_VERSION,
209
259
  SUPPORTED_APP_KINDS,
210
260
  SUPPORTED_MODULES,
261
+ SUPPORTED_TENANCY_MODELS,
262
+ SUPPORTED_AVAILABILITIES,
263
+ SUPPORTED_ACCESS_POLICIES,
264
+ SUPPORTED_DEPLOYMENT_MODES,
265
+ APP_KIND_DIMENSIONS,
211
266
  AppManifestError,
212
267
  parseVersion,
213
268
  compareVersions,
269
+ dimensionsFor,
214
270
  validateAppManifest,
215
271
  resolveAppManifestPath,
216
272
  appManifestToConfig,