@budibase/backend-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.
Files changed (250) hide show
  1. package/dist/index.js +266 -324
  2. package/dist/index.js.map +4 -4
  3. package/dist/index.js.meta.json +1 -1
  4. package/dist/package.json +19 -4
  5. package/dist/plugins.js +1 -1
  6. package/dist/plugins.js.map +1 -1
  7. package/dist/plugins.js.meta.json +1 -1
  8. package/dist/src/security/permissions.d.ts +1 -1
  9. package/dist/tests.js +222 -260
  10. package/dist/tests.js.map +4 -4
  11. package/dist/tests.js.meta.json +1 -1
  12. package/package.json +19 -4
  13. package/dist/tsconfig.build.tsbuildinfo +0 -1
  14. package/src/accounts/accounts.ts +0 -82
  15. package/src/accounts/api.ts +0 -59
  16. package/src/accounts/index.ts +0 -1
  17. package/src/auth/auth.ts +0 -208
  18. package/src/auth/index.ts +0 -1
  19. package/src/auth/tests/auth.spec.ts +0 -14
  20. package/src/blacklist/blacklist.ts +0 -54
  21. package/src/blacklist/index.ts +0 -1
  22. package/src/blacklist/tests/blacklist.spec.ts +0 -46
  23. package/src/cache/appMetadata.ts +0 -88
  24. package/src/cache/base/index.ts +0 -92
  25. package/src/cache/generic.ts +0 -30
  26. package/src/cache/index.ts +0 -5
  27. package/src/cache/tests/writethrough.spec.ts +0 -138
  28. package/src/cache/user.ts +0 -69
  29. package/src/cache/writethrough.ts +0 -133
  30. package/src/configs/configs.ts +0 -257
  31. package/src/configs/index.ts +0 -1
  32. package/src/configs/tests/configs.spec.ts +0 -184
  33. package/src/constants/db.ts +0 -63
  34. package/src/constants/index.ts +0 -2
  35. package/src/constants/misc.ts +0 -50
  36. package/src/context/Context.ts +0 -14
  37. package/src/context/identity.ts +0 -58
  38. package/src/context/index.ts +0 -3
  39. package/src/context/mainContext.ts +0 -310
  40. package/src/context/tests/index.spec.ts +0 -147
  41. package/src/context/types.ts +0 -11
  42. package/src/db/Replication.ts +0 -84
  43. package/src/db/constants.ts +0 -10
  44. package/src/db/couch/DatabaseImpl.ts +0 -238
  45. package/src/db/couch/connections.ts +0 -77
  46. package/src/db/couch/index.ts +0 -5
  47. package/src/db/couch/pouchDB.ts +0 -97
  48. package/src/db/couch/pouchDump.ts +0 -0
  49. package/src/db/couch/utils.ts +0 -50
  50. package/src/db/db.ts +0 -39
  51. package/src/db/errors.ts +0 -14
  52. package/src/db/index.ts +0 -12
  53. package/src/db/lucene.ts +0 -732
  54. package/src/db/searchIndexes/index.ts +0 -1
  55. package/src/db/searchIndexes/searchIndexes.ts +0 -62
  56. package/src/db/tests/index.spec.js +0 -25
  57. package/src/db/tests/lucene.spec.ts +0 -298
  58. package/src/db/tests/pouch.spec.js +0 -62
  59. package/src/db/tests/utils.spec.ts +0 -63
  60. package/src/db/utils.ts +0 -207
  61. package/src/db/views.ts +0 -241
  62. package/src/docIds/conversions.ts +0 -59
  63. package/src/docIds/ids.ts +0 -113
  64. package/src/docIds/index.ts +0 -2
  65. package/src/docIds/newid.ts +0 -5
  66. package/src/docIds/params.ts +0 -174
  67. package/src/docUpdates/index.ts +0 -29
  68. package/src/environment.ts +0 -201
  69. package/src/errors/errors.ts +0 -119
  70. package/src/errors/index.ts +0 -1
  71. package/src/events/analytics.ts +0 -6
  72. package/src/events/asyncEvents/index.ts +0 -2
  73. package/src/events/asyncEvents/publisher.ts +0 -12
  74. package/src/events/asyncEvents/queue.ts +0 -22
  75. package/src/events/backfill.ts +0 -183
  76. package/src/events/documentId.ts +0 -56
  77. package/src/events/events.ts +0 -40
  78. package/src/events/identification.ts +0 -310
  79. package/src/events/index.ts +0 -14
  80. package/src/events/processors/AnalyticsProcessor.ts +0 -64
  81. package/src/events/processors/AuditLogsProcessor.ts +0 -93
  82. package/src/events/processors/LoggingProcessor.ts +0 -37
  83. package/src/events/processors/Processors.ts +0 -52
  84. package/src/events/processors/async/DocumentUpdateProcessor.ts +0 -43
  85. package/src/events/processors/index.ts +0 -19
  86. package/src/events/processors/posthog/PosthogProcessor.ts +0 -118
  87. package/src/events/processors/posthog/index.ts +0 -2
  88. package/src/events/processors/posthog/rateLimiting.ts +0 -106
  89. package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +0 -168
  90. package/src/events/processors/types.ts +0 -1
  91. package/src/events/publishers/account.ts +0 -35
  92. package/src/events/publishers/app.ts +0 -155
  93. package/src/events/publishers/auditLog.ts +0 -26
  94. package/src/events/publishers/auth.ts +0 -73
  95. package/src/events/publishers/automation.ts +0 -110
  96. package/src/events/publishers/backfill.ts +0 -74
  97. package/src/events/publishers/backup.ts +0 -42
  98. package/src/events/publishers/datasource.ts +0 -48
  99. package/src/events/publishers/email.ts +0 -17
  100. package/src/events/publishers/environmentVariable.ts +0 -38
  101. package/src/events/publishers/group.ts +0 -99
  102. package/src/events/publishers/index.ts +0 -24
  103. package/src/events/publishers/installation.ts +0 -38
  104. package/src/events/publishers/layout.ts +0 -26
  105. package/src/events/publishers/license.ts +0 -84
  106. package/src/events/publishers/org.ts +0 -37
  107. package/src/events/publishers/plugin.ts +0 -47
  108. package/src/events/publishers/query.ts +0 -88
  109. package/src/events/publishers/role.ts +0 -62
  110. package/src/events/publishers/rows.ts +0 -29
  111. package/src/events/publishers/screen.ts +0 -36
  112. package/src/events/publishers/serve.ts +0 -43
  113. package/src/events/publishers/table.ts +0 -70
  114. package/src/events/publishers/user.ts +0 -202
  115. package/src/events/publishers/view.ts +0 -107
  116. package/src/featureFlags/index.ts +0 -77
  117. package/src/featureFlags/tests/featureFlags.spec.ts +0 -85
  118. package/src/helpers.ts +0 -9
  119. package/src/index.ts +0 -53
  120. package/src/installation.ts +0 -107
  121. package/src/logging/alerts.ts +0 -26
  122. package/src/logging/correlation/correlation.ts +0 -13
  123. package/src/logging/correlation/index.ts +0 -1
  124. package/src/logging/correlation/middleware.ts +0 -17
  125. package/src/logging/index.ts +0 -4
  126. package/src/logging/pino/logger.ts +0 -232
  127. package/src/logging/pino/middleware.ts +0 -45
  128. package/src/logging/system.ts +0 -81
  129. package/src/logging/tests/system.spec.ts +0 -61
  130. package/src/middleware/adminOnly.ts +0 -9
  131. package/src/middleware/auditLog.ts +0 -6
  132. package/src/middleware/authenticated.ts +0 -193
  133. package/src/middleware/builderOnly.ts +0 -20
  134. package/src/middleware/builderOrAdmin.ts +0 -20
  135. package/src/middleware/csrf.ts +0 -81
  136. package/src/middleware/errorHandling.ts +0 -29
  137. package/src/middleware/index.ts +0 -21
  138. package/src/middleware/internalApi.ts +0 -23
  139. package/src/middleware/joi-validator.ts +0 -45
  140. package/src/middleware/matchers.ts +0 -47
  141. package/src/middleware/passport/datasource/google.ts +0 -95
  142. package/src/middleware/passport/local.ts +0 -54
  143. package/src/middleware/passport/sso/google.ts +0 -77
  144. package/src/middleware/passport/sso/oidc.ts +0 -154
  145. package/src/middleware/passport/sso/sso.ts +0 -165
  146. package/src/middleware/passport/sso/tests/google.spec.ts +0 -67
  147. package/src/middleware/passport/sso/tests/oidc.spec.ts +0 -152
  148. package/src/middleware/passport/sso/tests/sso.spec.ts +0 -197
  149. package/src/middleware/passport/utils.ts +0 -38
  150. package/src/middleware/querystringToBody.ts +0 -28
  151. package/src/middleware/tenancy.ts +0 -36
  152. package/src/middleware/tests/builder.spec.ts +0 -180
  153. package/src/middleware/tests/matchers.spec.ts +0 -134
  154. package/src/migrations/definitions.ts +0 -40
  155. package/src/migrations/index.ts +0 -2
  156. package/src/migrations/migrations.ts +0 -191
  157. package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +0 -11
  158. package/src/migrations/tests/migrations.spec.ts +0 -64
  159. package/src/objectStore/buckets/app.ts +0 -40
  160. package/src/objectStore/buckets/global.ts +0 -29
  161. package/src/objectStore/buckets/index.ts +0 -3
  162. package/src/objectStore/buckets/plugins.ts +0 -71
  163. package/src/objectStore/buckets/tests/app.spec.ts +0 -171
  164. package/src/objectStore/buckets/tests/global.spec.ts +0 -74
  165. package/src/objectStore/buckets/tests/plugins.spec.ts +0 -111
  166. package/src/objectStore/cloudfront.ts +0 -41
  167. package/src/objectStore/index.ts +0 -3
  168. package/src/objectStore/objectStore.ts +0 -440
  169. package/src/objectStore/utils.ts +0 -27
  170. package/src/platform/index.ts +0 -3
  171. package/src/platform/platformDb.ts +0 -6
  172. package/src/platform/tenants.ts +0 -101
  173. package/src/platform/tests/tenants.spec.ts +0 -26
  174. package/src/platform/users.ts +0 -90
  175. package/src/plugin/index.ts +0 -1
  176. package/src/plugin/tests/validation.spec.ts +0 -83
  177. package/src/plugin/utils.ts +0 -156
  178. package/src/queue/constants.ts +0 -6
  179. package/src/queue/inMemoryQueue.ts +0 -141
  180. package/src/queue/index.ts +0 -2
  181. package/src/queue/listeners.ts +0 -195
  182. package/src/queue/queue.ts +0 -54
  183. package/src/redis/index.ts +0 -6
  184. package/src/redis/init.ts +0 -86
  185. package/src/redis/redis.ts +0 -308
  186. package/src/redis/redlockImpl.ts +0 -139
  187. package/src/redis/utils.ts +0 -117
  188. package/src/security/encryption.ts +0 -179
  189. package/src/security/permissions.ts +0 -159
  190. package/src/security/roles.ts +0 -420
  191. package/src/security/sessions.ts +0 -120
  192. package/src/security/tests/encryption.spec.ts +0 -31
  193. package/src/security/tests/permissions.spec.ts +0 -145
  194. package/src/security/tests/sessions.spec.ts +0 -12
  195. package/src/tenancy/db.ts +0 -6
  196. package/src/tenancy/index.ts +0 -2
  197. package/src/tenancy/tenancy.ts +0 -140
  198. package/src/tenancy/tests/tenancy.spec.ts +0 -184
  199. package/src/timers/index.ts +0 -1
  200. package/src/timers/timers.ts +0 -22
  201. package/src/users/db.ts +0 -460
  202. package/src/users/events.ts +0 -176
  203. package/src/users/index.ts +0 -4
  204. package/src/users/lookup.ts +0 -102
  205. package/src/users/users.ts +0 -276
  206. package/src/users/utils.ts +0 -55
  207. package/src/utils/hashing.ts +0 -14
  208. package/src/utils/index.ts +0 -3
  209. package/src/utils/stringUtils.ts +0 -8
  210. package/src/utils/tests/utils.spec.ts +0 -191
  211. package/src/utils/utils.ts +0 -239
  212. package/tests/core/logging.ts +0 -34
  213. package/tests/core/utilities/index.ts +0 -6
  214. package/tests/core/utilities/jestUtils.ts +0 -30
  215. package/tests/core/utilities/mocks/alerts.ts +0 -3
  216. package/tests/core/utilities/mocks/date.ts +0 -2
  217. package/tests/core/utilities/mocks/events.ts +0 -131
  218. package/tests/core/utilities/mocks/fetch.ts +0 -17
  219. package/tests/core/utilities/mocks/index.ts +0 -10
  220. package/tests/core/utilities/mocks/licenses.ts +0 -107
  221. package/tests/core/utilities/mocks/posthog.ts +0 -7
  222. package/tests/core/utilities/structures/Chance.ts +0 -20
  223. package/tests/core/utilities/structures/accounts.ts +0 -115
  224. package/tests/core/utilities/structures/apps.ts +0 -21
  225. package/tests/core/utilities/structures/common.ts +0 -7
  226. package/tests/core/utilities/structures/db.ts +0 -12
  227. package/tests/core/utilities/structures/documents/index.ts +0 -1
  228. package/tests/core/utilities/structures/documents/platform/index.ts +0 -1
  229. package/tests/core/utilities/structures/documents/platform/installation.ts +0 -12
  230. package/tests/core/utilities/structures/generator.ts +0 -2
  231. package/tests/core/utilities/structures/index.ts +0 -15
  232. package/tests/core/utilities/structures/koa.ts +0 -16
  233. package/tests/core/utilities/structures/licenses.ts +0 -167
  234. package/tests/core/utilities/structures/plugins.ts +0 -19
  235. package/tests/core/utilities/structures/quotas.ts +0 -67
  236. package/tests/core/utilities/structures/scim.ts +0 -80
  237. package/tests/core/utilities/structures/shared.ts +0 -19
  238. package/tests/core/utilities/structures/sso.ts +0 -119
  239. package/tests/core/utilities/structures/tenants.ts +0 -5
  240. package/tests/core/utilities/structures/userGroups.ts +0 -10
  241. package/tests/core/utilities/structures/users.ts +0 -73
  242. package/tests/core/utilities/testContainerUtils.ts +0 -98
  243. package/tests/core/utilities/utils/index.ts +0 -1
  244. package/tests/core/utilities/utils/time.ts +0 -3
  245. package/tests/extra/DBTestConfiguration.ts +0 -36
  246. package/tests/extra/index.ts +0 -2
  247. package/tests/extra/testEnv.ts +0 -95
  248. package/tests/index.ts +0 -1
  249. package/tests/jestEnv.ts +0 -6
  250. package/tests/jestSetup.ts +0 -28
