@cocreate/authorize 1.3.14 → 1.5.0

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,25 @@
1
+ # [1.5.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.4.0...v1.5.0) (2023-08-17)
2
+
3
+
4
+ ### Features
5
+
6
+ * bump cocreate dependencies for the latest updates and features ([6614a3a](https://github.com/CoCreate-app/CoCreate-authorize/commit/6614a3ab6c0f31a430f61f94908752c8eb24baeb))
7
+
8
+ # [1.4.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.3.14...v1.4.0) (2023-08-16)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * crud attributes renamed ([6c66db2](https://github.com/CoCreate-app/CoCreate-authorize/commit/6c66db2efd13914e1315df639335624cf75d433a))
14
+ * Refactored *-target to *-selector ([bc6e173](https://github.com/CoCreate-app/CoCreate-authorize/commit/bc6e173f053d8441c60d85382db0c277259b78ce))
15
+ * typo crud.sent updated to crud.send ([a705592](https://github.com/CoCreate-app/CoCreate-authorize/commit/a7055922b05c82be1f4786552c7df60c7e7ed11d))
16
+ * webpack.config and package.json make use of mode=production instead of process.env ([94334dc](https://github.com/CoCreate-app/CoCreate-authorize/commit/94334dc7ebfa724383c477eb6833eb9f6c3461e2))
17
+
18
+
19
+ ### Features
20
+
21
+ * name attribute and variable renamed to key ([e09073e](https://github.com/CoCreate-app/CoCreate-authorize/commit/e09073e69ab810d8fbd08b37ae955df324a0be72))
22
+
1
23
  ## [1.3.14](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.3.13...v1.3.14) (2023-06-14)
2
24
 
3
25
 
@@ -4,8 +4,8 @@ module.exports = {
4
4
  "host": "",
5
5
  "sources": [
6
6
  {
7
- "collection": "files",
8
- "document": {
7
+ "array": "files",
8
+ "object": {
9
9
  "_id": "637ca55150234ef1671ce324",
10
10
  "name": "index.html",
11
11
  "path": "/docs/authorize/index.html",
package/docs/index.html CHANGED
@@ -11,10 +11,10 @@
11
11
  sizes="32x32"
12
12
  href="https://cocreate.app/images/favicon.ico" />
13
13
  <meta
14
- name="description"
14
+ key="description"
15
15
  content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
16
  <meta
17
- name="keywords"
17
+ key="keywords"
18
18
  content="helper classes, utility classes, css framework, css library, inline style classes" />
19
19
  <meta name="robots" content="index,follow" />
20
20
 
@@ -28,7 +28,7 @@
28
28
  </head>
29
29
 
30
30
  <body>
31
- <div collection="" document_id="" name="" id="cocreate-authorize">
31
+ <div array="" object="" key="" id="cocreate-authorize">
32
32
  <div
33
33
  class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
34
34
  <div class="display:flex align-items:center">
@@ -153,9 +153,9 @@
153
153
  <textarea
154
154
  type="code"
155
155
  lang="html"
156
- collection="demos"
157
- document_id=""
158
- name="demo"
156
+ array="demos"
157
+ object=""
158
+ key="demo"
159
159
  save="false"
160
160
  id="demo"
161
161
  class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
@@ -178,7 +178,7 @@
178
178
  show="#eye-slash"
179
179
  hide="#eye, #demo-preview"
180
180
  toggle="code-height"
181
- toggle-target="#demo-code"
181
+ toggle-selector="#demo-code"
182
182
  ><i class="far fa-eye"></i
183
183
  ></a>
184
184
  <a
@@ -188,7 +188,7 @@
188
188
  show="#eye, #demo-preview"
189
189
  hide="#eye-slash"
190
190
  toggle="code-height"
191
- toggle-target="#demo-code"
191
+ toggle-selector="#demo-code"
192
192
  ><i class="fas fa-eye-slash"></i
193
193
  ></a>
194
194
  <a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/authorize",
3
- "version": "1.3.14",
3
+ "version": "1.5.0",
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",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "scripts": {
27
27
  "start": "npx webpack --config webpack.config.js",
28
- "build": "NODE_ENV=production npx webpack --config webpack.config.js",
28
+ "build": "npx webpack --mode=production --config webpack.config.js",
29
29
  "dev": "npx webpack --config webpack.config.js --watch",
30
30
  "postinstall": "node -e \"const { execSync } = require('child_process'); try { execSync('coc --version', { stdio: 'ignore' }); } catch (error) { try { execSync('npm install -g @cocreate/cli', { stdio: 'inherit' }); console.log('Installed \"@cocreate/cli\" globally.'); } catch (error) { console.error('Failed to install \"@cocreate/cli\" globally:', error); } }\""
31
31
  },
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "main": "./src/index.js",
47
47
  "dependencies": {
48
- "@cocreate/crud-client": "^1.21.23",
49
- "@cocreate/utils": "^1.21.15"
48
+ "@cocreate/crud-client": "^1.22.0",
49
+ "@cocreate/utils": "^1.22.0"
50
50
  }
51
51
  }
package/src/index.js CHANGED
@@ -18,24 +18,24 @@
18
18
  const permissions = new Map()
19
19
 
20
20
  if (isBrowser) {
21
- crud.listen('updateDocument', function (data) {
21
+ crud.listen('update.object', function (data) {
22
22
  updatePermission(data)
23
23
  });
24
24
 
25
- crud.listen('deleteDocument', function (data) {
25
+ crud.listen('delete.object', function (data) {
26
26
  deletePermission(data)
27
27
  });
28
28
  } else {
29
- process.on('changed-document', async (data) => {
29
+ process.on('changed-object', async (data) => {
30
30
  updatePermission(data)
31
31
  })
32
32
  }
33
33
 
34
34
  async function updatePermission(data) {
35
- const { collection, document, organization_id } = data
35
+ const { array, object, organization_id } = data
36
36
 
37
- if (collection === 'keys' && document) {
38
- let permission = document[0]
37
+ if (array === 'keys' && object) {
38
+ let permission = object[0]
39
39
  if (permission && permission.key && hasPermission(permission.key)) {
40
40
  let newPermission = await readPermisson(permission.key, organization_id)
41
41
  setPermission(permission.key, newPermission)
@@ -44,10 +44,10 @@
44
44
  }
45
45
 
46
46
  async function deletePermission(data) {
47
- const { collection, document, organization_id } = data
47
+ const { array, object, organization_id } = data
48
48
 
49
- if (collection === 'keys' && document) {
50
- let permission = document[0]
49
+ if (array === 'keys' && object) {
50
+ let permission = object[0]
51
51
  if (permission && permission.key && hasPermission(permission.key)) {
52
52
  permissions.delete(permission.key)
53
53
  }
@@ -78,7 +78,7 @@
78
78
  return null;
79
79
 
80
80
  let request = {
81
- collection: 'keys',
81
+ array: 'keys',
82
82
  organization_id,
83
83
  filter: {
84
84
  query: []
@@ -86,17 +86,17 @@
86
86
  }
87
87
 
88
88
  if (key)
89
- request.filter.query.push({ name: 'key', value: key, operator: '$eq' })
89
+ request.filter.query.push({ key: 'key', value: key, operator: '$eq' })
90
90
  else
91
- request.filter.query.push({ name: 'default', value: true, operator: '$eq' })
91
+ request.filter.query.push({ key: 'default', value: true, operator: '$eq' })
92
92
 
93
93
 
94
- let permission = await crud.readDocument(request)
95
- if (permission && permission.document && permission.document[0]) {
96
- permission = permission.document[0]
94
+ let permission = await crud.send(request)
95
+ if (permission && permission.object && permission.object[0]) {
96
+ permission = permission.object[0]
97
97
 
98
- if (!permission.collections) {
99
- permission.collections = {};
98
+ if (!permission.arrays) {
99
+ permission.arrays = {};
100
100
  }
101
101
 
102
102
  if (permission && permission.roles) {
@@ -108,10 +108,10 @@
108
108
 
109
109
  delete request.filter
110
110
  delete request.request
111
- request.document = role_ids
111
+ request.object = role_ids
112
112
 
113
- let roles = await crud.readDocument(request)
114
- roles = roles.document
113
+ let roles = await crud.send(request)
114
+ roles = roles.object
115
115
 
116
116
  permission = createPermissionObject(permission, roles)
117
117
  }
@@ -162,26 +162,25 @@
162
162
  return permission;
163
163
  }
164
164
 
165
- async function check(action, data, user_id) {
165
+ async function check(data, user_id) {
166
166
  let permission = false
167
167
  if (user_id) {
168
168
  permission = await checkPermissionObject({
169
169
  key: user_id,
170
- action,
171
170
  data
172
171
  })
173
172
  }
174
173
  if (!permission || permission.error) {
175
174
  permission = await checkPermissionObject({
176
175
  key: data.key,
177
- action,
178
176
  data
179
177
  })
180
178
  }
181
179
  return permission;
182
180
  }
183
181
 
184
- async function checkPermissionObject({ key, action, data }) {
182
+ async function checkPermissionObject({ key, data }) {
183
+ let action = data.method
185
184
  let { organization_id, filter, endPoint } = data
186
185
  if (!key || !organization_id) return false;
187
186
 
@@ -331,7 +330,7 @@
331
330
  } else if (typeof dataValue === "object") {
332
331
  let checkKeys = true
333
332
  if (dataValue['_id']) {
334
- if (authorized.document.includes(dataValue['_id']))
333
+ if (authorized.object.includes(dataValue['_id']))
335
334
  checkKeys = true
336
335
  }
337
336
  if (checkKeys) {
@@ -347,21 +346,21 @@
347
346
  return keyStatus
348
347
  }
349
348
 
350
- async function checkFilter(authorized, data, key, unauthorize) {
349
+ async function checkFilter(authorized, data, apikey, unauthorize) {
351
350
  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]
351
+ let key
352
+ if (data.filter.type == 'object')
353
+ key = '_id'
354
+ else if (data.filter.type == 'array')
355
+ key = 'name'
356
+ if (key) {
357
+ for (let value of authorized[apikey]) {
358
+ if (value[key])
359
+ value = value[key]
361
360
  if (unauthorize)
362
- data.filter.query.push({ name, value, operator: '$ne', logicalOperator: 'or' })
361
+ data.filter.query.push({ key, value, operator: '$ne', logicalOperator: 'or' })
363
362
  else
364
- data.filter.query.push({ name, value, operator: '$eq', logicalOperator: 'or' })
363
+ data.filter.query.push({ key, value, operator: '$eq', logicalOperator: 'or' })
365
364
  }
366
365
  if (!unauthorize)
367
366
  return true