@budibase/server 2.4.43 → 2.4.44-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.
Files changed (66) hide show
  1. package/builder/assets/{index.8b377b88.js → index.76deb808.js} +385 -384
  2. package/builder/assets/index.7f9a008b.css +6 -0
  3. package/builder/index.html +7 -7
  4. package/dist/api/controllers/application.js +28 -24
  5. package/dist/api/controllers/public/metrics.js +113 -0
  6. package/dist/api/controllers/row/external.js +15 -0
  7. package/dist/api/controllers/static/index.js +84 -24
  8. package/dist/api/controllers/static/templates/BudibaseApp.svelte +34 -11
  9. package/dist/api/controllers/table/utils.js +2 -4
  10. package/dist/api/routes/public/index.js +8 -0
  11. package/dist/api/routes/public/metrics.js +30 -0
  12. package/dist/app.js +1 -0
  13. package/dist/integrations/googlesheets.js +4 -0
  14. package/dist/integrations/redis.js +1 -1
  15. package/dist/middleware/currentapp.js +1 -27
  16. package/dist/package.json +12 -11
  17. package/dist/sdk/users/utils.js +11 -6
  18. package/dist/tsconfig.build.tsbuildinfo +1 -1
  19. package/dist/utilities/fileSystem/app.js +1 -10
  20. package/dist/utilities/global.js +17 -7
  21. package/jest.config.ts +1 -0
  22. package/package.json +13 -12
  23. package/specs/openapi.json +39 -0
  24. package/specs/openapi.yaml +169 -0
  25. package/specs/resources/application.ts +11 -0
  26. package/specs/resources/index.ts +2 -0
  27. package/specs/resources/metrics.ts +81 -0
  28. package/src/api/controllers/application.ts +20 -21
  29. package/src/api/controllers/component.ts +2 -2
  30. package/src/api/controllers/public/metrics.ts +251 -0
  31. package/src/api/controllers/row/external.ts +14 -0
  32. package/src/api/controllers/static/index.ts +69 -26
  33. package/src/api/controllers/static/templates/BudibaseApp.svelte +34 -11
  34. package/src/api/controllers/table/tests/utils.spec.ts +97 -0
  35. package/src/api/controllers/table/utils.ts +20 -12
  36. package/src/api/controllers/view/tests/__snapshots__/viewBuilder.spec.js.snap +48 -48
  37. package/src/api/routes/public/index.ts +10 -1
  38. package/src/api/routes/public/metrics.ts +28 -0
  39. package/src/api/routes/public/tests/metrics.spec.js +34 -0
  40. package/src/api/routes/tests/__snapshots__/datasource.spec.ts.snap +22 -22
  41. package/src/api/routes/tests/__snapshots__/view.spec.js.snap +5 -5
  42. package/src/api/routes/tests/appSync.spec.ts +1 -1
  43. package/src/api/routes/tests/internalSearch.spec.js +6 -6
  44. package/src/api/routes/tests/user.spec.js +2 -2
  45. package/src/app.ts +2 -1
  46. package/src/automations/automationUtils.ts +1 -1
  47. package/src/automations/tests/automation.spec.ts +99 -0
  48. package/src/db/defaultData/datasource_bb_default.ts +1 -1
  49. package/src/definitions/openapi.ts +15 -0
  50. package/src/integrations/googlesheets.ts +4 -0
  51. package/src/integrations/redis.ts +1 -1
  52. package/src/integrations/tests/googlesheets.spec.ts +4 -0
  53. package/src/integrations/tests/redis.spec.ts +9 -5
  54. package/src/middleware/currentapp.ts +3 -32
  55. package/src/middleware/tests/currentapp.spec.js +6 -42
  56. package/src/sdk/users/tests/utils.spec.ts +159 -0
  57. package/src/sdk/users/utils.ts +18 -7
  58. package/src/tests/jestSetup.ts +5 -1
  59. package/src/tests/utilities/TestConfiguration.ts +7 -19
  60. package/src/tests/utilities/structures.ts +13 -1
  61. package/src/utilities/fileSystem/app.ts +2 -9
  62. package/src/utilities/global.ts +21 -9
  63. package/src/utilities/rowProcessor/index.ts +1 -1
  64. package/builder/assets/favicon.e7fc7733.png +0 -0
  65. package/builder/assets/index.b0e3aca6.css +0 -6
  66. package/src/automations/tests/automation.spec.js +0 -84
