@cocreate/authorize 1.6.4 → 1.6.5

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": "@cocreate/authorize",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "A simple authorize component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "authorize",
@@ -34,7 +34,7 @@
34
34
  "url": "git+https://github.com/CoCreate-app/CoCreate-authorize.git"
35
35
  },
36
36
  "author": "CoCreate LLC",
37
- "license": "SSPL-1.0",
37
+ "license": "AGPL-3.0",
38
38
  "bugs": {
39
39
  "url": "https://github.com/CoCreate-app/CoCreate-authorize/issues"
40
40
  },
package/src/index.js CHANGED
@@ -81,15 +81,17 @@
81
81
  method: 'read.object',
82
82
  array: 'keys',
83
83
  organization_id,
84
- filter: {
85
- query: []
84
+ object: {
85
+ $filter: {
86
+ query: []
87
+ }
86
88
  }
87
89
  }
88
90
 
89
91
  if (key)
90
- request.filter.query.push({ key: 'key', value: key, operator: '$eq' })
92
+ request.object.$filter.query.push({ key: 'key', value: key, operator: '$eq' })
91
93
  else
92
- request.filter.query.push({ key: 'default', value: true, operator: '$eq' })
94
+ request.object.$filter.query.push({ key: 'default', value: true, operator: '$eq' })
93
95
 
94
96
 
95
97
  let authorization = await crud.send(request)
@@ -107,7 +109,7 @@
107
109
  role_ids.push({ _id })
108
110
  })
109
111
 
110
- delete request.filter
112
+ delete request.object.$filter
111
113
  delete request.request
112
114
  request.object = role_ids
113
115
 
@@ -182,7 +184,7 @@
182
184
 
183
185
  async function checkAuthorization({ key, data }) {
184
186
  // let method = data.method
185
- let { method, organization_id, filter, endPoint } = data
187
+ let { method, organization_id, endPoint } = data
186
188
  if (!key || !organization_id) return false;
187
189
 
188
190
  let autorized = await getAuthorization(key, organization_id)
@@ -198,7 +200,7 @@
198
200
  if (autorized.admin == 'true' || autorized.admin === true)
199
201
  return true;
200
202
 
201
- let status = await checkMethod(autorized.actions, method, endPoint, data, filter)
203
+ let status = await checkMethod(autorized.actions, method, endPoint, data)
202
204
 
203
205
  if (!status)
204
206
  return false
@@ -348,20 +350,20 @@
348
350
  }
349
351
 
350
352
  async function checkFilter(authorized, data, apikey, unauthorize) {
351
- if (data.filter && data.filter.query) {
353
+ if (data.object.$filter && data.object.$filter.query) {
352
354
  let key
353
- if (data.filter.type == 'object')
355
+ if (data.object.$filter.type == 'object')
354
356
  key = '_id'
355
- else if (data.filter.type == 'array')
357
+ else if (data.object.$filter.type == 'array')
356
358
  key = 'name'
357
359
  if (key) {
358
360
  for (let value of authorized[apikey]) {
359
361
  if (value[key])
360
362
  value = value[key]
361
363
  if (unauthorize)
362
- data.filter.query.push({ key, value, operator: '$ne', logicalOperator: 'or' })
364
+ data.object.$filter.query.push({ key, value, operator: '$ne', logicalOperator: 'or' })
363
365
  else
364
- data.filter.query.push({ key, value, operator: '$eq', logicalOperator: 'or' })
366
+ data.object.$filter.query.push({ key, value, operator: '$eq', logicalOperator: 'or' })
365
367
  }
366
368
  if (!unauthorize)
367
369
  return true