@budibase/shared-core 2.9.19 → 2.9.21-alpha.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.
@@ -1,35 +0,0 @@
1
- import { DocumentType, prefixed } from "@budibase/types"
2
-
3
- const APP_PREFIX = prefixed(DocumentType.APP)
4
- const APP_DEV_PREFIX = prefixed(DocumentType.APP_DEV)
5
-
6
- export function getDevAppID(appId: string) {
7
- if (!appId) {
8
- throw new Error("No app ID provided")
9
- }
10
- if (appId.startsWith(APP_DEV_PREFIX)) {
11
- return appId
12
- }
13
- // split to take off the app_ element, then join it together incase any other app_ exist
14
- const split = appId.split(APP_PREFIX)
15
- split.shift()
16
- const rest = split.join(APP_PREFIX)
17
- return `${APP_DEV_PREFIX}${rest}`
18
- }
19
-
20
- /**
21
- * Convert a development app ID to a deployed app ID.
22
- */
23
- export function getProdAppID(appId: string) {
24
- if (!appId) {
25
- throw new Error("No app ID provided")
26
- }
27
- if (!appId.startsWith(APP_DEV_PREFIX)) {
28
- return appId
29
- }
30
- // split to take off the app_dev element, then join it together incase any other app_ exist
31
- const split = appId.split(APP_DEV_PREFIX)
32
- split.shift()
33
- const rest = split.join(APP_DEV_PREFIX)
34
- return `${APP_PREFIX}${rest}`
35
- }
@@ -1,2 +0,0 @@
1
- export * as applications from "./applications"
2
- export * as users from "./users"
@@ -1,62 +0,0 @@
1
- import { ContextUser, User } from "@budibase/types"
2
- import { getProdAppID } from "./applications"
3
-
4
- // checks if a user is specifically a builder, given an app ID
5
- export function isBuilder(user: User | ContextUser, appId?: string): boolean {
6
- if (!user) {
7
- return false
8
- }
9
- if (user.builder?.global) {
10
- return true
11
- } else if (appId && user.builder?.apps?.includes(getProdAppID(appId))) {
12
- return true
13
- }
14
- return false
15
- }
16
-
17
- export function isGlobalBuilder(user: User | ContextUser): boolean {
18
- return (isBuilder(user) && !hasAppBuilderPermissions(user)) || isAdmin(user)
19
- }
20
-
21
- // alias for hasAdminPermission, currently do the same thing
22
- // in future whether someone has admin permissions and whether they are
23
- // an admin for a specific resource could be separated
24
- export function isAdmin(user: User | ContextUser): boolean {
25
- if (!user) {
26
- return false
27
- }
28
- return hasAdminPermissions(user)
29
- }
30
-
31
- export function isAdminOrBuilder(
32
- user: User | ContextUser,
33
- appId?: string
34
- ): boolean {
35
- return isBuilder(user, appId) || isAdmin(user)
36
- }
37
-
38
- // check if they are a builder within an app (not necessarily a global builder)
39
- export function hasAppBuilderPermissions(user?: User | ContextUser): boolean {
40
- if (!user) {
41
- return false
42
- }
43
- const appLength = user.builder?.apps?.length
44
- const isGlobalBuilder = !!user.builder?.global
45
- return !isGlobalBuilder && appLength != null && appLength > 0
46
- }
47
-
48
- // checks if a user is capable of building any app
49
- export function hasBuilderPermissions(user?: User | ContextUser): boolean {
50
- if (!user) {
51
- return false
52
- }
53
- return user.builder?.global || hasAppBuilderPermissions(user)
54
- }
55
-
56
- // checks if a user is capable of being an admin
57
- export function hasAdminPermissions(user?: User | ContextUser): boolean {
58
- if (!user) {
59
- return false
60
- }
61
- return !!user.admin?.global
62
- }
package/src/sdk/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./documents"
package/src/utils.ts DELETED
@@ -1,45 +0,0 @@
1
- export function unreachable(
2
- value: never,
3
- message = `No such case in exhaustive switch: ${value}`
4
- ) {
5
- throw new Error(message)
6
- }
7
-
8
- export async function parallelForeach<T>(
9
- items: T[],
10
- task: (item: T) => Promise<void>,
11
- maxConcurrency: number
12
- ): Promise<void> {
13
- const promises: Promise<void>[] = []
14
- let index = 0
15
-
16
- const processItem = async (item: T) => {
17
- try {
18
- await task(item)
19
- } finally {
20
- processNext()
21
- }
22
- }
23
-
24
- const processNext = () => {
25
- if (index >= items.length) {
26
- // No more items to process
27
- return
28
- }
29
-
30
- const item = items[index]
31
- index++
32
-
33
- const promise = processItem(item)
34
- promises.push(promise)
35
-
36
- if (promises.length >= maxConcurrency) {
37
- Promise.race(promises).then(processNext)
38
- } else {
39
- processNext()
40
- }
41
- }
42
- processNext()
43
-
44
- await Promise.all(promises)
45
- }