@budibase/frontend-core 1.4.17 → 1.4.18-alpha.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/package.json +3 -3
- package/src/api/groups.js +87 -36
- package/src/api/licensing.js +9 -0
- package/src/api/user.js +16 -8
- package/src/fetch/DataFetch.js +2 -0
- package/src/fetch/UserFetch.js +52 -0
- package/src/fetch/fetchData.js +2 -0
- package/src/themes/nord.css +1 -0
- package/src/utils/utils.js +21 -0
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.18-alpha.1",
|
|
4
4
|
"description": "Budibase frontend core libraries used in builder and client",
|
|
5
5
|
"author": "Budibase",
|
|
6
6
|
"license": "MPL-2.0",
|
|
7
7
|
"svelte": "src/index.js",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@budibase/bbui": "
|
|
9
|
+
"@budibase/bbui": "1.4.18-alpha.1",
|
|
10
10
|
"lodash": "^4.17.21",
|
|
11
11
|
"svelte": "^3.46.2"
|
|
12
12
|
},
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "2e5daebd856a007bd48c48fecfa1b5137771161a"
|
|
14
14
|
}
|
package/src/api/groups.js
CHANGED
|
@@ -1,40 +1,91 @@
|
|
|
1
|
-
export const buildGroupsEndpoints = API =>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export const buildGroupsEndpoints = API => {
|
|
2
|
+
// underlying functionality of adding/removing users/apps to groups
|
|
3
|
+
async function updateGroupResource(groupId, resource, operation, ids) {
|
|
4
|
+
if (!Array.isArray(ids)) {
|
|
5
|
+
ids = [ids]
|
|
6
|
+
}
|
|
7
7
|
return await API.post({
|
|
8
|
-
url:
|
|
9
|
-
body:
|
|
8
|
+
url: `/api/global/groups/${groupId}/${resource}`,
|
|
9
|
+
body: {
|
|
10
|
+
[operation]: ids,
|
|
11
|
+
},
|
|
10
12
|
})
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Gets all of the user groups
|
|
14
|
-
*/
|
|
15
|
-
getGroups: async () => {
|
|
16
|
-
return await API.get({
|
|
17
|
-
url: "/api/global/groups",
|
|
18
|
-
})
|
|
19
|
-
},
|
|
13
|
+
}
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
return {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a user group.
|
|
18
|
+
* @param group the new group to create
|
|
19
|
+
*/
|
|
20
|
+
saveGroup: async group => {
|
|
21
|
+
return await API.post({
|
|
22
|
+
url: "/api/global/groups",
|
|
23
|
+
body: group,
|
|
24
|
+
})
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Gets all the user groups
|
|
28
|
+
*/
|
|
29
|
+
getGroups: async () => {
|
|
30
|
+
return await API.get({
|
|
31
|
+
url: "/api/global/groups",
|
|
32
|
+
})
|
|
33
|
+
},
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Gets a group by ID
|
|
37
|
+
*/
|
|
38
|
+
getGroup: async id => {
|
|
39
|
+
return await API.get({
|
|
40
|
+
url: `/api/global/groups/${id}`,
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Deletes a user group
|
|
46
|
+
* @param id the id of the config to delete
|
|
47
|
+
* @param rev the revision of the config to delete
|
|
48
|
+
*/
|
|
49
|
+
deleteGroup: async ({ id, rev }) => {
|
|
50
|
+
return await API.delete({
|
|
51
|
+
url: `/api/global/groups/${id}/${rev}`,
|
|
52
|
+
})
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Adds users to a group
|
|
57
|
+
* @param groupId The group to update
|
|
58
|
+
* @param userIds The user IDs to be added
|
|
59
|
+
*/
|
|
60
|
+
addUsersToGroup: async (groupId, userIds) => {
|
|
61
|
+
return updateGroupResource(groupId, "users", "add", userIds)
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Removes users from a group
|
|
66
|
+
* @param groupId The group to update
|
|
67
|
+
* @param userIds The user IDs to be removed
|
|
68
|
+
*/
|
|
69
|
+
removeUsersFromGroup: async (groupId, userIds) => {
|
|
70
|
+
return updateGroupResource(groupId, "users", "remove", userIds)
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Adds apps to a group
|
|
75
|
+
* @param groupId The group to update
|
|
76
|
+
* @param appArray Array of objects, containing the appId and roleId to be added
|
|
77
|
+
*/
|
|
78
|
+
addAppsToGroup: async (groupId, appArray) => {
|
|
79
|
+
return updateGroupResource(groupId, "apps", "add", appArray)
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Removes apps from a group
|
|
84
|
+
* @param groupId The group to update
|
|
85
|
+
* @param appArray Array of objects, containing the appId to be removed
|
|
86
|
+
*/
|
|
87
|
+
removeAppsFromGroup: async (groupId, appArray) => {
|
|
88
|
+
return updateGroupResource(groupId, "apps", "remove", appArray)
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/api/licensing.js
CHANGED
|
@@ -9,6 +9,15 @@ export const buildLicensingEndpoints = API => ({
|
|
|
9
9
|
})
|
|
10
10
|
},
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Delete a self hosted license key
|
|
14
|
+
*/
|
|
15
|
+
deleteLicenseKey: async () => {
|
|
16
|
+
return API.delete({
|
|
17
|
+
url: `/api/global/license/info`,
|
|
18
|
+
})
|
|
19
|
+
},
|
|
20
|
+
|
|
12
21
|
/**
|
|
13
22
|
* Get the license info - metadata about the license including the
|
|
14
23
|
* obfuscated license key.
|
package/src/api/user.js
CHANGED
|
@@ -86,15 +86,19 @@ export const buildUserEndpoints = API => ({
|
|
|
86
86
|
/**
|
|
87
87
|
* Creates multiple users.
|
|
88
88
|
* @param users the array of user objects to create
|
|
89
|
+
* @param groups the array of group ids to add all users to
|
|
89
90
|
*/
|
|
90
91
|
createUsers: async ({ users, groups }) => {
|
|
91
|
-
|
|
92
|
-
url: "/api/global/users/
|
|
92
|
+
const res = await API.post({
|
|
93
|
+
url: "/api/global/users/bulk",
|
|
93
94
|
body: {
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
create: {
|
|
96
|
+
users,
|
|
97
|
+
groups,
|
|
98
|
+
},
|
|
96
99
|
},
|
|
97
100
|
})
|
|
101
|
+
return res.created
|
|
98
102
|
},
|
|
99
103
|
|
|
100
104
|
/**
|
|
@@ -109,15 +113,18 @@ export const buildUserEndpoints = API => ({
|
|
|
109
113
|
|
|
110
114
|
/**
|
|
111
115
|
* Deletes multiple users
|
|
112
|
-
* @param
|
|
116
|
+
* @param userIds the ID of the user to delete
|
|
113
117
|
*/
|
|
114
118
|
deleteUsers: async userIds => {
|
|
115
|
-
|
|
116
|
-
url: `/api/global/users/
|
|
119
|
+
const res = await API.post({
|
|
120
|
+
url: `/api/global/users/bulk`,
|
|
117
121
|
body: {
|
|
118
|
-
|
|
122
|
+
delete: {
|
|
123
|
+
userIds,
|
|
124
|
+
},
|
|
119
125
|
},
|
|
120
126
|
})
|
|
127
|
+
return res.deleted
|
|
121
128
|
},
|
|
122
129
|
|
|
123
130
|
/**
|
|
@@ -151,6 +158,7 @@ export const buildUserEndpoints = API => ({
|
|
|
151
158
|
userInfo: {
|
|
152
159
|
admin: user.admin ? { global: true } : undefined,
|
|
153
160
|
builder: user.admin || user.builder ? { global: true } : undefined,
|
|
161
|
+
groups: user.groups,
|
|
154
162
|
},
|
|
155
163
|
})),
|
|
156
164
|
})
|
package/src/fetch/DataFetch.js
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { get } from "svelte/store"
|
|
2
|
+
import DataFetch from "./DataFetch.js"
|
|
3
|
+
import { TableNames } from "../constants"
|
|
4
|
+
|
|
5
|
+
export default class UserFetch extends DataFetch {
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
super({
|
|
8
|
+
...opts,
|
|
9
|
+
datasource: {
|
|
10
|
+
tableId: TableNames.USERS,
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
determineFeatureFlags() {
|
|
16
|
+
return {
|
|
17
|
+
supportsSearch: true,
|
|
18
|
+
supportsSort: false,
|
|
19
|
+
supportsPagination: true,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async getDefinition() {
|
|
24
|
+
return {
|
|
25
|
+
schema: {},
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getData() {
|
|
30
|
+
const { cursor, query } = get(this.store)
|
|
31
|
+
try {
|
|
32
|
+
// "query" normally contains a lucene query, but users uses a non-standard
|
|
33
|
+
// search endpoint so we use query uniquely here
|
|
34
|
+
const res = await this.API.searchUsers({
|
|
35
|
+
page: cursor,
|
|
36
|
+
email: query.email,
|
|
37
|
+
appId: query.appId,
|
|
38
|
+
})
|
|
39
|
+
return {
|
|
40
|
+
rows: res?.data || [],
|
|
41
|
+
hasNextPage: res?.hasNextPage || false,
|
|
42
|
+
cursor: res?.nextPage || null,
|
|
43
|
+
}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
rows: [],
|
|
47
|
+
hasNextPage: false,
|
|
48
|
+
error,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/fetch/fetchData.js
CHANGED
|
@@ -5,12 +5,14 @@ import RelationshipFetch from "./RelationshipFetch.js"
|
|
|
5
5
|
import NestedProviderFetch from "./NestedProviderFetch.js"
|
|
6
6
|
import FieldFetch from "./FieldFetch.js"
|
|
7
7
|
import JSONArrayFetch from "./JSONArrayFetch.js"
|
|
8
|
+
import UserFetch from "./UserFetch.js"
|
|
8
9
|
|
|
9
10
|
const DataFetchMap = {
|
|
10
11
|
table: TableFetch,
|
|
11
12
|
view: ViewFetch,
|
|
12
13
|
query: QueryFetch,
|
|
13
14
|
link: RelationshipFetch,
|
|
15
|
+
user: UserFetch,
|
|
14
16
|
|
|
15
17
|
// Client specific datasource types
|
|
16
18
|
provider: NestedProviderFetch,
|
package/src/themes/nord.css
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
--spectrum-global-color-static-blue-600: #5680b4;
|
|
29
29
|
--spectrum-global-color-static-blue-700: #4e79af;
|
|
30
30
|
--spectrum-global-color-static-blue-800: #4a73a6;
|
|
31
|
+
--spectrum-global-color-static-blue: var(--spectrum-global-color-blue-600);
|
|
31
32
|
|
|
32
33
|
--spectrum-global-color-gray-50: #2e3440;
|
|
33
34
|
--spectrum-global-color-gray-75: #353b4a;
|
package/src/utils/utils.js
CHANGED
|
@@ -19,3 +19,24 @@ export const sequential = fn => {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Utility to debounce an async function and ensure a minimum delay between
|
|
25
|
+
* invocations is enforced.
|
|
26
|
+
* @param callback an async function to run
|
|
27
|
+
* @param minDelay the minimum delay between invocations
|
|
28
|
+
* @returns {Promise} a debounced version of the callback
|
|
29
|
+
*/
|
|
30
|
+
export const debounce = (callback, minDelay = 1000) => {
|
|
31
|
+
let timeout
|
|
32
|
+
return async (...params) => {
|
|
33
|
+
return new Promise(resolve => {
|
|
34
|
+
if (timeout) {
|
|
35
|
+
clearTimeout(timeout)
|
|
36
|
+
}
|
|
37
|
+
timeout = setTimeout(async () => {
|
|
38
|
+
resolve(await callback(...params))
|
|
39
|
+
}, minDelay)
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
}
|