@izara_project/izara-shared-service-schemas 1.0.78 → 1.0.80
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/index.js +21 -3
- package/package.json +1 -1
- package/src/Consts.js +14 -12
- package/src/getSchemas/GetErrorSchema.js +197 -0
- package/src/getSchemas/GetFlowSchema.js +61 -0
- package/src/getSchemas/GetNotificationSchema.js +62 -0
- package/src/getSchemas/GetObjectSchema.js +738 -0
- package/src/getSchemas/GetPluginSchema.js +57 -0
- package/src/getSchemas/GetRelSchema.js +666 -0
- package/src/getSchemas/GetSystemTextSchema.js +62 -0
- package/src/libs/BasicValidatorSchema.js +2 -21
- package/src/libs/ValidateObjType.js +11 -5
- package/src/GetObjectSchema.js +0 -1687
package/index.js
CHANGED
|
@@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import
|
|
18
|
+
import errorSchemas from './src/errorSchemas.js';
|
|
19
19
|
import consts from './src/Consts.js';
|
|
20
20
|
import utils from './src/Utils.js';
|
|
21
21
|
|
|
@@ -24,15 +24,33 @@ import relSchemaLib from './src/libs/RelSchemaLib.js';
|
|
|
24
24
|
import validateObjType from './src/libs/ValidateObjType.js';
|
|
25
25
|
import reformatObjectSchema from './src/libs/ReformatObjectSchema.js';
|
|
26
26
|
|
|
27
|
+
import getErrorSchema from './src/getSchemas/GetErrorSchema.js';
|
|
28
|
+
import getFlowSchema from './src/getSchemas/GetFlowSchema.js';
|
|
29
|
+
import getNotificationSchema from './src/getSchemas/GetNotificationSchema.js';
|
|
30
|
+
import getObjectSchema from './src/getSchemas/GetObjectSchema.js';
|
|
31
|
+
import getPluginSchema from './src/getSchemas/GetPluginSchema.js';
|
|
32
|
+
import getRelSchema from './src/getSchemas/GetRelSchema.js';
|
|
33
|
+
import getSystemTextSchema from './src/GetSystemTextSchema.js';
|
|
34
|
+
|
|
27
35
|
export {
|
|
28
36
|
// ./src
|
|
29
|
-
|
|
37
|
+
errorSchemas,
|
|
30
38
|
consts,
|
|
31
39
|
utils,
|
|
32
40
|
|
|
41
|
+
// getSchemas
|
|
42
|
+
getObjectSchema,
|
|
43
|
+
getErrorSchema,
|
|
44
|
+
getFlowSchema,
|
|
45
|
+
getNotificationSchema,
|
|
46
|
+
getPluginSchema,
|
|
47
|
+
getRelSchema,
|
|
48
|
+
getSystemTextSchema,
|
|
49
|
+
|
|
33
50
|
// ./src/libs
|
|
34
51
|
basicValidatorSchema,
|
|
35
52
|
relSchemaLib,
|
|
36
53
|
validateObjType,
|
|
37
|
-
reformatObjectSchema
|
|
54
|
+
reformatObjectSchema,
|
|
55
|
+
|
|
38
56
|
};
|
package/package.json
CHANGED
package/src/Consts.js
CHANGED
|
@@ -68,7 +68,8 @@ const ALLOW_FIELDNAME_TYPES = Object.keys(FIELDNAME_TYPES);
|
|
|
68
68
|
|
|
69
69
|
const PREFIX_PATH_S3 = {
|
|
70
70
|
perServiceSchemas: 'perServiceSchemas',
|
|
71
|
-
serviceConfig: 'serviceConfig'
|
|
71
|
+
serviceConfig: 'serviceConfig',
|
|
72
|
+
plugInSchema: 'plugInSchema'
|
|
72
73
|
};
|
|
73
74
|
|
|
74
75
|
function objectListAllPathS3(serviceTag) {
|
|
@@ -286,21 +287,19 @@ function notificationSchemaPathS3(serviceTag) {
|
|
|
286
287
|
}
|
|
287
288
|
}
|
|
288
289
|
|
|
289
|
-
function
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
errorsFound: validateObjTypeResult.errorsFound,
|
|
290
|
+
function plugInSchemasPathS3(plugInTag) {
|
|
291
|
+
if (typeof plugInTag !== 'string') {
|
|
292
|
+
return {
|
|
293
|
+
errorsFound: `${plugInTag} not string`,
|
|
294
294
|
result: null
|
|
295
295
|
};
|
|
296
296
|
} else {
|
|
297
297
|
return {
|
|
298
298
|
errorsFound: [],
|
|
299
|
-
result: `${PREFIX_PATH_S3.
|
|
299
|
+
result: `${PREFIX_PATH_S3.plugInSchema}/${plugInTag}.json`
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
-
|
|
304
303
|
function allErrorSchemasPathS3(serviceTag) {
|
|
305
304
|
if (typeof serviceTag !== 'string') {
|
|
306
305
|
return {
|
|
@@ -346,9 +345,9 @@ const SCHEMA_NAME = {
|
|
|
346
345
|
flowSchema: 'flowSchema',
|
|
347
346
|
systemTextSchemas: 'systemTextSchemas',
|
|
348
347
|
notificationSchemas: 'notificationSchemas',
|
|
349
|
-
plugInConfigSchemas: 'plugInConfigSchemas',
|
|
350
348
|
allErrorSchemas: 'allErrorSchemas',
|
|
351
|
-
perErrorSchemaTag: 'perErrorSchemaTag'
|
|
349
|
+
perErrorSchemaTag: 'perErrorSchemaTag',
|
|
350
|
+
plugInSchema: 'plugInSchema',
|
|
352
351
|
};
|
|
353
352
|
|
|
354
353
|
const SCHEMA_NAME_PER_S3_PATH = {
|
|
@@ -374,10 +373,13 @@ const SCHEMA_NAME_PER_S3_PATH = {
|
|
|
374
373
|
[SCHEMA_NAME.systemTextSchemas]: systemTextSchemaPathS3,
|
|
375
374
|
// notification schema
|
|
376
375
|
[SCHEMA_NAME.notificationSchemas]: notificationSchemaPathS3,
|
|
377
|
-
|
|
378
|
-
[SCHEMA_NAME.plugInConfigSchemas]: plugInConfigSchemasPathS3,
|
|
376
|
+
|
|
379
377
|
[SCHEMA_NAME.allErrorSchemas]: allErrorSchemasPathS3,
|
|
380
378
|
[SCHEMA_NAME.perErrorSchemaTag]: perErrorSchemaTagPathS3,
|
|
379
|
+
|
|
380
|
+
// plugIn schema
|
|
381
|
+
[SCHEMA_NAME.plugInSchema]: plugInSchemasPathS3,
|
|
382
|
+
|
|
381
383
|
};
|
|
382
384
|
|
|
383
385
|
const ACTION_LIST = Object.values(ACTIONS);
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright(C) 2021 Sven Mason < http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and / or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or(at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program.If not, see < http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import consts from '../Consts.js';
|
|
19
|
+
const { SCHEMA_NAME, OBJECT_SCHEMA_BUCKET_NAME } = consts;
|
|
20
|
+
import { validateErrorType } from '../libs/ValidateObjType.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Gets all error schemas for a given service tag.
|
|
24
|
+
* @param {function} getSchemaFn - Function to get the schema.
|
|
25
|
+
* @param {string} serviceTag - Tag of the service.
|
|
26
|
+
* @param {string} bucketName - Name of the bucket to get the schema from.
|
|
27
|
+
* @returns {{errorsFound: string[], result: Object[]}}
|
|
28
|
+
*/
|
|
29
|
+
async function getErrorSchemaAllS3(
|
|
30
|
+
getSchemaFn,
|
|
31
|
+
serviceTag,
|
|
32
|
+
bucketName = OBJECT_SCHEMA_BUCKET_NAME
|
|
33
|
+
) {
|
|
34
|
+
const errorsFound = [];
|
|
35
|
+
if (!serviceTag || typeof serviceTag !== 'string') {
|
|
36
|
+
return {
|
|
37
|
+
errorsFound: ['serviceTag must be a non-empty string'],
|
|
38
|
+
result: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getDataParams = {
|
|
43
|
+
schemaName: SCHEMA_NAME.allErrorSchemas,
|
|
44
|
+
getParams: serviceTag
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
let errorSchemas = await getSchemaFn(getDataParams, bucketName);
|
|
48
|
+
if (!errorSchemas) {
|
|
49
|
+
return {
|
|
50
|
+
errorsFound: errorsFound,
|
|
51
|
+
result: null
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
return {
|
|
55
|
+
errorsFound: errorsFound,
|
|
56
|
+
result: errorSchemas
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Gets an error schema for a given error type.
|
|
63
|
+
* @param {function} getSchemaFn - Function to get the schema.
|
|
64
|
+
* @param {Object} errorType - The error type.
|
|
65
|
+
* @param {string} errorType.serviceTag - Tag of the service.
|
|
66
|
+
* @param {string} errorType.errorTag - Tag of the error.
|
|
67
|
+
* @param {string} bucketName - Name of the bucket to get the schema from.
|
|
68
|
+
* @returns {{errorsFound: string[], result: Object[]}}
|
|
69
|
+
*/
|
|
70
|
+
async function getErrorSchemaPerTagS3(
|
|
71
|
+
getSchemaFn,
|
|
72
|
+
errorType,
|
|
73
|
+
bucketName = OBJECT_SCHEMA_BUCKET_NAME
|
|
74
|
+
) {
|
|
75
|
+
const validateErrorTypeRes = validateErrorType(errorType);
|
|
76
|
+
if (validateErrorTypeRes.errorsFound.length > 0) {
|
|
77
|
+
return {
|
|
78
|
+
errorsFound: validateErrorTypeRes.errorsFound,
|
|
79
|
+
result: null
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const getDataParams = {
|
|
84
|
+
schemaName: SCHEMA_NAME.perErrorSchemaTag,
|
|
85
|
+
getParams: errorType
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
let errorSchema = await getSchemaFn(getDataParams, bucketName);
|
|
89
|
+
if (!errorSchema) {
|
|
90
|
+
return {
|
|
91
|
+
errorsFound: [],
|
|
92
|
+
result: null
|
|
93
|
+
};
|
|
94
|
+
} else {
|
|
95
|
+
return {
|
|
96
|
+
errorsFound: [],
|
|
97
|
+
result: errorSchema
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Gets error schemas with throw action for a given error type.
|
|
104
|
+
* @param {function} getSchemaFn - Function to get the schema.
|
|
105
|
+
* @param {Object} errorType - The error type.
|
|
106
|
+
* @param {string} errorType.serviceTag - Tag of the service.
|
|
107
|
+
* @param {string} errorType.errorTag - Tag of the error.
|
|
108
|
+
* @param {string} bucketName - Name of the bucket to get the schema from.
|
|
109
|
+
* @returns {{errorsFound: string[], result: Object[]}}
|
|
110
|
+
*/
|
|
111
|
+
async function getActionThrowErrorSchemaS3(
|
|
112
|
+
getSchemaFn,
|
|
113
|
+
errorType,
|
|
114
|
+
bucketName = OBJECT_SCHEMA_BUCKET_NAME
|
|
115
|
+
) {
|
|
116
|
+
const validateErrorTypeRes = validateErrorType(errorType);
|
|
117
|
+
if (validateErrorTypeRes.errorsFound.length > 0) {
|
|
118
|
+
return {
|
|
119
|
+
errorsFound: validateErrorTypeRes.errorsFound,
|
|
120
|
+
result: null
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const getDataParams = {
|
|
125
|
+
schemaName: SCHEMA_NAME.perErrorSchemaTag,
|
|
126
|
+
getParams: errorType
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
let errorSchemas = await getSchemaFn(getDataParams, bucketName);
|
|
130
|
+
if (!errorSchemas) {
|
|
131
|
+
return {
|
|
132
|
+
errorsFound: [],
|
|
133
|
+
result: null
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const filterThrowAction = errorSchemas.filter(
|
|
138
|
+
errorSchema => errorSchema.errorAction === 'throw'
|
|
139
|
+
);
|
|
140
|
+
return {
|
|
141
|
+
errorsFound: [],
|
|
142
|
+
result: filterThrowAction
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Gets error schemas with return action for a given error type.
|
|
148
|
+
* @param {function} getSchemaFn - Function to get the schema.
|
|
149
|
+
* @param {Object} errorType - The error type.
|
|
150
|
+
* @param {string} errorType.serviceTag - Tag of the service.
|
|
151
|
+
* @param {string} errorType.errorTag - Tag of the error.
|
|
152
|
+
* @param {string} bucketName - Name of the bucket to get the schema from.
|
|
153
|
+
* @returns {{errorsFound: string[], result: Object[]}}
|
|
154
|
+
*/
|
|
155
|
+
async function getActionReturnErrorSchemaS3(
|
|
156
|
+
getSchemaFn,
|
|
157
|
+
errorType,
|
|
158
|
+
bucketName = OBJECT_SCHEMA_BUCKET_NAME
|
|
159
|
+
) {
|
|
160
|
+
const validateErrorTypeRes = validateErrorType(errorType);
|
|
161
|
+
if (validateErrorTypeRes.errorsFound.length > 0) {
|
|
162
|
+
return {
|
|
163
|
+
errorsFound: validateErrorTypeRes.errorsFound,
|
|
164
|
+
result: null
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const getDataParams = {
|
|
169
|
+
schemaName: SCHEMA_NAME.perErrorSchemaTag,
|
|
170
|
+
getParams: errorType
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
let errorSchemas = await getSchemaFn(getDataParams, bucketName);
|
|
174
|
+
if (!errorSchemas) {
|
|
175
|
+
return {
|
|
176
|
+
errorsFound: [],
|
|
177
|
+
result: null
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const filterReturnAction = errorSchemas.filter(
|
|
182
|
+
errorSchema => errorSchema.errorAction === 'return'
|
|
183
|
+
);
|
|
184
|
+
return {
|
|
185
|
+
errorsFound: [],
|
|
186
|
+
result: filterReturnAction
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
export default {
|
|
192
|
+
validateErrorType,
|
|
193
|
+
getErrorSchemaAllS3,
|
|
194
|
+
getErrorSchemaPerTagS3,
|
|
195
|
+
getActionThrowErrorSchemaS3,
|
|
196
|
+
getActionReturnErrorSchemaS3
|
|
197
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright(C) 2021 Sven Mason < http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and / or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or(at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program.If not, see < http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import consts from '../Consts.js';
|
|
19
|
+
import validateObjType from '../libs/ValidateObjType.js';
|
|
20
|
+
|
|
21
|
+
const { SCHEMA_NAME, OBJECT_SCHEMA_BUCKET_NAME } = consts;
|
|
22
|
+
|
|
23
|
+
async function getFlowSchemaS3(
|
|
24
|
+
getSchemaFn,
|
|
25
|
+
flowType,
|
|
26
|
+
bucketName = OBJECT_SCHEMA_BUCKET_NAME
|
|
27
|
+
) {
|
|
28
|
+
let errorsFound = [];
|
|
29
|
+
try {
|
|
30
|
+
validateObjType.validateFlowType(flowType);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
errorsFound.push(error.message);
|
|
33
|
+
return {
|
|
34
|
+
errorsFound: [error.message],
|
|
35
|
+
result: null
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getDataParams = {
|
|
40
|
+
schemaName: SCHEMA_NAME.flowSchema,
|
|
41
|
+
getParams: flowType
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
let flowSchema = await getSchemaFn(getDataParams, bucketName);
|
|
45
|
+
if (!flowSchema) {
|
|
46
|
+
// return objSchema;
|
|
47
|
+
return {
|
|
48
|
+
errorsFound: errorsFound,
|
|
49
|
+
result: null
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
return {
|
|
53
|
+
errorsFound: errorsFound,
|
|
54
|
+
result: flowSchema
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default {
|
|
60
|
+
getFlowSchemaS3
|
|
61
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright(C) 2021 Sven Mason < http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and / or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or(at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program.If not, see < http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import consts from '../Consts.js';
|
|
19
|
+
|
|
20
|
+
const { SCHEMA_NAME, OBJECT_SCHEMA_BUCKET_NAME } = consts;
|
|
21
|
+
|
|
22
|
+
async function getNotificationSchemaS3(
|
|
23
|
+
getSchemaFn,
|
|
24
|
+
serviceTag,
|
|
25
|
+
bucketName = OBJECT_SCHEMA_BUCKET_NAME
|
|
26
|
+
) {
|
|
27
|
+
const errorsFound = [];
|
|
28
|
+
try {
|
|
29
|
+
if (typeof serviceTag !== 'string') {
|
|
30
|
+
errorsFound.push('serviceTag not String');
|
|
31
|
+
}
|
|
32
|
+
} catch (error) {
|
|
33
|
+
errorsFound.push(error.message);
|
|
34
|
+
return {
|
|
35
|
+
errorsFound: [error.message],
|
|
36
|
+
result: null
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getDataParams = {
|
|
41
|
+
schemaName: SCHEMA_NAME.notificationSchemas,
|
|
42
|
+
getParams: serviceTag
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let notificationSchemas = await getSchemaFn(getDataParams, bucketName);
|
|
46
|
+
if (!notificationSchemas) {
|
|
47
|
+
// return objSchema;
|
|
48
|
+
return {
|
|
49
|
+
errorsFound: errorsFound,
|
|
50
|
+
result: null
|
|
51
|
+
};
|
|
52
|
+
} else {
|
|
53
|
+
return {
|
|
54
|
+
errorsFound: errorsFound,
|
|
55
|
+
result: notificationSchemas
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default {
|
|
61
|
+
getNotificationSchemaS3
|
|
62
|
+
}
|