@budibase/backend-core 2.5.6-alpha.6 → 2.5.6

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 (396) hide show
  1. package/dist/package.json +10 -12
  2. package/dist/src/cache/writethrough.js +1 -1
  3. package/dist/src/cache/writethrough.js.map +1 -1
  4. package/dist/src/configs/configs.d.ts +1 -2
  5. package/dist/src/configs/configs.js +1 -9
  6. package/dist/src/configs/configs.js.map +1 -1
  7. package/dist/src/constants/misc.d.ts +2 -4
  8. package/dist/src/constants/misc.js +0 -2
  9. package/dist/src/constants/misc.js.map +1 -1
  10. package/dist/src/context/mainContext.d.ts +1 -4
  11. package/dist/src/context/mainContext.js +3 -20
  12. package/dist/src/context/mainContext.js.map +1 -1
  13. package/dist/src/context/types.d.ts +0 -1
  14. package/dist/src/db/conversions.js.map +1 -0
  15. package/dist/src/db/couch/DatabaseImpl.js +1 -1
  16. package/dist/src/db/couch/DatabaseImpl.js.map +1 -1
  17. package/dist/src/db/index.d.ts +1 -2
  18. package/dist/src/db/index.js +2 -15
  19. package/dist/src/db/index.js.map +1 -1
  20. package/dist/src/db/lucene.d.ts +14 -8
  21. package/dist/src/db/lucene.js +86 -152
  22. package/dist/src/db/lucene.js.map +1 -1
  23. package/dist/src/db/utils.d.ts +126 -5
  24. package/dist/src/db/utils.js +232 -20
  25. package/dist/src/db/utils.js.map +1 -1
  26. package/dist/src/db/views.js +1 -16
  27. package/dist/src/db/views.js.map +1 -1
  28. package/dist/src/environment.d.ts +2 -2
  29. package/dist/src/environment.js +2 -9
  30. package/dist/src/environment.js.map +1 -1
  31. package/dist/src/errors/errors.d.ts +0 -3
  32. package/dist/src/errors/errors.js +1 -8
  33. package/dist/src/errors/errors.js.map +1 -1
  34. package/dist/src/events/events.js +0 -9
  35. package/dist/src/events/events.js.map +1 -1
  36. package/dist/src/events/identification.js +0 -1
  37. package/dist/src/events/identification.js.map +1 -1
  38. package/dist/src/events/index.d.ts +0 -1
  39. package/dist/src/events/index.js +1 -3
  40. package/dist/src/events/index.js.map +1 -1
  41. package/dist/src/events/processors/LoggingProcessor.js +17 -3
  42. package/dist/src/events/processors/LoggingProcessor.js.map +1 -1
  43. package/dist/src/events/processors/Processors.js +3 -9
  44. package/dist/src/events/processors/Processors.js.map +1 -1
  45. package/dist/src/events/processors/types.d.ts +11 -1
  46. package/dist/src/events/processors/types.js +6 -0
  47. package/dist/src/events/processors/types.js.map +1 -1
  48. package/dist/src/events/publishers/group.js +0 -6
  49. package/dist/src/events/publishers/group.js.map +1 -1
  50. package/dist/src/events/publishers/user.js +0 -4
  51. package/dist/src/events/publishers/user.js.map +1 -1
  52. package/dist/src/index.d.ts +1 -5
  53. package/dist/src/index.js +1 -2
  54. package/dist/src/index.js.map +1 -1
  55. package/dist/src/{logging/alerts.d.ts → logging.d.ts} +5 -0
  56. package/dist/src/logging.js +56 -0
  57. package/dist/src/logging.js.map +1 -0
  58. package/dist/src/middleware/authenticated.js +2 -5
  59. package/dist/src/middleware/authenticated.js.map +1 -1
  60. package/dist/src/middleware/errorHandling.js +7 -5
  61. package/dist/src/middleware/errorHandling.js.map +1 -1
  62. package/dist/src/middleware/index.d.ts +1 -2
  63. package/dist/src/middleware/index.js +3 -5
  64. package/dist/src/middleware/index.js.map +1 -1
  65. package/dist/src/middleware/logging.d.ts +2 -0
  66. package/dist/src/middleware/logging.js +106 -0
  67. package/dist/src/middleware/logging.js.map +1 -0
  68. package/dist/src/middleware/passport/sso/oidc.js +5 -2
  69. package/dist/src/middleware/passport/sso/oidc.js.map +1 -1
  70. package/dist/src/migrations/migrations.js +4 -4
  71. package/dist/src/migrations/migrations.js.map +1 -1
  72. package/dist/src/newid.js.map +1 -0
  73. package/dist/src/objectStore/objectStore.js +3 -3
  74. package/dist/src/objectStore/objectStore.js.map +1 -1
  75. package/dist/src/plugin/utils.js +2 -53
  76. package/dist/src/plugin/utils.js.map +1 -1
  77. package/dist/src/queue/constants.d.ts +1 -2
  78. package/dist/src/queue/constants.js +0 -1
  79. package/dist/src/queue/constants.js.map +1 -1
  80. package/dist/src/security/encryption.d.ts +0 -1
  81. package/dist/src/security/encryption.js +1 -2
  82. package/dist/src/security/encryption.js.map +1 -1
  83. package/dist/src/security/permissions.d.ts +2 -35
  84. package/dist/src/security/permissions.js +6 -9
  85. package/dist/src/security/permissions.js.map +1 -1
  86. package/dist/src/tenancy/tenancy.js +5 -1
  87. package/dist/src/tenancy/tenancy.js.map +1 -1
  88. package/dist/src/users.d.ts +1 -10
  89. package/dist/src/users.js +1 -35
  90. package/dist/src/users.js.map +1 -1
  91. package/dist/src/utils/hashing.d.ts +1 -1
  92. package/dist/src/utils/hashing.js +1 -1
  93. package/dist/src/utils/hashing.js.map +1 -1
  94. package/dist/src/utils/index.d.ts +0 -1
  95. package/dist/src/utils/index.js +0 -1
  96. package/dist/src/utils/index.js.map +1 -1
  97. package/dist/tests/index.d.ts +1 -1
  98. package/dist/tests/index.js +1 -1
  99. package/dist/tests/index.js.map +1 -1
  100. package/dist/tests/jestEnv.js +1 -0
  101. package/dist/tests/jestEnv.js.map +1 -1
  102. package/dist/tests/jestSetup.d.ts +1 -1
  103. package/dist/tests/jestSetup.js +2 -2
  104. package/dist/tests/jestSetup.js.map +1 -1
  105. package/dist/tests/logging.js.map +1 -0
  106. package/dist/tests/{extra → utilities}/DBTestConfiguration.d.ts +1 -1
  107. package/dist/tests/{extra → utilities}/DBTestConfiguration.js +2 -2
  108. package/dist/tests/utilities/DBTestConfiguration.js.map +1 -0
  109. package/dist/tests/{core/utilities → utilities}/index.d.ts +2 -0
  110. package/dist/tests/{core/utilities → utilities}/index.js +7 -1
  111. package/dist/tests/utilities/index.js.map +1 -0
  112. package/dist/tests/utilities/jestUtils.js.map +1 -0
  113. package/dist/tests/utilities/mocks/date.js.map +1 -0
  114. package/dist/tests/utilities/mocks/events.d.ts +1 -0
  115. package/dist/tests/utilities/mocks/events.js +126 -0
  116. package/dist/tests/utilities/mocks/events.js.map +1 -0
  117. package/dist/tests/utilities/mocks/fetch.d.ts +31 -0
  118. package/dist/tests/utilities/mocks/fetch.js +8 -0
  119. package/dist/tests/utilities/mocks/fetch.js.map +1 -0
  120. package/dist/tests/{core/utilities → utilities}/mocks/index.d.ts +3 -4
  121. package/dist/tests/{core/utilities → utilities}/mocks/index.js +3 -7
  122. package/dist/tests/utilities/mocks/index.js.map +1 -0
  123. package/dist/tests/{core/utilities → utilities}/mocks/licenses.d.ts +0 -1
  124. package/dist/tests/{core/utilities → utilities}/mocks/licenses.js +1 -5
  125. package/dist/tests/utilities/mocks/licenses.js.map +1 -0
  126. package/dist/tests/utilities/mocks/posthog.js.map +1 -0
  127. package/dist/tests/{core/utilities → utilities}/structures/accounts.js +25 -2
  128. package/dist/tests/utilities/structures/accounts.js.map +1 -0
  129. package/dist/tests/{core/utilities → utilities}/structures/apps.js +1 -1
  130. package/dist/tests/utilities/structures/apps.js.map +1 -0
  131. package/dist/tests/utilities/structures/common.js.map +1 -0
  132. package/dist/tests/{core/utilities → utilities}/structures/db.js +1 -1
  133. package/dist/tests/utilities/structures/db.js.map +1 -0
  134. package/dist/tests/utilities/structures/generator.js.map +1 -0
  135. package/dist/tests/{core/utilities → utilities}/structures/index.d.ts +0 -1
  136. package/dist/tests/{core/utilities → utilities}/structures/index.js +1 -2
  137. package/dist/tests/utilities/structures/index.js.map +1 -0
  138. package/dist/tests/utilities/structures/koa.js.map +1 -0
  139. package/dist/tests/utilities/structures/licenses.js.map +1 -0
  140. package/dist/tests/utilities/structures/plugins.js.map +1 -0
  141. package/dist/tests/utilities/structures/shared.js.map +1 -0
  142. package/dist/tests/utilities/structures/sso.js.map +1 -0
  143. package/dist/tests/{core/utilities → utilities}/structures/tenants.js +1 -1
  144. package/dist/tests/utilities/structures/tenants.js.map +1 -0
  145. package/dist/tests/utilities/structures/userGroups.js.map +1 -0
  146. package/dist/tests/utilities/structures/users.js.map +1 -0
  147. package/dist/tests/utilities/testContainerUtils.js.map +1 -0
  148. package/dist/tests/{extra → utilities}/testEnv.js +1 -1
  149. package/dist/tests/utilities/testEnv.js.map +1 -0
  150. package/dist/tsconfig.build.tsbuildinfo +1 -1
  151. package/package.json +10 -12
  152. package/src/auth/tests/auth.spec.ts +1 -2
  153. package/src/cache/tests/writethrough.spec.ts +3 -4
  154. package/src/cache/writethrough.ts +2 -1
  155. package/src/configs/configs.ts +0 -9
  156. package/src/configs/tests/configs.spec.ts +6 -2
  157. package/src/constants/misc.ts +0 -2
  158. package/src/context/mainContext.ts +2 -19
  159. package/src/context/tests/index.spec.ts +3 -16
  160. package/src/context/types.ts +0 -1
  161. package/src/db/couch/DatabaseImpl.ts +1 -1
  162. package/src/db/index.ts +1 -2
  163. package/src/db/lucene.ts +88 -143
  164. package/src/db/tests/lucene.spec.ts +1 -101
  165. package/src/db/tests/utils.spec.ts +1 -1
  166. package/src/db/utils.ts +275 -7
  167. package/src/db/views.ts +2 -18
  168. package/src/environment.ts +2 -11
  169. package/src/errors/errors.ts +0 -8
  170. package/src/events/events.ts +1 -10
  171. package/src/events/identification.ts +0 -1
  172. package/src/events/index.ts +0 -2
  173. package/src/events/processors/LoggingProcessor.ts +22 -3
  174. package/src/events/processors/Processors.ts +3 -9
  175. package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +1 -1
  176. package/src/events/processors/types.ts +18 -1
  177. package/src/events/publishers/group.ts +1 -6
  178. package/src/events/publishers/user.ts +0 -4
  179. package/src/index.ts +0 -1
  180. package/src/logging.ts +60 -0
  181. package/src/middleware/authenticated.ts +2 -8
  182. package/src/middleware/errorHandling.ts +4 -4
  183. package/src/middleware/index.ts +1 -2
  184. package/src/middleware/logging.ts +90 -0
  185. package/src/middleware/passport/sso/oidc.ts +9 -2
  186. package/src/middleware/passport/sso/tests/sso.spec.ts +1 -2
  187. package/src/migrations/migrations.ts +8 -4
  188. package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +1 -1
  189. package/src/migrations/tests/migrations.spec.ts +1 -1
  190. package/src/objectStore/buckets/tests/app.spec.ts +1 -1
  191. package/src/objectStore/buckets/tests/global.spec.ts +1 -1
  192. package/src/objectStore/buckets/tests/plugins.spec.ts +1 -2
  193. package/src/objectStore/objectStore.ts +3 -3
  194. package/src/platform/tests/tenants.spec.ts +1 -2
  195. package/src/plugin/utils.ts +3 -63
  196. package/src/queue/constants.ts +0 -1
  197. package/src/security/encryption.ts +1 -1
  198. package/src/security/permissions.ts +5 -5
  199. package/src/tenancy/tenancy.ts +2 -2
  200. package/src/users.ts +1 -41
  201. package/src/utils/hashing.ts +1 -1
  202. package/src/utils/index.ts +0 -1
  203. package/src/utils/tests/utils.spec.ts +1 -2
  204. package/tests/index.ts +1 -1
  205. package/tests/jestEnv.ts +1 -0
  206. package/tests/jestSetup.ts +2 -2
  207. package/tests/{extra → utilities}/DBTestConfiguration.ts +2 -2
  208. package/tests/{core/utilities → utilities}/index.ts +3 -0
  209. package/tests/utilities/mocks/events.ts +122 -0
  210. package/tests/utilities/mocks/fetch.ts +10 -0
  211. package/tests/{core/utilities → utilities}/mocks/index.ts +3 -4
  212. package/tests/{core/utilities → utilities}/mocks/licenses.ts +0 -4
  213. package/tests/{core/utilities → utilities}/structures/accounts.ts +2 -2
  214. package/tests/{core/utilities → utilities}/structures/apps.ts +1 -1
  215. package/tests/{core/utilities → utilities}/structures/db.ts +1 -1
  216. package/tests/{core/utilities → utilities}/structures/index.ts +0 -1
  217. package/tests/{core/utilities → utilities}/structures/tenants.ts +1 -1
  218. package/tests/{extra → utilities}/testEnv.ts +1 -1
  219. package/dist/src/db/searchIndexes/index.d.ts +0 -1
  220. package/dist/src/db/searchIndexes/index.js +0 -18
  221. package/dist/src/db/searchIndexes/index.js.map +0 -1
  222. package/dist/src/db/searchIndexes/searchIndexes.d.ts +0 -1
  223. package/dist/src/db/searchIndexes/searchIndexes.js +0 -77
  224. package/dist/src/db/searchIndexes/searchIndexes.js.map +0 -1
  225. package/dist/src/docIds/conversions.js.map +0 -1
  226. package/dist/src/docIds/ids.d.ts +0 -53
  227. package/dist/src/docIds/ids.js +0 -101
  228. package/dist/src/docIds/ids.js.map +0 -1
  229. package/dist/src/docIds/index.d.ts +0 -2
  230. package/dist/src/docIds/index.js +0 -19
  231. package/dist/src/docIds/index.js.map +0 -1
  232. package/dist/src/docIds/newid.js.map +0 -1
  233. package/dist/src/docIds/params.d.ts +0 -69
  234. package/dist/src/docIds/params.js +0 -138
  235. package/dist/src/docIds/params.js.map +0 -1
  236. package/dist/src/docUpdates/index.d.ts +0 -2
  237. package/dist/src/docUpdates/index.js +0 -36
  238. package/dist/src/docUpdates/index.js.map +0 -1
  239. package/dist/src/events/asyncEvents/index.d.ts +0 -2
  240. package/dist/src/events/asyncEvents/index.js +0 -19
  241. package/dist/src/events/asyncEvents/index.js.map +0 -1
  242. package/dist/src/events/asyncEvents/publisher.d.ts +0 -2
  243. package/dist/src/events/asyncEvents/publisher.js +0 -27
  244. package/dist/src/events/asyncEvents/publisher.js.map +0 -1
  245. package/dist/src/events/asyncEvents/queue.d.ts +0 -11
  246. package/dist/src/events/asyncEvents/queue.js +0 -26
  247. package/dist/src/events/asyncEvents/queue.js.map +0 -1
  248. package/dist/src/events/documentId.d.ts +0 -2
  249. package/dist/src/events/documentId.js +0 -28
  250. package/dist/src/events/documentId.js.map +0 -1
  251. package/dist/src/events/processors/async/DocumentUpdateProcessor.d.ts +0 -13
  252. package/dist/src/events/processors/async/DocumentUpdateProcessor.js +0 -44
  253. package/dist/src/events/processors/async/DocumentUpdateProcessor.js.map +0 -1
  254. package/dist/src/logging/alerts.js +0 -24
  255. package/dist/src/logging/alerts.js.map +0 -1
  256. package/dist/src/logging/correlation/correlation.d.ts +0 -2
  257. package/dist/src/logging/correlation/correlation.js +0 -17
  258. package/dist/src/logging/correlation/correlation.js.map +0 -1
  259. package/dist/src/logging/correlation/index.d.ts +0 -1
  260. package/dist/src/logging/correlation/index.js +0 -18
  261. package/dist/src/logging/correlation/index.js.map +0 -1
  262. package/dist/src/logging/correlation/middleware.d.ts +0 -2
  263. package/dist/src/logging/correlation/middleware.js +0 -17
  264. package/dist/src/logging/correlation/middleware.js.map +0 -1
  265. package/dist/src/logging/index.d.ts +0 -4
  266. package/dist/src/logging/index.js +0 -37
  267. package/dist/src/logging/index.js.map +0 -1
  268. package/dist/src/logging/pino/logger.d.ts +0 -3
  269. package/dist/src/logging/pino/logger.js +0 -181
  270. package/dist/src/logging/pino/logger.js.map +0 -1
  271. package/dist/src/logging/pino/middleware.d.ts +0 -4
  272. package/dist/src/logging/pino/middleware.js +0 -47
  273. package/dist/src/logging/pino/middleware.js.map +0 -1
  274. package/dist/src/utils/stringUtils.d.ts +0 -1
  275. package/dist/src/utils/stringUtils.js +0 -9
  276. package/dist/src/utils/stringUtils.js.map +0 -1
  277. package/dist/tests/core/logging.js.map +0 -1
  278. package/dist/tests/core/utilities/index.js.map +0 -1
  279. package/dist/tests/core/utilities/jestUtils.js.map +0 -1
  280. package/dist/tests/core/utilities/mocks/alerts.d.ts +0 -3
  281. package/dist/tests/core/utilities/mocks/alerts.js +0 -30
  282. package/dist/tests/core/utilities/mocks/alerts.js.map +0 -1
  283. package/dist/tests/core/utilities/mocks/date.js.map +0 -1
  284. package/dist/tests/core/utilities/mocks/events.d.ts +0 -0
  285. package/dist/tests/core/utilities/mocks/events.js +0 -136
  286. package/dist/tests/core/utilities/mocks/events.js.map +0 -1
  287. package/dist/tests/core/utilities/mocks/fetch.d.ts +0 -33
  288. package/dist/tests/core/utilities/mocks/fetch.js +0 -15
  289. package/dist/tests/core/utilities/mocks/fetch.js.map +0 -1
  290. package/dist/tests/core/utilities/mocks/index.js.map +0 -1
  291. package/dist/tests/core/utilities/mocks/licenses.js.map +0 -1
  292. package/dist/tests/core/utilities/mocks/posthog.js.map +0 -1
  293. package/dist/tests/core/utilities/structures/accounts.js.map +0 -1
  294. package/dist/tests/core/utilities/structures/apps.js.map +0 -1
  295. package/dist/tests/core/utilities/structures/common.js.map +0 -1
  296. package/dist/tests/core/utilities/structures/db.js.map +0 -1
  297. package/dist/tests/core/utilities/structures/generator.js.map +0 -1
  298. package/dist/tests/core/utilities/structures/index.js.map +0 -1
  299. package/dist/tests/core/utilities/structures/koa.js.map +0 -1
  300. package/dist/tests/core/utilities/structures/licenses.js.map +0 -1
  301. package/dist/tests/core/utilities/structures/plugins.js.map +0 -1
  302. package/dist/tests/core/utilities/structures/scim.d.ts +0 -14
  303. package/dist/tests/core/utilities/structures/scim.js +0 -67
  304. package/dist/tests/core/utilities/structures/scim.js.map +0 -1
  305. package/dist/tests/core/utilities/structures/shared.js.map +0 -1
  306. package/dist/tests/core/utilities/structures/sso.js.map +0 -1
  307. package/dist/tests/core/utilities/structures/tenants.js.map +0 -1
  308. package/dist/tests/core/utilities/structures/userGroups.js.map +0 -1
  309. package/dist/tests/core/utilities/structures/users.js.map +0 -1
  310. package/dist/tests/core/utilities/testContainerUtils.js.map +0 -1
  311. package/dist/tests/extra/DBTestConfiguration.js.map +0 -1
  312. package/dist/tests/extra/index.d.ts +0 -2
  313. package/dist/tests/extra/index.js +0 -33
  314. package/dist/tests/extra/index.js.map +0 -1
  315. package/dist/tests/extra/testEnv.js.map +0 -1
  316. package/src/db/searchIndexes/index.ts +0 -1
  317. package/src/db/searchIndexes/searchIndexes.ts +0 -62
  318. package/src/docIds/ids.ts +0 -102
  319. package/src/docIds/index.ts +0 -2
  320. package/src/docIds/params.ts +0 -174
  321. package/src/docUpdates/index.ts +0 -29
  322. package/src/events/asyncEvents/index.ts +0 -2
  323. package/src/events/asyncEvents/publisher.ts +0 -12
  324. package/src/events/asyncEvents/queue.ts +0 -22
  325. package/src/events/documentId.ts +0 -56
  326. package/src/events/processors/async/DocumentUpdateProcessor.ts +0 -43
  327. package/src/logging/alerts.ts +0 -26
  328. package/src/logging/correlation/correlation.ts +0 -13
  329. package/src/logging/correlation/index.ts +0 -1
  330. package/src/logging/correlation/middleware.ts +0 -17
  331. package/src/logging/index.ts +0 -6
  332. package/src/logging/pino/logger.ts +0 -188
  333. package/src/logging/pino/middleware.ts +0 -45
  334. package/src/plugin/tests/validation.spec.ts +0 -83
  335. package/src/security/tests/encryption.spec.ts +0 -31
  336. package/src/security/tests/permissions.spec.ts +0 -145
  337. package/src/tenancy/tests/tenancy.spec.ts +0 -184
  338. package/src/utils/stringUtils.ts +0 -8
  339. package/tests/core/utilities/mocks/alerts.ts +0 -3
  340. package/tests/core/utilities/mocks/events.ts +0 -123
  341. package/tests/core/utilities/mocks/fetch.ts +0 -17
  342. package/tests/core/utilities/structures/scim.ts +0 -81
  343. package/tests/extra/index.ts +0 -2
  344. /package/dist/src/{docIds → db}/conversions.d.ts +0 -0
  345. /package/dist/src/{docIds → db}/conversions.js +0 -0
  346. /package/dist/src/{docIds/newid.d.ts → newid.d.ts} +0 -0
  347. /package/dist/src/{docIds/newid.js → newid.js} +0 -0
  348. /package/dist/tests/{core/logging.d.ts → logging.d.ts} +0 -0
  349. /package/dist/tests/{core/logging.js → logging.js} +0 -0
  350. /package/dist/tests/{core/utilities → utilities}/jestUtils.d.ts +0 -0
  351. /package/dist/tests/{core/utilities → utilities}/jestUtils.js +0 -0
  352. /package/dist/tests/{core/utilities → utilities}/mocks/date.d.ts +0 -0
  353. /package/dist/tests/{core/utilities → utilities}/mocks/date.js +0 -0
  354. /package/dist/tests/{core/utilities → utilities}/mocks/posthog.d.ts +0 -0
  355. /package/dist/tests/{core/utilities → utilities}/mocks/posthog.js +0 -0
  356. /package/dist/tests/{core/utilities → utilities}/structures/accounts.d.ts +0 -0
  357. /package/dist/tests/{core/utilities → utilities}/structures/apps.d.ts +0 -0
  358. /package/dist/tests/{core/utilities → utilities}/structures/common.d.ts +0 -0
  359. /package/dist/tests/{core/utilities → utilities}/structures/common.js +0 -0
  360. /package/dist/tests/{core/utilities → utilities}/structures/db.d.ts +0 -0
  361. /package/dist/tests/{core/utilities → utilities}/structures/generator.d.ts +0 -0
  362. /package/dist/tests/{core/utilities → utilities}/structures/generator.js +0 -0
  363. /package/dist/tests/{core/utilities → utilities}/structures/koa.d.ts +0 -0
  364. /package/dist/tests/{core/utilities → utilities}/structures/koa.js +0 -0
  365. /package/dist/tests/{core/utilities → utilities}/structures/licenses.d.ts +0 -0
  366. /package/dist/tests/{core/utilities → utilities}/structures/licenses.js +0 -0
  367. /package/dist/tests/{core/utilities → utilities}/structures/plugins.d.ts +0 -0
  368. /package/dist/tests/{core/utilities → utilities}/structures/plugins.js +0 -0
  369. /package/dist/tests/{core/utilities → utilities}/structures/shared.d.ts +0 -0
  370. /package/dist/tests/{core/utilities → utilities}/structures/shared.js +0 -0
  371. /package/dist/tests/{core/utilities → utilities}/structures/sso.d.ts +0 -0
  372. /package/dist/tests/{core/utilities → utilities}/structures/sso.js +0 -0
  373. /package/dist/tests/{core/utilities → utilities}/structures/tenants.d.ts +0 -0
  374. /package/dist/tests/{core/utilities → utilities}/structures/userGroups.d.ts +0 -0
  375. /package/dist/tests/{core/utilities → utilities}/structures/userGroups.js +0 -0
  376. /package/dist/tests/{core/utilities → utilities}/structures/users.d.ts +0 -0
  377. /package/dist/tests/{core/utilities → utilities}/structures/users.js +0 -0
  378. /package/dist/tests/{core/utilities → utilities}/testContainerUtils.d.ts +0 -0
  379. /package/dist/tests/{core/utilities → utilities}/testContainerUtils.js +0 -0
  380. /package/dist/tests/{extra → utilities}/testEnv.d.ts +0 -0
  381. /package/src/{docIds → db}/conversions.ts +0 -0
  382. /package/src/{docIds/newid.ts → newid.ts} +0 -0
  383. /package/tests/{core/logging.ts → logging.ts} +0 -0
  384. /package/tests/{core/utilities → utilities}/jestUtils.ts +0 -0
  385. /package/tests/{core/utilities → utilities}/mocks/date.ts +0 -0
  386. /package/tests/{core/utilities → utilities}/mocks/posthog.ts +0 -0
  387. /package/tests/{core/utilities → utilities}/structures/common.ts +0 -0
  388. /package/tests/{core/utilities → utilities}/structures/generator.ts +0 -0
  389. /package/tests/{core/utilities → utilities}/structures/koa.ts +0 -0
  390. /package/tests/{core/utilities → utilities}/structures/licenses.ts +0 -0
  391. /package/tests/{core/utilities → utilities}/structures/plugins.ts +0 -0
  392. /package/tests/{core/utilities → utilities}/structures/shared.ts +0 -0
  393. /package/tests/{core/utilities → utilities}/structures/sso.ts +0 -0
  394. /package/tests/{core/utilities → utilities}/structures/userGroups.ts +0 -0
  395. /package/tests/{core/utilities → utilities}/structures/users.ts +0 -0
  396. /package/tests/{core/utilities → utilities}/testContainerUtils.ts +0 -0
