@cocreate/authorize 1.12.0 → 1.13.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/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## [1.13.1](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.13.0...v1.13.1) (2024-01-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * get user from socket or data ([1e3a821](https://github.com/CoCreate-app/CoCreate-authorize/commit/1e3a82119e774c9714324e8780e453f43eecb9c4))
7
+ * update to support new query system ([0ddfeca](https://github.com/CoCreate-app/CoCreate-authorize/commit/0ddfeca394ae44b1c56499df38df0b96c0b15396))
8
+
9
+ # [1.13.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.12.0...v1.13.0) (2024-01-08)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * applied host to define environment/branch ([56ff08a](https://github.com/CoCreate-app/CoCreate-authorize/commit/56ff08a0929003b37658ab394c74bf1e429cecd5))
15
+
16
+
17
+ ### Features
18
+
19
+ * bumped CoCreate dependencies to their latest versions ([641c52b](https://github.com/CoCreate-app/CoCreate-authorize/commit/641c52b6af630d7164cc9e720d00e4e40d7e3d11))
20
+
1
21
  # [1.12.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.11.0...v1.12.0) (2023-12-21)
2
22
 
3
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/authorize",
3
- "version": "1.12.0",
3
+ "version": "1.13.1",
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",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "main": "./src/index.js",
47
47
  "dependencies": {
48
- "@cocreate/crud-client": "^1.31.0",
49
- "@cocreate/utils": "^1.29.0"
48
+ "@cocreate/crud-client": "^1.32.2",
49
+ "@cocreate/utils": "^1.30.0"
50
50
  }
51
51
  }
package/src/index.js CHANGED
@@ -37,7 +37,7 @@
37
37
  if (array === 'keys' && object) {
38
38
  let authorization = object[0]
39
39
  if (authorization && authorization.key && organizations[organization_id] && organizations[organization_id][authorization.key]) {
40
- let newAuthorization = await readAuthorization(authorization.key, organization_id)
40
+ let newAuthorization = await readAuthorization(authorization.key, data)
41
41
  organizations[organization_id][authorization.key] = newAuthorization
42
42
  }
43
43
  }
@@ -54,36 +54,39 @@
54
54
  }
55
55
  }
56
56
 
57
- async function getAuthorization(key, organization_id) {
57
+ async function getAuthorization(key, data) {
58
+ let organization_id = data.organization_id
58
59
  if (!organizations[organization_id])
59
60
  organizations[organization_id] = {}
60
61
 
61
62
  if (!organizations[organization_id][key])
62
- organizations[organization_id][key] = readAuthorization(key, organization_id);
63
+ organizations[organization_id][key] = readAuthorization(key, data);
63
64
 
64
65
  organizations[organization_id][key] = await organizations[organization_id][key]
65
66
  return organizations[organization_id][key]
66
67
  }
67
68
 
68
- async function readAuthorization(key, organization_id) {
69
+ async function readAuthorization(key, data) {
69
70
  try {
71
+ let organization_id = data.organization_id
70
72
  if (!organization_id)
71
73
  return { error: 'An organization_id is required' };
72
74
 
73
75
  let request = {
74
76
  method: 'object.read',
77
+ host: data.host,
75
78
  database: organization_id,
76
79
  array: 'keys',
77
80
  organization_id,
78
81
  $filter: {
79
- query: []
82
+ query: {}
80
83
  }
81
84
  }
82
85
 
83
86
  if (key)
84
- request.$filter.query.push({ key: 'key', value: key, operator: '$eq' })
87
+ request.$filter.query.key = key
85
88
  else
86
- request.$filter.query.push({ key: 'default', value: true, operator: '$eq' })
89
+ request.$filter.query.default = true
87
90
 
88
91
 
89
92
  let authorization = await crud.send(request)
@@ -146,7 +149,7 @@
146
149
  if (!data.method)
147
150
  return { error: 'method is required' };
148
151
 
149
- let authorized = await getAuthorization(key, data.organization_id)
152
+ let authorized = await getAuthorization(key, data)
150
153
  if (!authorized || authorized.error)
151
154
  return authorized
152
155
  if (authorized.organization_id !== data.organization_id)
@@ -230,18 +233,17 @@
230
233
 
231
234
  async function checkMethodOperators(data, key, value) {
232
235
  if (value === 'this.userId' && data.socket)
233
- value = data.socket.user_id
236
+ value = data.socket.user_id || data.user_id
234
237
 
238
+ // TODO: support our standard query system
235
239
  let keys = key.split('.')
236
240
  if (['$eq', '$ne', '$lt', '$lte', '$gt', '$gte', '$in', '$nin', '$or', '$and', '$not', '$nor', '$exists', '$type', '$mod', '$regex', '$text', '$where', '$all', '$elemMatch', '$size'].includes(keys[0])) {
237
- // let keys = key.split('.')
238
- let query = { key: keys[1], value, operator: keys[0] }
239
241
  if (!data.$filter)
240
- data.$filter = { query: [query] }
242
+ data.$filter = { query: {} }
241
243
  else if (!data.$filter.query)
242
- data.$filter.query = [query]
243
- else
244
- data.$filter.query.push(query)
244
+ data.$filter.query = {}
245
+
246
+ data.$filter.query[keys[1]] = { [keys[0]]: value }
245
247
 
246
248
  } else {
247
249
  if (key === '$array' && value === 'questions') {
@@ -272,10 +274,12 @@
272
274
  for (let value of authorized[apikey]) {
273
275
  if (value[key])
274
276
  value = value[key]
277
+ if (!data.object.$filter.query.$or)
278
+ data.object.$filter.query.$or = []
275
279
  if (unauthorize)
276
- data.object.$filter.query.push({ key, value, operator: '$ne', logicalOperator: 'or' })
280
+ data.object.$filter.query.$or.push({ [key]: { $ne: value } })
277
281
  else
278
- data.object.$filter.query.push({ key, value, operator: '$eq', logicalOperator: 'or' })
282
+ data.object.$filter.query.$or.push({ [key]: value })
279
283
  }
280
284
  if (!unauthorize)
281
285
  return true