@@ -33,15 +33,8 @@ export const deleteApp = async (appId: string) => {
33
33
  export const getComponentLibraryManifest = async (library: string) => {
34
34
  const appId = context.getAppId()
35
35
  const filename = "manifest.json"
36
- /* istanbul ignore next */
37
- // when testing in cypress and so on we need to get the package
38
- // as the environment may not be fully fleshed out for dev or prod
39
- if (env.isTest()) {
40
- library = library.replace("standard-components", "client")
41
- const lib = library.split("/")[1]
42
- const path = require.resolve(library).split(lib)[0]
43
- return require(join(path, lib, filename))
44
- } else if (env.isDev()) {
36
+
37
+ if (env.isDev() || env.isTest()) {
45
38
  const path = join(NODE_MODULES_PATH, "@budibase", "client", filename)
46
39
  // always load from new so that updates are refreshed
47
40
  delete require.cache[require.resolve(path)]
@@ -8,7 +8,7 @@ import {
8
8
  } from "@budibase/backend-core"
9
9
  import env from "../environment"
10
10
  import { groups } from "@budibase/pro"
11
- import { BBContext, ContextUser, User } from "@budibase/types"
11
+ import { UserCtx, ContextUser, User, UserGroup } from "@budibase/types"
12
12
 
13
13
  export function updateAppRole(
14
14
  user: ContextUser,
@@ -43,33 +43,40 @@ export function updateAppRole(
43
43
 
44
44
  async function checkGroupRoles(
45
45
  user: ContextUser,
46
- { appId }: { appId?: string } = {}
46
+ opts: { appId?: string; groups?: UserGroup[] } = {}
47
47
  ) {
48
48
  if (user.roleId && user.roleId !== roles.BUILTIN_ROLE_IDS.PUBLIC) {
49
49
  return user
50
50
  }
51
- if (appId) {
52
- user.roleId = await groups.getGroupRoleId(user as User, appId)
51
+ if (opts.appId) {
52
+ user.roleId = await groups.getGroupRoleId(user as User, opts.appId, {
53
+ groups: opts.groups,
54
+ })
55
+ }
56
+ // final fallback, simply couldn't find a role - user must be public
57
+ if (!user.roleId) {
58
+ user.roleId = roles.BUILTIN_ROLE_IDS.PUBLIC
53
59
  }
54
60
  return user
55
61
  }
56
62
 
57
63
  async function processUser(
58
64
  user: ContextUser,
59
- { appId }: { appId?: string } = {}
65
+ opts: { appId?: string; groups?: UserGroup[] } = {}
60
66
  ) {
61
67
  if (user) {
62
68
  delete user.password
63
69
  }
64
- user = await updateAppRole(user, { appId })
70
+ const appId = opts.appId || context.getAppId()
71
+ user = updateAppRole(user, { appId })
65
72
  if (!user.roleId && user?.userGroups?.length) {
66
- user = await checkGroupRoles(user, { appId })
73
+ user = await checkGroupRoles(user, { appId, groups: opts?.groups })
67
74
  }
68
75
 
69
76
  return user
70
77
  }
71
78
 
72
- export async function getCachedSelf(ctx: BBContext, appId: string) {
79
+ export async function getCachedSelf(ctx: UserCtx, appId: string) {
73
80
  // this has to be tenant aware, can't depend on the context to find it out
74
81
  // running some middlewares before the tenancy causes context to break
75
82
  const user = await cache.user.getUser(ctx.user?._id!)
@@ -90,6 +97,7 @@ export async function getGlobalUser(userId: string) {
90
97
  export async function getGlobalUsers(users?: ContextUser[]) {
91
98
  const appId = context.getAppId()
92
99
  const db = tenancy.getGlobalDB()
100
+ const allGroups = await groups.fetch()
93
101
  let globalUsers
94
102
  if (users) {
95
103
  const globalIds = users.map(user =>
@@ -118,7 +126,11 @@ export async function getGlobalUsers(users?: ContextUser[]) {
118
126
  return globalUsers
119
127
  }
120
128
 
121
- return globalUsers.map(user => updateAppRole(user))
129
+ // pass in the groups, meaning we don't actually need to retrieve them for
130
+ // each user individually
131
+ return Promise.all(
132
+ globalUsers.map(user => processUser(user, { groups: allGroups }))
133
+ )
122
134
  }
123
135
 
124
136
  export async function getGlobalUsersFromMetadata(users: ContextUser[]) {
@@ -131,7 +131,7 @@ export function coerce(row: any, type: string) {
131
131
  * @returns {object} the row which has been prepared to be written to the DB.
132
132
  */
133
133
  export function inputProcessing(
134
- user: ContextUser,
134
+ user: ContextUser | null,
135
135
  table: Table,
136
136
  row: Row,
137
137
  opts?: AutoColumnProcessingOpts
Binary file