@budibase/frontend-core 2.0.39 → 2.0.40
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/backups.js +50 -0
- package/src/api/index.js +2 -0
- package/src/constants.js +2 -0
- package/src/utils/utils.js +55 -9
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.40",
|
|
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": "^2.0.
|
|
9
|
+
"@budibase/bbui": "^2.0.40",
|
|
10
10
|
"lodash": "^4.17.21",
|
|
11
11
|
"svelte": "^3.46.2"
|
|
12
12
|
},
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "581ffaea14dfa2b88b55381e56ee1b6eb283a489"
|
|
14
14
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const buildBackupsEndpoints = API => ({
|
|
2
|
+
/**
|
|
3
|
+
* Gets a list of users in the current tenant.
|
|
4
|
+
*/
|
|
5
|
+
searchBackups: async ({ appId, trigger, type, page, startDate, endDate }) => {
|
|
6
|
+
const opts = {}
|
|
7
|
+
if (page) {
|
|
8
|
+
opts.page = page
|
|
9
|
+
}
|
|
10
|
+
if (trigger && type) {
|
|
11
|
+
opts.trigger = trigger.toLowerCase()
|
|
12
|
+
opts.type = type.toLowerCase()
|
|
13
|
+
}
|
|
14
|
+
if (startDate && endDate) {
|
|
15
|
+
opts.startDate = startDate
|
|
16
|
+
opts.endDate = endDate
|
|
17
|
+
}
|
|
18
|
+
return await API.post({
|
|
19
|
+
url: `/api/apps/${appId}/backups/search`,
|
|
20
|
+
body: opts,
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
createManualBackup: async ({ appId, name }) => {
|
|
25
|
+
return await API.post({
|
|
26
|
+
url: `/api/apps/${appId}/backups`,
|
|
27
|
+
body: { name },
|
|
28
|
+
})
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
deleteBackup: async ({ appId, backupId }) => {
|
|
32
|
+
return await API.delete({
|
|
33
|
+
url: `/api/apps/${appId}/backups/${backupId}`,
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
updateBackup: async ({ appId, backupId, name }) => {
|
|
38
|
+
return await API.patch({
|
|
39
|
+
url: `/api/apps/${appId}/backups/${backupId}`,
|
|
40
|
+
body: { name },
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
restoreBackup: async ({ appId, backupId, name }) => {
|
|
45
|
+
return await API.post({
|
|
46
|
+
url: `/api/apps/${appId}/backups/${backupId}/import`,
|
|
47
|
+
body: { name },
|
|
48
|
+
})
|
|
49
|
+
},
|
|
50
|
+
})
|
package/src/api/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import { buildViewEndpoints } from "./views"
|
|
|
25
25
|
import { buildLicensingEndpoints } from "./licensing"
|
|
26
26
|
import { buildGroupsEndpoints } from "./groups"
|
|
27
27
|
import { buildPluginEndpoints } from "./plugins"
|
|
28
|
+
import { buildBackupsEndpoints } from "./backups"
|
|
28
29
|
|
|
29
30
|
const defaultAPIClientConfig = {
|
|
30
31
|
/**
|
|
@@ -245,5 +246,6 @@ export const createAPIClient = config => {
|
|
|
245
246
|
...buildLicensingEndpoints(API),
|
|
246
247
|
...buildGroupsEndpoints(API),
|
|
247
248
|
...buildPluginEndpoints(API),
|
|
249
|
+
...buildBackupsEndpoints(API),
|
|
248
250
|
}
|
|
249
251
|
}
|
package/src/constants.js
CHANGED
|
@@ -98,6 +98,7 @@ export const BuilderRoleDescriptions = [
|
|
|
98
98
|
export const PlanType = {
|
|
99
99
|
FREE: "free",
|
|
100
100
|
TEAM: "team",
|
|
101
|
+
PRO: "pro",
|
|
101
102
|
BUSINESS: "business",
|
|
102
103
|
ENTERPRISE: "enterprise",
|
|
103
104
|
}
|
|
@@ -112,6 +113,7 @@ export const ApiVersion = "1"
|
|
|
112
113
|
|
|
113
114
|
export const Features = {
|
|
114
115
|
USER_GROUPS: "userGroups",
|
|
116
|
+
BACKUPS: "appBackups",
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
// Role IDs
|
package/src/utils/utils.js
CHANGED
|
@@ -6,17 +6,29 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export const sequential = fn => {
|
|
8
8
|
let queue = []
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
return (...params) => {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
queue.push(async () => {
|
|
12
|
+
let data, error
|
|
13
|
+
try {
|
|
14
|
+
data = await fn(...params)
|
|
15
|
+
} catch (err) {
|
|
16
|
+
error = err
|
|
17
|
+
}
|
|
18
|
+
queue.shift()
|
|
19
|
+
if (queue.length) {
|
|
20
|
+
queue[0]()
|
|
21
|
+
}
|
|
22
|
+
if (error) {
|
|
23
|
+
reject(error)
|
|
24
|
+
} else {
|
|
25
|
+
resolve(data)
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
if (queue.length === 1) {
|
|
29
|
+
queue[0]()
|
|
15
30
|
}
|
|
16
31
|
})
|
|
17
|
-
if (queue.length === 1) {
|
|
18
|
-
await queue[0]()
|
|
19
|
-
}
|
|
20
32
|
}
|
|
21
33
|
}
|
|
22
34
|
|
|
@@ -40,3 +52,37 @@ export const debounce = (callback, minDelay = 1000) => {
|
|
|
40
52
|
})
|
|
41
53
|
}
|
|
42
54
|
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Utility to throttle invocations of a synchronous function. This is better
|
|
58
|
+
* than a simple debounce invocation for a number of reasons. Features include:
|
|
59
|
+
* - First invocation is immediate (no initial delay)
|
|
60
|
+
* - Every invocation has the latest params (no stale params)
|
|
61
|
+
* - There will always be a final invocation with the last params (no missing
|
|
62
|
+
* final update)
|
|
63
|
+
* @param callback
|
|
64
|
+
* @param minDelay
|
|
65
|
+
* @returns {Function} a throttled version function
|
|
66
|
+
*/
|
|
67
|
+
export const throttle = (callback, minDelay = 1000) => {
|
|
68
|
+
let lastParams
|
|
69
|
+
let stalled = false
|
|
70
|
+
let pending = false
|
|
71
|
+
const invoke = (...params) => {
|
|
72
|
+
lastParams = params
|
|
73
|
+
if (stalled) {
|
|
74
|
+
pending = true
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
callback(...lastParams)
|
|
78
|
+
stalled = true
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
stalled = false
|
|
81
|
+
if (pending) {
|
|
82
|
+
pending = false
|
|
83
|
+
invoke(...lastParams)
|
|
84
|
+
}
|
|
85
|
+
}, minDelay)
|
|
86
|
+
}
|
|
87
|
+
return invoke
|
|
88
|
+
}
|