@cocreate/authorize 1.11.0 → 1.13.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 +19 -0
- package/package.json +3 -3
- package/src/index.js +22 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# [1.13.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.12.0...v1.13.0) (2024-01-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* applied host to define environment/branch ([56ff08a](https://github.com/CoCreate-app/CoCreate-authorize/commit/56ff08a0929003b37658ab394c74bf1e429cecd5))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* bumped CoCreate dependencies to their latest versions ([641c52b](https://github.com/CoCreate-app/CoCreate-authorize/commit/641c52b6af630d7164cc9e720d00e4e40d7e3d11))
|
|
12
|
+
|
|
13
|
+
# [1.12.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.11.0...v1.12.0) (2023-12-21)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* use dotNotation for merging keys ([ac1177a](https://github.com/CoCreate-app/CoCreate-authorize/commit/ac1177a7445060ab679a3922bbfe544c11d807dc))
|
|
19
|
+
|
|
1
20
|
# [1.11.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.10.0...v1.11.0) (2023-11-25)
|
|
2
21
|
|
|
3
22
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/authorize",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"main": "./src/index.js",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@cocreate/crud-client": "^1.
|
|
49
|
-
"@cocreate/utils": "^1.
|
|
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,
|
|
40
|
+
let newAuthorization = await readAuthorization(authorization.key, data)
|
|
41
41
|
organizations[organization_id][authorization.key] = newAuthorization
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -54,24 +54,27 @@
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
async function getAuthorization(key,
|
|
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,
|
|
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,
|
|
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,
|
|
@@ -109,7 +112,9 @@
|
|
|
109
112
|
let roles = await crud.send(request)
|
|
110
113
|
roles = roles.object
|
|
111
114
|
|
|
112
|
-
|
|
115
|
+
for (let role of roles) {
|
|
116
|
+
authorization = dotNotationToObject(authorization, role)
|
|
117
|
+
}
|
|
113
118
|
}
|
|
114
119
|
return authorization;
|
|
115
120
|
} else
|
|
@@ -121,41 +126,6 @@
|
|
|
121
126
|
|
|
122
127
|
}
|
|
123
128
|
|
|
124
|
-
async function createAuthorization(authorization, roles) {
|
|
125
|
-
roles.map(role => {
|
|
126
|
-
for (const roleKey in role) {
|
|
127
|
-
if (!["_id", "type", "name", "organization_id"].includes(roleKey)) {
|
|
128
|
-
if (!authorization[roleKey]) {
|
|
129
|
-
authorization[roleKey] = role[roleKey]
|
|
130
|
-
} else {
|
|
131
|
-
if (Array.isArray(role[roleKey])) {
|
|
132
|
-
for (let item of role[roleKey]) {
|
|
133
|
-
if (!authorization[roleKey].includes(item))
|
|
134
|
-
authorization[roleKey].push(item)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else if (typeof role[roleKey] == 'object') {
|
|
138
|
-
for (const c of Object.keys(role[roleKey])) {
|
|
139
|
-
if (!authorization[roleKey][c]) {
|
|
140
|
-
authorization[roleKey][c] = role[roleKey][c]
|
|
141
|
-
} else {
|
|
142
|
-
if (typeof role[roleKey][c] == 'object') {
|
|
143
|
-
authorization[roleKey][c] = { ...authorization[roleKey][c], ...role[roleKey][c] }
|
|
144
|
-
} else {
|
|
145
|
-
authorization[roleKey][c] = role[roleKey][c]
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
authorization[roleKey] = role[roleKey]
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
})
|
|
156
|
-
return authorization;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
129
|
async function check(data, user_id) {
|
|
160
130
|
let authorization = false
|
|
161
131
|
if (user_id) {
|
|
@@ -179,7 +149,7 @@
|
|
|
179
149
|
if (!data.method)
|
|
180
150
|
return { error: 'method is required' };
|
|
181
151
|
|
|
182
|
-
let authorized = await getAuthorization(key, data
|
|
152
|
+
let authorized = await getAuthorization(key, data)
|
|
183
153
|
if (!authorized || authorized.error)
|
|
184
154
|
return authorized
|
|
185
155
|
if (authorized.organization_id !== data.organization_id)
|
|
@@ -277,6 +247,17 @@
|
|
|
277
247
|
data.$filter.query.push(query)
|
|
278
248
|
|
|
279
249
|
} else {
|
|
250
|
+
if (key === '$array' && value === 'questions') {
|
|
251
|
+
if (typeof data.array === 'string') {
|
|
252
|
+
if (typeof value === 'string') {
|
|
253
|
+
return data.array === value
|
|
254
|
+
} else if (Array.isArray(value)) {
|
|
255
|
+
return value.includes(data.array)
|
|
256
|
+
}
|
|
257
|
+
} else if (Array.isArray(data.array)) {
|
|
258
|
+
|
|
259
|
+
}
|
|
260
|
+
}
|
|
280
261
|
// TODO: sanitize data by removing items user does not have access to.
|
|
281
262
|
// console.log('key is a query operator', key)
|
|
282
263
|
}
|