@cocreate/authorize 1.1.0 → 1.2.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/src/index.js CHANGED
@@ -1,372 +1,384 @@
1
- (function (root, factory) {
2
- if (typeof define === 'function' && define.amd) {
3
- define(["@cocreate/crud-client"], function (crud) {
4
- return factory(true, crud)
5
- });
6
- } else if (typeof module === 'object' && module.exports) {
7
- module.exports = class CoCreateAuthorize {
8
- constructor(crud) {
9
- return factory(false, crud);
10
- }
11
- }
12
- } else {
13
- root.returnExports = factory(true, root["@cocreate/crud-client"]);
14
- }
15
- }(typeof self !== 'undefined' ? self : this, function (isBrowser, crud) {
16
-
17
- const permissions = new Map()
18
-
19
- if (isBrowser) {
20
- crud.listen('updateDocument', function (data) {
21
- updatePermission(data)
22
- });
23
-
24
- crud.listen('deleteDocument', function (data) {
25
- deletePermission(data)
26
- });
27
- } else {
28
- process.on('changed-document', async (data) => {
29
- updatePermission(data)
30
- })
31
- }
32
-
33
- async function updatePermission(data) {
34
- const { collection, document, organization_id } = data
35
-
36
- if (collection === 'keys' && document) {
37
- let permission = document[0]
38
- if (permission && permission.key && hasPermission(permission.key)) {
39
- let newPermission = await readPermisson(permission.key, organization_id)
40
- setPermission(permission.key, newPermission)
41
- }
42
- }
43
- }
44
-
45
- function setPermission(key, permission) {
46
- permissions.set(key, permission)
47
- }
48
-
49
- function hasPermission(key) {
50
- return permissions.has(key)
51
- }
52
-
53
- async function getPermission(key, organization_id) {
54
- if (permissions.get(key)) {
55
- return permissions.get(key)
56
- } else {
57
- let permission = await readPermisson(key, organization_id);
58
- permissions.set(key, permission)
59
- return permission
60
- }
61
- }
62
-
63
- async function readPermisson(key, organization_id) {
64
- try {
65
- if (!organization_id)
66
- return null;
67
-
68
- let request = {
69
- collection: 'keys',
70
- organization_id,
71
- filter: {
72
- query: []
73
- }
74
- }
75
-
76
- if (key)
77
- request.filter.query.push({ name: 'key', value: key, operator: '$eq' })
78
- else
79
- request.filter.query.push({ name: 'default', value: true, operator: '$eq' })
80
-
81
-
82
- let permission = await crud.readDocument(request)
83
- if (permission && permission.document && permission.document[0]) {
84
- permission = permission.document[0]
85
-
86
- if (!permission.collections) {
87
- permission.collections = {};
88
- }
89
-
90
- if (permission && permission.roles) {
91
- const role_ids = []
92
- permission.roles.forEach((_id) => {
93
- if (_id)
94
- role_ids.push({ _id })
95
- })
96
-
97
- delete request.filter
98
- delete request.request
99
- request.document = role_ids
100
-
101
- let roles = await crud.readDocument(request)
102
- roles = roles.document
103
-
104
- permission = createPermissionObject(permission, roles)
105
- }
106
-
107
- }
108
-
109
- return permission;
110
-
111
- } catch (error) {
112
- console.log("Permission Error", error)
113
- return null;
114
- }
115
-
116
- }
117
-
118
- async function createPermissionObject(permission, roles) {
119
- roles.map(role => {
120
- for (const roleKey in role) {
121
- if (!["_id", "type", "name", "organization_id"].includes(roleKey)) {
122
- if (!permission[roleKey]) {
123
- permission[roleKey] = role[roleKey]
124
- } else {
125
- if (Array.isArray(role[roleKey])) {
126
- for (let item of role[roleKey]) {
127
- if (!permission[roleKey].includes(item))
128
- permission[roleKey].push(item)
129
- }
130
- }
131
- else if (typeof role[roleKey] == 'object') {
132
- for (const c of Object.keys(role[roleKey])) {
133
- if (!permission[roleKey][c]) {
134
- permission[roleKey][c] = role[roleKey][c]
135
- } else {
136
- if (typeof role[roleKey][c] == 'object') {
137
- permission[roleKey][c] = { ...permission[roleKey][c], ...role[roleKey][c] }
138
- } else {
139
- permission[roleKey][c] = role[roleKey][c]
140
- }
141
- }
142
- }
143
- } else {
144
- permission[roleKey] = role[roleKey]
145
- }
146
- }
147
- }
148
- }
149
- })
150
- return permission;
151
- }
152
-
153
- async function check(action, data, user_id) {
154
- let permission = false
155
- if (user_id) {
156
- permission = await checkPermissionObject({
157
- key: user_id,
158
- action,
159
- data
160
- })
161
- }
162
- if (!permission || permission.error) {
163
- permission = await checkPermissionObject({
164
- key: data.key,
165
- action,
166
- data
167
- })
168
- }
169
- return permission;
170
- }
171
-
172
- async function checkPermissionObject({ key, action, data }) {
173
- let { organization_id, filter, endPoint } = data
174
- if (!key || !organization_id) return false;
175
-
176
- let permission = await getPermission(key, organization_id)
177
- if (!permission || permission.error)
178
- return permission
179
- if (permission.organization_id !== organization_id)
180
- return false;
181
- if (permission.hosts && permission.hosts.length) {
182
- if (!permission.hosts || (!permission.hosts.includes(data.host) && !permission.hosts.includes("*")))
183
- return false;
184
-
185
- }
186
- if (permission.admin == 'true' || permission.admin === true)
187
- return true;
188
-
189
- // if (data.request) {
190
- // let type = action.match(/[A-Z][a-z]+/g);
191
- // type = type[0].toLowerCase()
192
- // data[type] = data.request
193
- // }
194
-
195
- let status = await checkAction(permission.actions, action, endPoint, data, filter)
196
-
197
- if (!status)
198
- return false
199
-
200
- return { authorized: data };
201
- }
202
-
203
- async function checkAction(permissions, action, endPoint, data) {
204
- if (!permissions || !action || !permissions[action] || permissions[action] == 'false') return false;
205
- if (permissions[action] === true || permissions[action] == 'true' || permissions[action] == '*') return true;
206
-
207
- let authorized = permissions[action].authorize
208
- if (authorized) {
209
- let status = await checkAthorized(authorized, action, endPoint, data)
210
- if (!status)
211
- return false
212
- else {
213
- let unauthorized = permissions[action].unauthorize
214
- if (unauthorized) {
215
- let status = await checkAthorized(unauthorized, action, endPoint, data, true)
216
- if (status)
217
- return false
218
- }
219
- return true
220
- }
221
- } else
222
- return false
223
- }
224
-
225
- async function checkAthorized(authorized, action, endPoint, data, unauthorize) {
226
- if (!Array.isArray(authorized))
227
- authorized = [authorized]
228
-
229
- let status = false
230
- for (let i = 0; i < authorized.length; i++) {
231
- // if authorized[i] is a booleaan
232
- if (authorized[i] === true)
233
- return true
234
-
235
- // if authorized[i] is a string or an array
236
- if (typeof authorized[i] === "string" || Array.isArray(authorized[i])) {
237
- if (authorized[i].includes(true) || authorized[i].includes('true') || authorized[i].includes('*'))
238
- return true
239
- else if (endPoint)
240
- return authorized.includes(endPoint)
241
- else
242
- return false
243
- }
244
-
245
- // if authorized[i] is an object
246
- for (const key of Object.keys(authorized[i])) {
247
- status = await checkAthorizedKey(authorized[i], action, endPoint, data, key, unauthorize)
248
- }
249
-
250
- }
251
-
252
- return status
253
-
254
- }
255
-
256
- async function checkAthorizedKey(authorized, action, endPoint, data, key, unauthorize) {
257
- let status = false;
258
- let keyStatus = false;
259
-
260
- // if authorized[key] is a booleaan
261
- if (authorized[key] === true)
262
- keyStatus = true
263
-
264
- // if authorized[key] is a string or number
265
- else if (typeof authorized[key] === "string" || typeof authorized[key] === "number") {
266
- if (authorized[key] === true || authorized[key] === 'true' || authorized[key] === '*')
267
- keyStatus = true
268
- else if (data[key]) {
269
- keyStatus = await checkArray(authorized, data, key, unauthorize)
270
- if (await checkFilter(authorized, data, key, unauthorize))
271
- status = true
272
- }
273
- }
274
-
275
- // if authorized[key] is an array
276
- else if (Array.isArray(authorized[key])) {
277
- if (authorized[key].includes(true) || authorized[key].includes('true') || authorized[key].includes('*'))
278
- keyStatus = true
279
- else if (data[key]) {
280
- keyStatus = await checkArray(authorized, data, key, unauthorize)
281
- if (await checkFilter(authorized, data, key, unauthorize))
282
- status = true
283
- }
284
- }
285
-
286
- // if authorized[key] is an object
287
- else if (typeof authorized[key] === "object") {
288
- console.log('authorized[key] is an object', authorized[key])
289
- } else
290
- delete data[key]
291
-
292
- // if key status is true for unauthorized case
293
- if (!keyStatus || keyStatus && unauthorize) {
294
- if (!data.unauthorized || !data.unauthorized[action])
295
- data.unauthorized = { [action]: { [key]: [data[key]] } }
296
- else if (!data.unauthorized[action][key])
297
- data.unauthorized[action][key] = [data[key]]
298
- else
299
- data.unauthorized[action][key].push(data[key])
300
- } else
301
- status = true
302
- return status
303
- }
304
-
305
- async function checkArray(authorized, data, key, unauthorize) {
306
- let keyStatus = false
307
- let authorizedValue = eval('authorized.' + key)
308
- let dataValue = eval('data.' + key)
309
-
310
- if (!authorizedValue && !unauthorize) {
311
- if (key.endsWith(']')) {
312
- let lastIndex = key.lastIndexOf('[')
313
- let index = key.slice(lastIndex + 1).slice(0, -1)
314
- let nkey = key.slice(0, key.length - (index.length + 2))
315
- console.log(index, nkey);
316
- eval(`data.${nkey}.splice(${index}, 1)`)
317
- } else
318
- eval(`delete data.${key}`)
319
- } else if (typeof dataValue == "string") {
320
- if (unauthorize && authorizedValue.includes(dataValue))
321
- eval(`delete data.${key}`)
322
- else {
323
- if (!authorizedValue.includes(dataValue))
324
- eval(`delete data.${key}`)
325
- else
326
- keyStatus = true
327
- }
328
-
329
- } else if (Array.isArray(dataValue)) {
330
- for (let i = 0; i < dataValue.length; i++) {
331
- let nkey = key + `[${i}]`
332
- keyStatus = await checkArray(authorized, data, nkey, unauthorize)
333
- }
334
- } else if (typeof dataValue === "object") {
335
- if (authorizedValue['*'] || authorizedValue['*'] == '') {
336
- keyStatus = true
337
- } else
338
- for (const k of Object.keys(dataValue)) {
339
- let nkey = `${key}.${k}`
340
- keyStatus = await checkArray(authorized, data, nkey, unauthorize)
341
- }
342
- }
343
- return keyStatus
344
- }
345
-
346
- async function checkFilter(authorized, data, key, unauthorize) {
347
- if (data.filter && data.filter.query) {
348
- let name
349
- if (data.filter.type == 'document')
350
- name = '_id'
351
- else if (data.filter.type == 'collection')
352
- name = 'name'
353
- if (name) {
354
- for (let value of authorized[key]) {
355
- if (value[name])
356
- value = value[name]
357
- if (unauthorize)
358
- data.filter.query.push({ name, value, operator: '$ne', logicalOperator: 'or' })
359
- else
360
- data.filter.query.push({ name, value, operator: '$eq', logicalOperator: 'or' })
361
- }
362
- if (!unauthorize)
363
- return true
364
- }
365
- }
366
- }
367
-
368
- return {
369
- check
370
- }
371
-
372
- }));
1
+ (function (root, factory) {
2
+ if (typeof define === 'function' && define.amd) {
3
+ define(["@cocreate/crud-client", "@cocreate/utils"], function (crud, { getValueFromObject, dotNotationToObject }) {
4
+ return factory(true, crud, { getValueFromObject, dotNotationToObject })
5
+ });
6
+ } else if (typeof module === 'object' && module.exports) {
7
+ const { getValueFromObject, dotNotationToObject } = require("@cocreate/utils");
8
+ module.exports = class CoCreateAuthorize {
9
+ constructor(crud) {
10
+ return factory(false, crud, { getValueFromObject, dotNotationToObject });
11
+ }
12
+ }
13
+ } else {
14
+ root.returnExports = factory(true, root["@cocreate/crud-client"], root["@cocreate/utils"]);
15
+ }
16
+ }(typeof self !== 'undefined' ? self : this, function (isBrowser, crud, { getValueFromObject, dotNotationToObject }) {
17
+
18
+ const permissions = new Map()
19
+
20
+ if (isBrowser) {
21
+ crud.listen('updateDocument', function (data) {
22
+ updatePermission(data)
23
+ });
24
+
25
+ crud.listen('deleteDocument', function (data) {
26
+ deletePermission(data)
27
+ });
28
+ } else {
29
+ process.on('changed-document', async (data) => {
30
+ updatePermission(data)
31
+ })
32
+ }
33
+
34
+ async function updatePermission(data) {
35
+ const { collection, document, organization_id } = data
36
+
37
+ if (collection === 'keys' && document) {
38
+ let permission = document[0]
39
+ if (permission && permission.key && hasPermission(permission.key)) {
40
+ let newPermission = await readPermisson(permission.key, organization_id)
41
+ setPermission(permission.key, newPermission)
42
+ }
43
+ }
44
+ }
45
+
46
+ async function deletePermission(data) {
47
+ const { collection, document, organization_id } = data
48
+
49
+ if (collection === 'keys' && document) {
50
+ let permission = document[0]
51
+ if (permission && permission.key && hasPermission(permission.key)) {
52
+ permissions.delete(permission.key)
53
+ }
54
+ }
55
+ }
56
+
57
+ function setPermission(key, permission) {
58
+ permissions.set(key, permission)
59
+ }
60
+
61
+ function hasPermission(key) {
62
+ return permissions.has(key)
63
+ }
64
+
65
+ async function getPermission(key, organization_id) {
66
+ if (permissions.get(key)) {
67
+ return permissions.get(key)
68
+ } else {
69
+ let permission = await readPermisson(key, organization_id);
70
+ permissions.set(key, permission)
71
+ return permission
72
+ }
73
+ }
74
+
75
+ async function readPermisson(key, organization_id) {
76
+ try {
77
+ if (!organization_id)
78
+ return null;
79
+
80
+ let request = {
81
+ collection: 'keys',
82
+ organization_id,
83
+ filter: {
84
+ query: []
85
+ }
86
+ }
87
+
88
+ if (key)
89
+ request.filter.query.push({ name: 'key', value: key, operator: '$eq' })
90
+ else
91
+ request.filter.query.push({ name: 'default', value: true, operator: '$eq' })
92
+
93
+
94
+ let permission = await crud.readDocument(request)
95
+ if (permission && permission.document && permission.document[0]) {
96
+ permission = permission.document[0]
97
+
98
+ if (!permission.collections) {
99
+ permission.collections = {};
100
+ }
101
+
102
+ if (permission && permission.roles) {
103
+ const role_ids = []
104
+ permission.roles.forEach((_id) => {
105
+ if (_id)
106
+ role_ids.push({ _id })
107
+ })
108
+
109
+ delete request.filter
110
+ delete request.request
111
+ request.document = role_ids
112
+
113
+ let roles = await crud.readDocument(request)
114
+ roles = roles.document
115
+
116
+ permission = createPermissionObject(permission, roles)
117
+ }
118
+
119
+ }
120
+
121
+ return permission;
122
+
123
+ } catch (error) {
124
+ console.log("Permission Error", error)
125
+ return null;
126
+ }
127
+
128
+ }
129
+
130
+ async function createPermissionObject(permission, roles) {
131
+ roles.map(role => {
132
+ for (const roleKey in role) {
133
+ if (!["_id", "type", "name", "organization_id"].includes(roleKey)) {
134
+ if (!permission[roleKey]) {
135
+ permission[roleKey] = role[roleKey]
136
+ } else {
137
+ if (Array.isArray(role[roleKey])) {
138
+ for (let item of role[roleKey]) {
139
+ if (!permission[roleKey].includes(item))
140
+ permission[roleKey].push(item)
141
+ }
142
+ }
143
+ else if (typeof role[roleKey] == 'object') {
144
+ for (const c of Object.keys(role[roleKey])) {
145
+ if (!permission[roleKey][c]) {
146
+ permission[roleKey][c] = role[roleKey][c]
147
+ } else {
148
+ if (typeof role[roleKey][c] == 'object') {
149
+ permission[roleKey][c] = { ...permission[roleKey][c], ...role[roleKey][c] }
150
+ } else {
151
+ permission[roleKey][c] = role[roleKey][c]
152
+ }
153
+ }
154
+ }
155
+ } else {
156
+ permission[roleKey] = role[roleKey]
157
+ }
158
+ }
159
+ }
160
+ }
161
+ })
162
+ return permission;
163
+ }
164
+
165
+ async function check(action, data, user_id) {
166
+ let permission = false
167
+ if (user_id) {
168
+ permission = await checkPermissionObject({
169
+ key: user_id,
170
+ action,
171
+ data
172
+ })
173
+ }
174
+ if (!permission || permission.error) {
175
+ permission = await checkPermissionObject({
176
+ key: data.key,
177
+ action,
178
+ data
179
+ })
180
+ }
181
+ return permission;
182
+ }
183
+
184
+ async function checkPermissionObject({ key, action, data }) {
185
+ let { organization_id, filter, endPoint } = data
186
+ if (!key || !organization_id) return false;
187
+
188
+ let permission = await getPermission(key, organization_id)
189
+ if (!permission || permission.error)
190
+ return permission
191
+ if (permission.organization_id !== organization_id)
192
+ return false;
193
+ if (permission.hosts && permission.hosts.length) {
194
+ if (!permission.hosts || (!permission.hosts.includes(data.host) && !permission.hosts.includes("*")))
195
+ return false;
196
+
197
+ }
198
+ if (permission.admin == 'true' || permission.admin === true)
199
+ return true;
200
+
201
+ let status = await checkAction(permission.actions, action, endPoint, data, filter)
202
+
203
+ if (!status)
204
+ return false
205
+
206
+ return { authorized: data };
207
+ }
208
+
209
+ async function checkAction(permissions, action, endPoint, data) {
210
+ if (!permissions || !action || !permissions[action] || permissions[action] == 'false') return false;
211
+ if (permissions[action] === true || permissions[action] == 'true' || permissions[action] == '*') return true;
212
+
213
+ let authorized = permissions[action].authorize
214
+ if (authorized) {
215
+ let status = await checkAthorized(authorized, action, endPoint, data)
216
+ if (!status)
217
+ return false
218
+ else {
219
+ let unauthorized = permissions[action].unauthorize
220
+ if (unauthorized) {
221
+ let status = await checkAthorized(unauthorized, action, endPoint, data, true)
222
+ if (status)
223
+ return false
224
+ }
225
+ return true
226
+ }
227
+ } else
228
+ return false
229
+ }
230
+
231
+ async function checkAthorized(authorized, action, endPoint, data, unauthorize) {
232
+ if (!Array.isArray(authorized))
233
+ authorized = [authorized]
234
+
235
+ let status = false
236
+ for (let i = 0; i < authorized.length; i++) {
237
+ // if authorized[i] is a booleaan
238
+ if (authorized[i] === true)
239
+ return true
240
+
241
+ // if authorized[i] is a string or an array
242
+ if (typeof authorized[i] === "string" || Array.isArray(authorized[i])) {
243
+ if (authorized[i].includes(true) || authorized[i].includes('true') || authorized[i].includes('*'))
244
+ return true
245
+ else if (endPoint)
246
+ return authorized.includes(endPoint)
247
+ else
248
+ return false
249
+ }
250
+
251
+ // if authorized[i] is an object
252
+ for (const key of Object.keys(authorized[i])) {
253
+ status = await checkAthorizedKey(authorized[i], action, endPoint, data, key, unauthorize)
254
+ }
255
+
256
+ }
257
+
258
+ return status
259
+
260
+ }
261
+
262
+ async function checkAthorizedKey(authorized, action, endPoint, data, key, unauthorize) {
263
+ let status = false;
264
+ let keyStatus = false;
265
+
266
+ // if authorized[key] is a booleaan
267
+ if (authorized[key] === true)
268
+ keyStatus = true
269
+
270
+ // if authorized[key] is a string or number
271
+ else if (typeof authorized[key] === "string" || typeof authorized[key] === "number") {
272
+ if (authorized[key] === true || authorized[key] === 'true' || authorized[key] === '*')
273
+ keyStatus = true
274
+ else if (data[key]) {
275
+ keyStatus = await checkArray(authorized, data, key, unauthorize)
276
+ if (await checkFilter(authorized, data, key, unauthorize))
277
+ status = true
278
+ }
279
+ }
280
+
281
+ // if authorized[key] is an array
282
+ else if (Array.isArray(authorized[key])) {
283
+ if (authorized[key].includes(true) || authorized[key].includes('true') || authorized[key].includes('*'))
284
+ keyStatus = true
285
+ else if (data[key]) {
286
+ keyStatus = await checkArray(authorized, data, key, unauthorize)
287
+ if (await checkFilter(authorized, data, key, unauthorize))
288
+ status = true
289
+ }
290
+ }
291
+
292
+ // if authorized[key] is an object
293
+ else if (typeof authorized[key] === "object") {
294
+ console.log('authorized[key] is an object', authorized[key])
295
+ } else
296
+ delete data[key]
297
+
298
+ // if key status is false for unauthorized case
299
+ if (!keyStatus || keyStatus && unauthorize) {
300
+ if (!data.unauthorized || !data.unauthorized[action])
301
+ data.unauthorized = { [action]: { [key]: [data[key]] } }
302
+ else if (!data.unauthorized[action][key])
303
+ data.unauthorized[action][key] = [data[key]]
304
+ else
305
+ data.unauthorized[action][key].push(data[key])
306
+ } else
307
+ status = true
308
+ return status
309
+ }
310
+
311
+ async function checkArray(authorized, data, key, unauthorize) {
312
+ let keyStatus = false
313
+ let authorizedValue = getValueFromObject(authorized, key);
314
+ let dataValue = getValueFromObject(data, key);
315
+
316
+ if (!authorizedValue && !unauthorize) {
317
+ data = deleteKey(data, key)
318
+ } else if (typeof dataValue == "string") {
319
+ if (unauthorize && authorizedValue.includes(dataValue))
320
+ data = deleteKey(data, key)
321
+ else {
322
+ if (!authorizedValue.includes(dataValue))
323
+ data = deleteKey(data, key)
324
+ else
325
+ keyStatus = true
326
+ }
327
+ } else if (Array.isArray(dataValue)) {
328
+ for (let i = 0; i < dataValue.length; i++) {
329
+ keyStatus = await checkArray(authorized, data, `${key}[${i}]`, unauthorize)
330
+ }
331
+ } else if (typeof dataValue === "object") {
332
+ let checkKeys = true
333
+ if (dataValue['_id']) {
334
+ if (authorized.document.includes(dataValue['_id']))
335
+ checkKeys = true
336
+ }
337
+ if (checkKeys) {
338
+ if (authorizedValue['*'] || authorizedValue['*'] == '')
339
+ keyStatus = true
340
+ else
341
+ for (const k of Object.keys(dataValue)) {
342
+ keyStatus = await checkArray(authorized, data, `${key}.${k}`, unauthorize)
343
+ }
344
+ }
345
+ }
346
+
347
+ return keyStatus
348
+ }
349
+
350
+ async function checkFilter(authorized, data, key, unauthorize) {
351
+ if (data.filter && data.filter.query) {
352
+ let name
353
+ if (data.filter.type == 'document')
354
+ name = '_id'
355
+ else if (data.filter.type == 'collection')
356
+ name = 'name'
357
+ if (name) {
358
+ for (let value of authorized[key]) {
359
+ if (value[name])
360
+ value = value[name]
361
+ if (unauthorize)
362
+ data.filter.query.push({ name, value, operator: '$ne', logicalOperator: 'or' })
363
+ else
364
+ data.filter.query.push({ name, value, operator: '$eq', logicalOperator: 'or' })
365
+ }
366
+ if (!unauthorize)
367
+ return true
368
+ }
369
+ }
370
+ }
371
+
372
+ function deleteKey(data, path) {
373
+ if (!data || !path) return
374
+ if (path.includes('._id'))
375
+ path = path.replace('._id', '');
376
+ data = dotNotationToObject({ [path]: undefined }, data)
377
+ return data
378
+ }
379
+
380
+ return {
381
+ check
382
+ }
383
+
384
+ }));