package/src/db/utils.ts CHANGED
@@ -1,12 +1,257 @@
1
+ import { newid } from "../newid"
1
2
  import env from "../environment"
2
- import { DEFAULT_TENANT_ID, SEPARATOR, DocumentType } from "../constants"
3
+ import {
4
+ DEFAULT_TENANT_ID,
5
+ SEPARATOR,
6
+ DocumentType,
7
+ UNICODE_MAX,
8
+ ViewName,
9
+ InternalTable,
10
+ APP_PREFIX,
11
+ } from "../constants"
3
12
  import { getTenantId, getGlobalDBName } from "../context"
4
13
  import { doWithDB, directCouchAllDbs } from "./db"
5
14
  import { getAppMetadata } from "../cache/appMetadata"
6
- import { isDevApp, isDevAppID, getProdAppID } from "../docIds/conversions"
15
+ import { isDevApp, isDevAppID, getProdAppID } from "./conversions"
7
16
  import { App, Database } from "@budibase/types"
8
- import { getStartEndKeyURL } from "../docIds"
9
- export * from "../docIds"
17
+
18
+ /**
19
+ * Generates a new app ID.
20
+ * @returns {string} The new app ID which the app doc can be stored under.
21
+ */
22
+ export const generateAppID = (tenantId?: string | null) => {
23
+ let id = APP_PREFIX
24
+ if (tenantId) {
25
+ id += `${tenantId}${SEPARATOR}`
26
+ }
27
+ return `${id}${newid()}`
28
+ }
29
+
30
+ /**
31
+ * If creating DB allDocs/query params with only a single top level ID this can be used, this
32
+ * is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
33
+ * More complex cases such as link docs and rows which have multiple levels of IDs that their
34
+ * ID consists of need their own functions to build the allDocs parameters.
35
+ * @param {string} docType The type of document which input params are being built for, e.g. user,
36
+ * link, app, table and so on.
37
+ * @param {string|null} docId The ID of the document minus its type - this is only needed if looking
38
+ * for a singular document.
39
+ * @param {object} otherProps Add any other properties onto the request, e.g. include_docs.
40
+ * @returns {object} Parameters which can then be used with an allDocs request.
41
+ */
42
+ export function getDocParams(
43
+ docType: string,
44
+ docId?: string | null,
45
+ otherProps: any = {}
46
+ ) {
47
+ if (docId == null) {
48
+ docId = ""
49
+ }
50
+ return {
51
+ ...otherProps,
52
+ startkey: `${docType}${SEPARATOR}${docId}`,
53
+ endkey: `${docType}${SEPARATOR}${docId}${UNICODE_MAX}`,
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Gets the DB allDocs/query params for retrieving a row.
59
+ * @param {string|null} tableId The table in which the rows have been stored.
60
+ * @param {string|null} rowId The ID of the row which is being specifically queried for. This can be
61
+ * left null to get all the rows in the table.
62
+ * @param {object} otherProps Any other properties to add to the request.
63
+ * @returns {object} Parameters which can then be used with an allDocs request.
64
+ */
65
+ export function getRowParams(
66
+ tableId?: string | null,
67
+ rowId?: string | null,
68
+ otherProps = {}
69
+ ) {
70
+ if (tableId == null) {
71
+ return getDocParams(DocumentType.ROW, null, otherProps)
72
+ }
73
+
74
+ const endOfKey = rowId == null ? `${tableId}${SEPARATOR}` : rowId
75
+
76
+ return getDocParams(DocumentType.ROW, endOfKey, otherProps)
77
+ }
78
+
79
+ /**
80
+ * Retrieve the correct index for a view based on default design DB.
81
+ */
82
+ export function getQueryIndex(viewName: ViewName) {
83
+ return `database/${viewName}`
84
+ }
85
+
86
+ /**
87
+ * Gets a new row ID for the specified table.
88
+ * @param {string} tableId The table which the row is being created for.
89
+ * @param {string|null} id If an ID is to be used then the UUID can be substituted for this.
90
+ * @returns {string} The new ID which a row doc can be stored under.
91
+ */
92
+ export function generateRowID(tableId: string, id?: string) {
93
+ id = id || newid()
94
+ return `${DocumentType.ROW}${SEPARATOR}${tableId}${SEPARATOR}${id}`
95
+ }
96
+
97
+ /**
98
+ * Check if a given ID is that of a table.
99
+ * @returns {boolean}
100
+ */
101
+ export const isTableId = (id: string) => {
102
+ // this includes datasource plus tables
103
+ return (
104
+ id &&
105
+ (id.startsWith(`${DocumentType.TABLE}${SEPARATOR}`) ||
106
+ id.startsWith(`${DocumentType.DATASOURCE_PLUS}${SEPARATOR}`))
107
+ )
108
+ }
109
+
110
+ /**
111
+ * Check if a given ID is that of a datasource or datasource plus.
112
+ * @returns {boolean}
113
+ */
114
+ export const isDatasourceId = (id: string) => {
115
+ // this covers both datasources and datasource plus
116
+ return id && id.startsWith(`${DocumentType.DATASOURCE}${SEPARATOR}`)
117
+ }
118
+
119
+ /**
120
+ * Generates a new workspace ID.
121
+ * @returns {string} The new workspace ID which the workspace doc can be stored under.
122
+ */
123
+ export function generateWorkspaceID() {
124
+ return `${DocumentType.WORKSPACE}${SEPARATOR}${newid()}`
125
+ }
126
+
127
+ /**
128
+ * Gets parameters for retrieving workspaces.
129
+ */
130
+ export function getWorkspaceParams(id = "", otherProps = {}) {
131
+ return {
132
+ ...otherProps,
133
+ startkey: `${DocumentType.WORKSPACE}${SEPARATOR}${id}`,
134
+ endkey: `${DocumentType.WORKSPACE}${SEPARATOR}${id}${UNICODE_MAX}`,
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Generates a new global user ID.
140
+ * @returns {string} The new user ID which the user doc can be stored under.
141
+ */
142
+ export function generateGlobalUserID(id?: any) {
143
+ return `${DocumentType.USER}${SEPARATOR}${id || newid()}`
144
+ }
145
+
146
+ /**
147
+ * Gets parameters for retrieving users.
148
+ */
149
+ export function getGlobalUserParams(globalId: any, otherProps: any = {}) {
150
+ if (!globalId) {
151
+ globalId = ""
152
+ }
153
+ const startkey = otherProps?.startkey
154
+ return {
155
+ ...otherProps,
156
+ // need to include this incase pagination
157
+ startkey: startkey
158
+ ? startkey
159
+ : `${DocumentType.USER}${SEPARATOR}${globalId}`,
160
+ endkey: `${DocumentType.USER}${SEPARATOR}${globalId}${UNICODE_MAX}`,
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Gets parameters for retrieving users, this is a utility function for the getDocParams function.
166
+ */
167
+ export function getUserMetadataParams(userId?: string | null, otherProps = {}) {
168
+ return getRowParams(InternalTable.USER_METADATA, userId, otherProps)
169
+ }
170
+
171
+ /**
172
+ * Generates a new user ID based on the passed in global ID.
173
+ * @param {string} globalId The ID of the global user.
174
+ * @returns {string} The new user ID which the user doc can be stored under.
175
+ */
176
+ export function generateUserMetadataID(globalId: string) {
177
+ return generateRowID(InternalTable.USER_METADATA, globalId)
178
+ }
179
+
180
+ /**
181
+ * Breaks up the ID to get the global ID.
182
+ */
183
+ export function getGlobalIDFromUserMetadataID(id: string) {
184
+ const prefix = `${DocumentType.ROW}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`
185
+ if (!id || !id.includes(prefix)) {
186
+ return id
187
+ }
188
+ return id.split(prefix)[1]
189
+ }
190
+
191
+ export function getUsersByAppParams(appId: any, otherProps: any = {}) {
192
+ const prodAppId = getProdAppID(appId)
193
+ return {
194
+ ...otherProps,
195
+ startkey: prodAppId,
196
+ endkey: `${prodAppId}${UNICODE_MAX}`,
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Generates a template ID.
202
+ * @param ownerId The owner/user of the template, this could be global or a workspace level.
203
+ */
204
+ export function generateTemplateID(ownerId: any) {
205
+ return `${DocumentType.TEMPLATE}${SEPARATOR}${ownerId}${SEPARATOR}${newid()}`
206
+ }
207
+
208
+ export function generateAppUserID(prodAppId: string, userId: string) {
209
+ return `${prodAppId}${SEPARATOR}${userId}`
210
+ }
211
+
212
+ /**
213
+ * Gets parameters for retrieving templates. Owner ID must be specified, either global or a workspace level.
214
+ */
215
+ export function getTemplateParams(
216
+ ownerId: any,
217
+ templateId: any,
218
+ otherProps = {}
219
+ ) {
220
+ if (!templateId) {
221
+ templateId = ""
222
+ }
223
+ let final
224
+ if (templateId) {
225
+ final = templateId
226
+ } else {
227
+ final = `${DocumentType.TEMPLATE}${SEPARATOR}${ownerId}${SEPARATOR}`
228
+ }
229
+ return {
230
+ ...otherProps,
231
+ startkey: final,
232
+ endkey: `${final}${UNICODE_MAX}`,
233
+ }
234
+ }
235
+
236
+ /**
237
+ * Generates a new role ID.
238
+ * @returns {string} The new role ID which the role doc can be stored under.
239
+ */
240
+ export function generateRoleID(id?: any) {
241
+ return `${DocumentType.ROLE}${SEPARATOR}${id || newid()}`
242
+ }
243
+
244
+ /**
245
+ * Gets parameters for retrieving a role, this is a utility function for the getDocParams function.
246
+ */
247
+ export function getRoleParams(roleId?: string | null, otherProps = {}) {
248
+ return getDocParams(DocumentType.ROLE, roleId, otherProps)
249
+ }
250
+
251
+ export function getStartEndKeyURL(baseKey: any, tenantId?: string) {
252
+ const tenancy = tenantId ? `${SEPARATOR}${tenantId}` : ""
253
+ return `startkey="${baseKey}${tenancy}"&endkey="${baseKey}${tenancy}${UNICODE_MAX}"`
254
+ }
10
255
 
11
256
  /**
12
257
  * if in production this will use the CouchDB _all_dbs call to retrieve a list of databases. If testing
@@ -166,8 +411,31 @@ export async function dbExists(dbName: any) {
166
411
  )
167
412
  }
168
413
 
169
- export function pagination<T>(
170
- data: T[],
414
+ /**
415
+ * Generates a new dev info document ID - this is scoped to a user.
416
+ * @returns {string} The new dev info ID which info for dev (like api key) can be stored under.
417
+ */
418
+ export const generateDevInfoID = (userId: any) => {
419
+ return `${DocumentType.DEV_INFO}${SEPARATOR}${userId}`
420
+ }
421
+
422
+ /**
423
+ * Generates a new plugin ID - to be used in the global DB.
424
+ * @returns {string} The new plugin ID which a plugin metadata document can be stored under.
425
+ */
426
+ export const generatePluginID = (name: string) => {
427
+ return `${DocumentType.PLUGIN}${SEPARATOR}${name}`
428
+ }
429
+
430
+ /**
431
+ * Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
432
+ */
433
+ export const getPluginParams = (pluginId?: string | null, otherProps = {}) => {
434
+ return getDocParams(DocumentType.PLUGIN, pluginId, otherProps)
435
+ }
436
+
437
+ export function pagination(
438
+ data: any[],
171
439
  pageSize: number,
172
440
  {
173
441
  paginate,
@@ -176,7 +444,7 @@ export function pagination<T>(
176
444
  }: {
177
445
  paginate: boolean
178
446
  property: string
179
- getKey?: (doc: T) => string | undefined
447
+ getKey?: (doc: any) => string | undefined
180
448
  } = {
181
449
  paginate: true,
182
450
  property: "_id",
package/src/db/views.ts CHANGED
@@ -42,11 +42,7 @@ async function removeDeprecated(db: Database, viewName: ViewName) {
42
42
  }
43
43
  }
44
44
 
45
- export async function createView(
46
- db: any,
47
- viewJs: string,
48
- viewName: string
49
- ): Promise<void> {
45
+ export async function createView(db: any, viewJs: string, viewName: string) {
50
46
  let designDoc
51
47
  try {
52
48
  designDoc = (await db.get(DESIGN_DB)) as DesignDocument
@@ -61,15 +57,7 @@ export async function createView(
61
57
  ...designDoc.views,
62
58
  [viewName]: view,
63
59
  }
64
- try {
65
- await db.put(designDoc)
66
- } catch (err: any) {
67
- if (err.status === 409) {
68
- return await createView(db, viewJs, viewName)
69
- } else {
70
- throw err
71
- }
72
- }
60
+ await db.put(designDoc)
73
61
  }
74
62
 
75
63
  export const createNewUserEmailView = async () => {
@@ -147,10 +135,6 @@ export const queryView = async <T>(
147
135
  await removeDeprecated(db, viewName)
148
136
  await createFunc()
149
137
  return queryView(viewName, params, db, createFunc, opts)
150
- } else if (err.status === 409) {
151
- // can happen when multiple queries occur at once, view couldn't be created
152
- // other design docs being updated, re-run
153
- return queryView(viewName, params, db, createFunc, opts)
154
138
  } else {
155
139
  throw err
156
140
  }
@@ -36,15 +36,6 @@ function getAPIEncryptionKey() {
36
36
  : process.env.JWT_SECRET // fallback to the JWT_SECRET used historically
37
37
  }
38
38
 
39
- function httpLogging() {
40
- if (process.env.HTTP_LOGGING === undefined) {
41
- // on by default unless otherwise specified
42
- return true
43
- }
44
-
45
- return process.env.HTTP_LOGGING
46
- }
47
-
48
39
  const environment = {
49
40
  isTest,
50
41
  isJest,
@@ -99,11 +90,11 @@ const environment = {
99
90
  USE_COUCH: process.env.USE_COUCH || true,
100
91
  DEFAULT_LICENSE: process.env.DEFAULT_LICENSE,
101
92
  SERVICE: process.env.SERVICE || "budibase",
102
- LOG_LEVEL: process.env.LOG_LEVEL || "info",
93
+ LOG_LEVEL: process.env.LOG_LEVEL,
103
94
  SESSION_UPDATE_PERIOD: process.env.SESSION_UPDATE_PERIOD,
104
95
  DEPLOYMENT_ENVIRONMENT:
105
96
  process.env.DEPLOYMENT_ENVIRONMENT || "docker-compose",
106
- HTTP_LOGGING: httpLogging(),
97
+ ENABLE_4XX_HTTP_LOGGING: process.env.ENABLE_4XX_HTTP_LOGGING || true,
107
98
  ENABLE_AUDIT_LOG_IP_ADDR: process.env.ENABLE_AUDIT_LOG_IP_ADDR,
108
99
  // smtp
109
100
  SMTP_FALLBACK_ENABLED: process.env.SMTP_FALLBACK_ENABLED,
@@ -97,11 +97,3 @@ export class InvalidAPIKeyError extends BudibaseError {
97
97
  )
98
98
  }
99
99
  }
100
-
101
- // USERS
102
-
103
- export class EmailUnavailableError extends Error {
104
- constructor(email: string) {
105
- super(`Email already in use: '${email}'`)
106
- }
107
- }
@@ -1,8 +1,7 @@
1
- import { Event } from "@budibase/types"
1
+ import { Event, AuditedEventFriendlyName } from "@budibase/types"
2
2
  import { processors } from "./processors"
3
3
  import identification from "./identification"
4
4
  import * as backfill from "./backfill"
5
- import { publishAsyncEvent } from "./asyncEvents"
6
5
 
7
6
  export const publishEvent = async (
8
7
  event: Event,
@@ -15,14 +14,6 @@ export const publishEvent = async (
15
14
  const backfilling = await backfill.isBackfillingEvent(event)
16
15
  // no backfill - send the event and exit
17
16
  if (!backfilling) {
18
- // send off async events if required
19
- await publishAsyncEvent({
20
- event,
21
- identity,
22
- properties,
23
- timestamp,
24
- })
25
- // now handle the main sync event processing pipeline
26
17
  await processors.processEvent(event, identity, properties, timestamp)
27
18
  return
28
19
  }
@@ -65,7 +65,6 @@ const getCurrentIdentity = async (): Promise<Identity> => {
65
65
  hosting,
66
66
  installationId,
67
67
  tenantId,
68
- realTenantId: context.getTenantId(),
69
68
  environment,
70
69
  }
71
70
  } else if (identityType === IdentityType.USER) {
@@ -6,8 +6,6 @@ export * as backfillCache from "./backfill"
6
6
 
7
7
  import { processors } from "./processors"
8
8
 
9
- export function initAsyncEvents() {}
10
-
11
9
  export const shutdown = () => {
12
10
  processors.shutdown()
13
11
  console.log("Events shutdown")
@@ -2,6 +2,14 @@ import { Event, Identity, Group } from "@budibase/types"
2
2
  import { EventProcessor } from "./types"
3
3
  import env from "../../environment"
4
4
 
5
+ const getTimestampString = (timestamp?: string | number) => {
6
+ let timestampString = ""
7
+ if (timestamp) {
8
+ timestampString = `[timestamp=${new Date(timestamp).toISOString()}]`
9
+ }
10
+ return timestampString
11
+ }
12
+
5
13
  const skipLogging = env.SELF_HOSTED && !env.isDev()
6
14
 
7
15
  export default class LoggingProcessor implements EventProcessor {
@@ -14,21 +22,32 @@ export default class LoggingProcessor implements EventProcessor {
14
22
  if (skipLogging) {
15
23
  return
16
24
  }
17
- console.log(`[audit] [identityType=${identity.type}] ${event}`, properties)
25
+ let timestampString = getTimestampString(timestamp)
26
+ let message = `[audit] [identityType=${identity.type}] ${timestampString} ${event} `
27
+ if (env.isDev()) {
28
+ message = message + `[debug: [properties=${JSON.stringify(properties)}] ]`
29
+ }
30
+ console.log(message)
18
31
  }
19
32
 
20
33
  async identify(identity: Identity, timestamp?: string | number) {
21
34
  if (skipLogging) {
22
35
  return
23
36
  }
24
- console.log(`[audit] identified`, identity)
37
+ let timestampString = getTimestampString(timestamp)
38
+ console.log(
39
+ `[audit] [${JSON.stringify(identity)}] ${timestampString} identified`
40
+ )
25
41
  }
26
42
 
27
43
  async identifyGroup(group: Group, timestamp?: string | number) {
28
44
  if (skipLogging) {
29
45
  return
30
46
  }
31
- console.log(`[audit] group identified`, group)
47
+ let timestampString = getTimestampString(timestamp)
48
+ console.log(
49
+ `[audit] [${JSON.stringify(group)}] ${timestampString} group identified`
50
+ )
32
51
  }
33
52
 
34
53
  shutdown(): void {
@@ -25,9 +25,7 @@ export default class Processor implements EventProcessor {
25
25
  timestamp?: string | number
26
26
  ): Promise<void> {
27
27
  for (const eventProcessor of this.processors) {
28
- if (eventProcessor.identify) {
29
- await eventProcessor.identify(identity, timestamp)
30
- }
28
+ await eventProcessor.identify(identity, timestamp)
31
29
  }
32
30
  }
33
31
 
@@ -36,17 +34,13 @@ export default class Processor implements EventProcessor {
36
34
  timestamp?: string | number
37
35
  ): Promise<void> {
38
36
  for (const eventProcessor of this.processors) {
39
- if (eventProcessor.identifyGroup) {
40
- await eventProcessor.identifyGroup(identity, timestamp)
41
- }
37
+ await eventProcessor.identifyGroup(identity, timestamp)
42
38
  }
43
39
  }
44
40
 
45
41
  shutdown() {
46
42
  for (const eventProcessor of this.processors) {
47
- if (eventProcessor.shutdown) {
48
- eventProcessor.shutdown()
49
- }
43
+ eventProcessor.shutdown()
50
44
  }
51
45
  }
52
46
  }
@@ -1,4 +1,4 @@
1
- import { testEnv } from "../../../../../tests/extra"
1
+ import { testEnv } from "../../../../../tests"
2
2
  import PosthogProcessor from "../PosthogProcessor"
3
3
  import { Event, IdentityType, Hosting } from "@budibase/types"
4
4
  const tk = require("timekeeper")
@@ -1 +1,18 @@
1
- export { EventProcessor } from "@budibase/types"
1
+ import { Event, Identity, Group } from "@budibase/types"
2
+
3
+ export enum EventProcessorType {
4
+ POSTHOG = "posthog",
5
+ LOGGING = "logging",
6
+ }
7
+
8
+ export interface EventProcessor {
9
+ processEvent(
10
+ event: Event,
11
+ identity: Identity,
12
+ properties: any,
13
+ timestamp?: string | number
14
+ ): Promise<void>
15
+ identify(identity: Identity, timestamp?: string | number): Promise<void>
16
+ identifyGroup(group: Group, timestamp?: string | number): Promise<void>
17
+ shutdown(): void
18
+ }
@@ -9,13 +9,12 @@ import {
9
9
  GroupUsersDeletedEvent,
10
10
  GroupAddedOnboardingEvent,
11
11
  GroupPermissionsEditedEvent,
12
+ UserGroupRoles,
12
13
  } from "@budibase/types"
13
- import { isScim } from "../../context"
14
14
 
15
15
  async function created(group: UserGroup, timestamp?: number) {
16
16
  const properties: GroupCreatedEvent = {
17
17
  groupId: group._id as string,
18
- viaScim: isScim(),
19
18
  audited: {
20
19
  name: group.name,
21
20
  },
@@ -26,7 +25,6 @@ async function created(group: UserGroup, timestamp?: number) {
26
25
  async function updated(group: UserGroup) {
27
26
  const properties: GroupUpdatedEvent = {
28
27
  groupId: group._id as string,
29
- viaScim: isScim(),
30
28
  audited: {
31
29
  name: group.name,
32
30
  },
@@ -37,7 +35,6 @@ async function updated(group: UserGroup) {
37
35
  async function deleted(group: UserGroup) {
38
36
  const properties: GroupDeletedEvent = {
39
37
  groupId: group._id as string,
40
- viaScim: isScim(),
41
38
  audited: {
42
39
  name: group.name,
43
40
  },
@@ -49,7 +46,6 @@ async function usersAdded(count: number, group: UserGroup) {
49
46
  const properties: GroupUsersAddedEvent = {
50
47
  count,
51
48
  groupId: group._id as string,
52
- viaScim: isScim(),
53
49
  audited: {
54
50
  name: group.name,
55
51
  },
@@ -61,7 +57,6 @@ async function usersDeleted(count: number, group: UserGroup) {
61
57
  const properties: GroupUsersDeletedEvent = {
62
58
  count,
63
59
  groupId: group._id as string,
64
- viaScim: isScim(),
65
60
  audited: {
66
61
  name: group.name,
67
62
  },
@@ -15,12 +15,10 @@ import {
15
15
  UserUpdatedEvent,
16
16
  UserOnboardingEvent,
17
17
  } from "@budibase/types"
18
- import { isScim } from "../../context"
19
18
 
20
19
  async function created(user: User, timestamp?: number) {
21
20
  const properties: UserCreatedEvent = {
22
21
  userId: user._id as string,
23
- viaScim: isScim(),
24
22
  audited: {
25
23
  email: user.email,
26
24
  },
@@ -31,7 +29,6 @@ async function created(user: User, timestamp?: number) {
31
29
  async function updated(user: User) {
32
30
  const properties: UserUpdatedEvent = {
33
31
  userId: user._id as string,
34
- viaScim: isScim(),
35
32
  audited: {
36
33
  email: user.email,
37
34
  },
@@ -42,7 +39,6 @@ async function updated(user: User) {
42
39
  async function deleted(user: User) {
43
40
  const properties: UserDeletedEvent = {
44
41
  userId: user._id as string,
45
- viaScim: isScim(),
46
42
  audited: {
47
43
  email: user.email,
48
44
  },
package/src/index.ts CHANGED
@@ -27,7 +27,6 @@ export * as errors from "./errors"
27
27
  export * as timers from "./timers"
28
28
  export { default as env } from "./environment"
29
29
  export * as blacklist from "./blacklist"
30
- export * as docUpdates from "./docUpdates"
31
30
  export { SearchParams } from "./db"
32
31
  // Add context to tenancy for backwards compatibility
33
32
  // only do this for external usages to prevent internal
package/src/logging.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { Header } from "./constants"
2
+ import env from "./environment"
3
+ const correlator = require("correlation-id")
4
+ import { Options } from "pino-http"
5
+ import { IncomingMessage } from "http"
6
+
7
+ const NonErrors = ["AccountError"]
8
+
9
+ function isSuppressed(e?: any) {
10
+ return e && e["suppressAlert"]
11
+ }
12
+
13
+ export function logAlert(message: string, e?: any) {
14
+ if (e && NonErrors.includes(e.name) && isSuppressed(e)) {
15
+ return
16
+ }
17
+ let errorJson = ""
18
+ if (e) {
19
+ errorJson = ": " + JSON.stringify(e, Object.getOwnPropertyNames(e))
20
+ }
21
+ console.error(`bb-alert: ${message} ${errorJson}`)
22
+ }
23
+
24
+ export function logAlertWithInfo(
25
+ message: string,
26
+ db: string,
27
+ id: string,
28
+ error: any
29
+ ) {
30
+ message = `${message} - db: ${db} - doc: ${id} - error: `
31
+ logAlert(message, error)
32
+ }
33
+
34
+ export function logWarn(message: string) {
35
+ console.warn(`bb-warn: ${message}`)
36
+ }
37
+
38
+ export function pinoSettings(): Options {
39
+ return {
40
+ prettyPrint: {
41
+ levelFirst: true,
42
+ },
43
+ genReqId: correlator.getId,
44
+ level: env.LOG_LEVEL || "error",
45
+ autoLogging: {
46
+ ignore: (req: IncomingMessage) => !!req.url?.includes("/health"),
47
+ },
48
+ }
49
+ }
50
+
51
+ const setCorrelationHeader = (headers: any) => {
52
+ const correlationId = correlator.getId()
53
+ if (correlationId) {
54
+ headers[Header.CORRELATION_ID] = correlationId
55
+ }
56
+ }
57
+
58
+ export const correlation = {
59
+ setHeader: setCorrelationHeader,
60
+ }