@@ -1,174 +0,0 @@
1
- import {
2
- DocumentType,
3
- InternalTable,
4
- SEPARATOR,
5
- UNICODE_MAX,
6
- ViewName,
7
- } from "../constants"
8
- import { getProdAppID } from "./conversions"
9
-
10
- /**
11
- * If creating DB allDocs/query params with only a single top level ID this can be used, this
12
- * is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
13
- * More complex cases such as link docs and rows which have multiple levels of IDs that their
14
- * ID consists of need their own functions to build the allDocs parameters.
15
- * @param {string} docType The type of document which input params are being built for, e.g. user,
16
- * link, app, table and so on.
17
- * @param {string|null} docId The ID of the document minus its type - this is only needed if looking
18
- * for a singular document.
19
- * @param {object} otherProps Add any other properties onto the request, e.g. include_docs.
20
- * @returns {object} Parameters which can then be used with an allDocs request.
21
- */
22
- export function getDocParams(
23
- docType: string,
24
- docId?: string | null,
25
- otherProps: any = {}
26
- ) {
27
- if (docId == null) {
28
- docId = ""
29
- }
30
- return {
31
- ...otherProps,
32
- startkey: `${docType}${SEPARATOR}${docId}`,
33
- endkey: `${docType}${SEPARATOR}${docId}${UNICODE_MAX}`,
34
- }
35
- }
36
-
37
- /**
38
- * Gets the DB allDocs/query params for retrieving a row.
39
- * @param {string|null} tableId The table in which the rows have been stored.
40
- * @param {string|null} rowId The ID of the row which is being specifically queried for. This can be
41
- * left null to get all the rows in the table.
42
- * @param {object} otherProps Any other properties to add to the request.
43
- * @returns {object} Parameters which can then be used with an allDocs request.
44
- */
45
- export function getRowParams(
46
- tableId?: string | null,
47
- rowId?: string | null,
48
- otherProps = {}
49
- ) {
50
- if (tableId == null) {
51
- return getDocParams(DocumentType.ROW, null, otherProps)
52
- }
53
-
54
- const endOfKey = rowId == null ? `${tableId}${SEPARATOR}` : rowId
55
-
56
- return getDocParams(DocumentType.ROW, endOfKey, otherProps)
57
- }
58
-
59
- /**
60
- * Retrieve the correct index for a view based on default design DB.
61
- */
62
- export function getQueryIndex(viewName: ViewName) {
63
- return `database/${viewName}`
64
- }
65
-
66
- /**
67
- * Check if a given ID is that of a table.
68
- * @returns {boolean}
69
- */
70
- export const isTableId = (id: string) => {
71
- // this includes datasource plus tables
72
- return (
73
- id &&
74
- (id.startsWith(`${DocumentType.TABLE}${SEPARATOR}`) ||
75
- id.startsWith(`${DocumentType.DATASOURCE_PLUS}${SEPARATOR}`))
76
- )
77
- }
78
-
79
- /**
80
- * Check if a given ID is that of a datasource or datasource plus.
81
- * @returns {boolean}
82
- */
83
- export const isDatasourceId = (id: string) => {
84
- // this covers both datasources and datasource plus
85
- return id && id.startsWith(`${DocumentType.DATASOURCE}${SEPARATOR}`)
86
- }
87
-
88
- /**
89
- * Gets parameters for retrieving workspaces.
90
- */
91
- export function getWorkspaceParams(id = "", otherProps = {}) {
92
- return {
93
- ...otherProps,
94
- startkey: `${DocumentType.WORKSPACE}${SEPARATOR}${id}`,
95
- endkey: `${DocumentType.WORKSPACE}${SEPARATOR}${id}${UNICODE_MAX}`,
96
- }
97
- }
98
-
99
- /**
100
- * Gets parameters for retrieving users.
101
- */
102
- export function getGlobalUserParams(globalId: any, otherProps: any = {}) {
103
- if (!globalId) {
104
- globalId = ""
105
- }
106
- const startkey = otherProps?.startkey
107
- return {
108
- ...otherProps,
109
- // need to include this incase pagination
110
- startkey: startkey
111
- ? startkey
112
- : `${DocumentType.USER}${SEPARATOR}${globalId}`,
113
- endkey: `${DocumentType.USER}${SEPARATOR}${globalId}${UNICODE_MAX}`,
114
- }
115
- }
116
-
117
- /**
118
- * Gets parameters for retrieving users, this is a utility function for the getDocParams function.
119
- */
120
- export function getUserMetadataParams(userId?: string | null, otherProps = {}) {
121
- return getRowParams(InternalTable.USER_METADATA, userId, otherProps)
122
- }
123
-
124
- export function getUsersByAppParams(appId: any, otherProps: any = {}) {
125
- const prodAppId = getProdAppID(appId)
126
- return {
127
- ...otherProps,
128
- startkey: prodAppId,
129
- endkey: `${prodAppId}${UNICODE_MAX}`,
130
- }
131
- }
132
-
133
- /**
134
- * Gets parameters for retrieving templates. Owner ID must be specified, either global or a workspace level.
135
- */
136
- export function getTemplateParams(
137
- ownerId: any,
138
- templateId: any,
139
- otherProps = {}
140
- ) {
141
- if (!templateId) {
142
- templateId = ""
143
- }
144
- let final
145
- if (templateId) {
146
- final = templateId
147
- } else {
148
- final = `${DocumentType.TEMPLATE}${SEPARATOR}${ownerId}${SEPARATOR}`
149
- }
150
- return {
151
- ...otherProps,
152
- startkey: final,
153
- endkey: `${final}${UNICODE_MAX}`,
154
- }
155
- }
156
-
157
- /**
158
- * Gets parameters for retrieving a role, this is a utility function for the getDocParams function.
159
- */
160
- export function getRoleParams(roleId?: string | null, otherProps = {}) {
161
- return getDocParams(DocumentType.ROLE, roleId, otherProps)
162
- }
163
-
164
- export function getStartEndKeyURL(baseKey: any, tenantId?: string) {
165
- const tenancy = tenantId ? `${SEPARATOR}${tenantId}` : ""
166
- return `startkey="${baseKey}${tenancy}"&endkey="${baseKey}${tenancy}${UNICODE_MAX}"`
167
- }
168
-
169
- /**
170
- * Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
171
- */
172
- export const getPluginParams = (pluginId?: string | null, otherProps = {}) => {
173
- return getDocParams(DocumentType.PLUGIN, pluginId, otherProps)
174
- }
@@ -1,29 +0,0 @@
1
- import { asyncEventQueue, init as initQueue } from "../events/asyncEvents"
2
- import {
3
- ProcessorMap,
4
- default as DocumentUpdateProcessor,
5
- } from "../events/processors/async/DocumentUpdateProcessor"
6
-
7
- let processingPromise: Promise<void>
8
- let documentProcessor: DocumentUpdateProcessor
9
-
10
- export function init(processors: ProcessorMap) {
11
- if (!asyncEventQueue) {
12
- initQueue()
13
- }
14
- if (!documentProcessor) {
15
- documentProcessor = new DocumentUpdateProcessor(processors)
16
- }
17
- // if not processing in this instance, kick it off
18
- if (!processingPromise) {
19
- processingPromise = asyncEventQueue.process(async job => {
20
- const { event, identity, properties, timestamp } = job.data
21
- await documentProcessor.processEvent(
22
- event,
23
- identity,
24
- properties,
25
- timestamp
26
- )
27
- })
28
- }
29
- }
@@ -1,201 +0,0 @@
1
- import { existsSync, readFileSync } from "fs"
2
- import { ServiceType } from "@budibase/types"
3
-
4
- function isTest() {
5
- return isCypress() || isJest()
6
- }
7
-
8
- function isJest() {
9
- return !!(process.env.NODE_ENV === "jest" || process.env.JEST_WORKER_ID)
10
- }
11
-
12
- function isCypress() {
13
- return process.env.NODE_ENV === "cypress"
14
- }
15
-
16
- function isDev() {
17
- return process.env.NODE_ENV !== "production"
18
- }
19
-
20
- let LOADED = false
21
- if (!LOADED && isDev() && !isTest()) {
22
- require("dotenv").config()
23
- LOADED = true
24
- }
25
-
26
- const DefaultBucketName = {
27
- BACKUPS: "backups",
28
- APPS: "prod-budi-app-assets",
29
- TEMPLATES: "templates",
30
- GLOBAL: "global",
31
- PLUGINS: "plugins",
32
- }
33
-
34
- const selfHosted = !!parseInt(process.env.SELF_HOSTED || "")
35
-
36
- function getAPIEncryptionKey() {
37
- return process.env.API_ENCRYPTION_KEY
38
- ? process.env.API_ENCRYPTION_KEY
39
- : process.env.JWT_SECRET // fallback to the JWT_SECRET used historically
40
- }
41
-
42
- function httpLogging() {
43
- if (process.env.HTTP_LOGGING === undefined) {
44
- // on by default unless otherwise specified
45
- return true
46
- }
47
-
48
- return process.env.HTTP_LOGGING
49
- }
50
-
51
- function getPackageJsonFields(): {
52
- VERSION: string
53
- SERVICE_NAME: string
54
- } {
55
- function findFileInAncestors(
56
- fileName: string,
57
- currentDir: string
58
- ): string | null {
59
- const filePath = `${currentDir}/${fileName}`
60
- if (existsSync(filePath)) {
61
- return filePath
62
- }
63
-
64
- const parentDir = `${currentDir}/..`
65
- if (parentDir === currentDir) {
66
- // reached root directory
67
- return null
68
- }
69
-
70
- return findFileInAncestors(fileName, parentDir)
71
- }
72
-
73
- try {
74
- const packageJsonFile = findFileInAncestors("package.json", process.cwd())
75
- const content = readFileSync(packageJsonFile!, "utf-8")
76
- const parsedContent = JSON.parse(content)
77
- return {
78
- VERSION: parsedContent.version,
79
- SERVICE_NAME: parsedContent.name,
80
- }
81
- } catch {
82
- // throwing an error here is confusing/causes backend-core to be hard to import
83
- return { VERSION: "", SERVICE_NAME: "" }
84
- }
85
- }
86
-
87
- function isWorker() {
88
- return environment.SERVICE_TYPE === ServiceType.WORKER
89
- }
90
-
91
- function isApps() {
92
- return environment.SERVICE_TYPE === ServiceType.APPS
93
- }
94
-
95
- const environment = {
96
- isTest,
97
- isJest,
98
- isDev,
99
- isWorker,
100
- isApps,
101
- isProd: () => {
102
- return !isDev()
103
- },
104
- JS_BCRYPT: process.env.JS_BCRYPT,
105
- JWT_SECRET: process.env.JWT_SECRET,
106
- JWT_SECRET_FALLBACK: process.env.JWT_SECRET_FALLBACK,
107
- ENCRYPTION_KEY: process.env.ENCRYPTION_KEY,
108
- API_ENCRYPTION_KEY: getAPIEncryptionKey(),
109
- COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005",
110
- COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
111
- COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
112
- GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
113
- GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
114
- SALT_ROUNDS: process.env.SALT_ROUNDS,
115
- REDIS_URL: process.env.REDIS_URL || "localhost:6379",
116
- REDIS_PASSWORD: process.env.REDIS_PASSWORD,
117
- REDIS_CLUSTERED: process.env.REDIS_CLUSTERED,
118
- MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
119
- MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
120
- AWS_REGION: process.env.AWS_REGION,
121
- MINIO_URL: process.env.MINIO_URL,
122
- MINIO_ENABLED: process.env.MINIO_ENABLED || 1,
123
- INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
124
- INTERNAL_API_KEY_FALLBACK: process.env.INTERNAL_API_KEY_FALLBACK,
125
- MULTI_TENANCY: process.env.MULTI_TENANCY,
126
- ACCOUNT_PORTAL_URL:
127
- process.env.ACCOUNT_PORTAL_URL || "https://account.budibase.app",
128
- ACCOUNT_PORTAL_API_KEY: process.env.ACCOUNT_PORTAL_API_KEY || "",
129
- DISABLE_ACCOUNT_PORTAL: process.env.DISABLE_ACCOUNT_PORTAL,
130
- SELF_HOSTED: selfHosted,
131
- COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
132
- PLATFORM_URL: process.env.PLATFORM_URL || "",
133
- POSTHOG_TOKEN: process.env.POSTHOG_TOKEN,
134
- ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
135
- TENANT_FEATURE_FLAGS: process.env.TENANT_FEATURE_FLAGS,
136
- CLOUDFRONT_CDN: process.env.CLOUDFRONT_CDN,
137
- CLOUDFRONT_PRIVATE_KEY_64: process.env.CLOUDFRONT_PRIVATE_KEY_64,
138
- CLOUDFRONT_PUBLIC_KEY_ID: process.env.CLOUDFRONT_PUBLIC_KEY_ID,
139
- BACKUPS_BUCKET_NAME:
140
- process.env.BACKUPS_BUCKET_NAME || DefaultBucketName.BACKUPS,
141
- APPS_BUCKET_NAME: process.env.APPS_BUCKET_NAME || DefaultBucketName.APPS,
142
- TEMPLATES_BUCKET_NAME:
143
- process.env.TEMPLATES_BUCKET_NAME || DefaultBucketName.TEMPLATES,
144
- GLOBAL_BUCKET_NAME:
145
- process.env.GLOBAL_BUCKET_NAME || DefaultBucketName.GLOBAL,
146
- PLUGIN_BUCKET_NAME:
147
- process.env.PLUGIN_BUCKET_NAME || DefaultBucketName.PLUGINS,
148
- USE_COUCH: process.env.USE_COUCH || true,
149
- MOCK_REDIS: process.env.MOCK_REDIS,
150
- DEFAULT_LICENSE: process.env.DEFAULT_LICENSE,
151
- SERVICE: process.env.SERVICE || "budibase",
152
- LOG_LEVEL: process.env.LOG_LEVEL || "info",
153
- SESSION_UPDATE_PERIOD: process.env.SESSION_UPDATE_PERIOD,
154
- DEPLOYMENT_ENVIRONMENT:
155
- process.env.DEPLOYMENT_ENVIRONMENT || "docker-compose",
156
- HTTP_LOGGING: httpLogging(),
157
- ENABLE_AUDIT_LOG_IP_ADDR: process.env.ENABLE_AUDIT_LOG_IP_ADDR,
158
- // smtp
159
- SMTP_FALLBACK_ENABLED: process.env.SMTP_FALLBACK_ENABLED,
160
- SMTP_USER: process.env.SMTP_USER,
161
- SMTP_PASSWORD: process.env.SMTP_PASSWORD,
162
- SMTP_HOST: process.env.SMTP_HOST,
163
- SMTP_PORT: parseInt(process.env.SMTP_PORT || ""),
164
- SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS,
165
- DISABLE_JWT_WARNING: process.env.DISABLE_JWT_WARNING,
166
- BLACKLIST_IPS: process.env.BLACKLIST_IPS,
167
- SERVICE_TYPE: "unknown",
168
- /**
169
- * Enable to allow an admin user to login using a password.
170
- * This can be useful to prevent lockout when configuring SSO.
171
- * However, this should be turned OFF by default for security purposes.
172
- */
173
- ENABLE_SSO_MAINTENANCE_MODE: selfHosted
174
- ? process.env.ENABLE_SSO_MAINTENANCE_MODE
175
- : false,
176
- ...getPackageJsonFields(),
177
- DISABLE_PINO_LOGGER: process.env.DISABLE_PINO_LOGGER,
178
- OFFLINE_MODE: process.env.OFFLINE_MODE,
179
- _set(key: any, value: any) {
180
- process.env[key] = value
181
- // @ts-ignore
182
- environment[key] = value
183
- },
184
- ROLLING_LOG_MAX_SIZE: process.env.ROLLING_LOG_MAX_SIZE || "10M",
185
- }
186
-
187
- // clean up any environment variable edge cases
188
- for (let [key, value] of Object.entries(environment)) {
189
- // handle the edge case of "0" to disable an environment variable
190
- if (value === "0") {
191
- // @ts-ignore
192
- environment[key] = 0
193
- }
194
- // handle the edge case of "false" to disable an environment variable
195
- if (value === "false") {
196
- // @ts-ignore
197
- environment[key] = 0
198
- }
199
- }
200
-
201
- export default environment
@@ -1,119 +0,0 @@
1
- // BASE
2
-
3
- export abstract class BudibaseError extends Error {
4
- code: string
5
-
6
- constructor(message: string, code: ErrorCode) {
7
- super(message)
8
- this.code = code
9
- }
10
-
11
- protected getPublicError?(): any
12
- }
13
-
14
- // ERROR HANDLING
15
-
16
- export enum ErrorCode {
17
- USAGE_LIMIT_EXCEEDED = "usage_limit_exceeded",
18
- FEATURE_DISABLED = "feature_disabled",
19
- INVALID_API_KEY = "invalid_api_key",
20
- HTTP = "http",
21
- }
22
-
23
- /**
24
- * For the given error, build the public representation that is safe
25
- * to be exposed over an api.
26
- */
27
- export const getPublicError = (err: any) => {
28
- let error
29
- if (err.code) {
30
- // add generic error information
31
- error = {
32
- code: err.code,
33
- }
34
-
35
- if (err.getPublicError) {
36
- error = {
37
- ...error,
38
- // get any additional context from this error
39
- ...err.getPublicError(),
40
- }
41
- }
42
- }
43
-
44
- return error
45
- }
46
-
47
- // HTTP
48
-
49
- export class HTTPError extends BudibaseError {
50
- status: number
51
-
52
- constructor(message: string, httpStatus: number, code = ErrorCode.HTTP) {
53
- super(message, code)
54
- this.status = httpStatus
55
- }
56
- }
57
-
58
- export class NotFoundError extends HTTPError {
59
- constructor(message: string) {
60
- super(message, 404)
61
- }
62
- }
63
-
64
- export class BadRequestError extends HTTPError {
65
- constructor(message: string) {
66
- super(message, 400)
67
- }
68
- }
69
-
70
- // LICENSING
71
-
72
- export class UsageLimitError extends HTTPError {
73
- limitName: string
74
-
75
- constructor(message: string, limitName: string) {
76
- super(message, 400, ErrorCode.USAGE_LIMIT_EXCEEDED)
77
- this.limitName = limitName
78
- }
79
-
80
- getPublicError() {
81
- return {
82
- limitName: this.limitName,
83
- }
84
- }
85
- }
86
-
87
- export class FeatureDisabledError extends HTTPError {
88
- featureName: string
89
-
90
- constructor(message: string, featureName: string) {
91
- super(message, 400, ErrorCode.FEATURE_DISABLED)
92
- this.featureName = featureName
93
- }
94
-
95
- getPublicError() {
96
- return {
97
- featureName: this.featureName,
98
- }
99
- }
100
- }
101
-
102
- // AUTH
103
-
104
- export class InvalidAPIKeyError extends BudibaseError {
105
- constructor() {
106
- super(
107
- "Invalid API key - may need re-generated, or user doesn't exist",
108
- ErrorCode.INVALID_API_KEY
109
- )
110
- }
111
- }
112
-
113
- // USERS
114
-
115
- export class EmailUnavailableError extends Error {
116
- constructor(email: string) {
117
- super(`Email already in use: '${email}'`)
118
- }
119
- }
@@ -1 +0,0 @@
1
- export * from "./errors"
@@ -1,6 +0,0 @@
1
- import * as configs from "../configs"
2
-
3
- // wrapper utility function
4
- export const enabled = async () => {
5
- return configs.analyticsEnabled()
6
- }
@@ -1,2 +0,0 @@
1
- export * from "./queue"
2
- export * from "./publisher"
@@ -1,12 +0,0 @@
1
- import { AsyncEvents } from "@budibase/types"
2
- import { EventPayload, asyncEventQueue, init } from "./queue"
3
-
4
- export async function publishAsyncEvent(payload: EventPayload) {
5
- if (!asyncEventQueue) {
6
- init()
7
- }
8
- const { event, identity } = payload
9
- if (AsyncEvents.indexOf(event) !== -1 && identity.tenantId) {
10
- await asyncEventQueue.add(payload)
11
- }
12
- }
@@ -1,22 +0,0 @@
1
- import BullQueue from "bull"
2
- import { createQueue, JobQueue } from "../../queue"
3
- import { Event, Identity } from "@budibase/types"
4
-
5
- export interface EventPayload {
6
- event: Event
7
- identity: Identity
8
- properties: any
9
- timestamp?: string | number
10
- }
11
-
12
- export let asyncEventQueue: BullQueue.Queue
13
-
14
- export function init() {
15
- asyncEventQueue = createQueue<EventPayload>(JobQueue.SYSTEM_EVENT_QUEUE)
16
- }
17
-
18
- export async function shutdown() {
19
- if (asyncEventQueue) {
20
- await asyncEventQueue.close()
21
- }
22
- }