@budibase/backend-core 2.5.9 → 2.5.10-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 (438) hide show
  1. package/dist/package.json +13 -10
  2. package/dist/src/configs/configs.d.ts +2 -1
  3. package/dist/src/configs/configs.js +9 -1
  4. package/dist/src/configs/configs.js.map +1 -1
  5. package/dist/src/constants/db.d.ts +1 -0
  6. package/dist/src/constants/db.js +1 -0
  7. package/dist/src/constants/db.js.map +1 -1
  8. package/dist/src/constants/misc.d.ts +4 -2
  9. package/dist/src/constants/misc.js +2 -0
  10. package/dist/src/constants/misc.js.map +1 -1
  11. package/dist/src/context/mainContext.d.ts +5 -2
  12. package/dist/src/context/mainContext.js +20 -3
  13. package/dist/src/context/mainContext.js.map +1 -1
  14. package/dist/src/context/types.d.ts +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 +2 -1
  18. package/dist/src/db/index.js +15 -2
  19. package/dist/src/db/index.js.map +1 -1
  20. package/dist/src/db/lucene.d.ts +8 -14
  21. package/dist/src/db/lucene.js +164 -97
  22. package/dist/src/db/lucene.js.map +1 -1
  23. package/dist/src/db/searchIndexes/index.d.ts +1 -0
  24. package/dist/src/db/searchIndexes/index.js +18 -0
  25. package/dist/src/db/searchIndexes/index.js.map +1 -0
  26. package/dist/src/db/searchIndexes/searchIndexes.d.ts +1 -0
  27. package/dist/src/db/searchIndexes/searchIndexes.js +77 -0
  28. package/dist/src/db/searchIndexes/searchIndexes.js.map +1 -0
  29. package/dist/src/db/utils.d.ts +5 -126
  30. package/dist/src/db/utils.js +20 -232
  31. package/dist/src/db/utils.js.map +1 -1
  32. package/dist/src/db/views.d.ts +3 -1
  33. package/dist/src/db/views.js +61 -30
  34. package/dist/src/db/views.js.map +1 -1
  35. package/dist/src/docIds/conversions.js.map +1 -0
  36. package/dist/src/docIds/ids.d.ts +53 -0
  37. package/dist/src/docIds/ids.js +101 -0
  38. package/dist/src/docIds/ids.js.map +1 -0
  39. package/dist/src/docIds/index.d.ts +2 -0
  40. package/dist/src/docIds/index.js +19 -0
  41. package/dist/src/docIds/index.js.map +1 -0
  42. package/dist/src/docIds/newid.js.map +1 -0
  43. package/dist/src/docIds/params.d.ts +69 -0
  44. package/dist/src/docIds/params.js +138 -0
  45. package/dist/src/docIds/params.js.map +1 -0
  46. package/dist/src/docUpdates/index.d.ts +2 -0
  47. package/dist/src/docUpdates/index.js +36 -0
  48. package/dist/src/docUpdates/index.js.map +1 -0
  49. package/dist/src/environment.d.ts +4 -2
  50. package/dist/src/environment.js +35 -2
  51. package/dist/src/environment.js.map +1 -1
  52. package/dist/src/errors/errors.d.ts +3 -0
  53. package/dist/src/errors/errors.js +8 -1
  54. package/dist/src/errors/errors.js.map +1 -1
  55. package/dist/src/events/asyncEvents/index.d.ts +2 -0
  56. package/dist/src/events/asyncEvents/index.js +19 -0
  57. package/dist/src/events/asyncEvents/index.js.map +1 -0
  58. package/dist/src/events/asyncEvents/publisher.d.ts +2 -0
  59. package/dist/src/events/asyncEvents/publisher.js +27 -0
  60. package/dist/src/events/asyncEvents/publisher.js.map +1 -0
  61. package/dist/src/events/asyncEvents/queue.d.ts +11 -0
  62. package/dist/src/events/asyncEvents/queue.js +26 -0
  63. package/dist/src/events/asyncEvents/queue.js.map +1 -0
  64. package/dist/src/events/documentId.d.ts +2 -0
  65. package/dist/src/events/documentId.js +28 -0
  66. package/dist/src/events/documentId.js.map +1 -0
  67. package/dist/src/events/events.js +9 -0
  68. package/dist/src/events/events.js.map +1 -1
  69. package/dist/src/events/identification.d.ts +1 -0
  70. package/dist/src/events/identification.js +3 -2
  71. package/dist/src/events/identification.js.map +1 -1
  72. package/dist/src/events/index.d.ts +1 -0
  73. package/dist/src/events/index.js +3 -1
  74. package/dist/src/events/index.js.map +1 -1
  75. package/dist/src/events/processors/LoggingProcessor.js +3 -17
  76. package/dist/src/events/processors/LoggingProcessor.js.map +1 -1
  77. package/dist/src/events/processors/Processors.js +9 -3
  78. package/dist/src/events/processors/Processors.js.map +1 -1
  79. package/dist/src/events/processors/async/DocumentUpdateProcessor.d.ts +13 -0
  80. package/dist/src/events/processors/async/DocumentUpdateProcessor.js +44 -0
  81. package/dist/src/events/processors/async/DocumentUpdateProcessor.js.map +1 -0
  82. package/dist/src/events/processors/posthog/PosthogProcessor.js +1 -2
  83. package/dist/src/events/processors/posthog/PosthogProcessor.js.map +1 -1
  84. package/dist/src/events/processors/types.d.ts +1 -11
  85. package/dist/src/events/processors/types.js +0 -6
  86. package/dist/src/events/processors/types.js.map +1 -1
  87. package/dist/src/events/publishers/group.js +6 -0
  88. package/dist/src/events/publishers/group.js.map +1 -1
  89. package/dist/src/events/publishers/license.d.ts +9 -4
  90. package/dist/src/events/publishers/license.js +2 -17
  91. package/dist/src/events/publishers/license.js.map +1 -1
  92. package/dist/src/events/publishers/user.js +4 -0
  93. package/dist/src/events/publishers/user.js.map +1 -1
  94. package/dist/src/index.d.ts +6 -2
  95. package/dist/src/index.js +2 -1
  96. package/dist/src/index.js.map +1 -1
  97. package/dist/src/installation.d.ts +1 -0
  98. package/dist/src/installation.js +7 -6
  99. package/dist/src/installation.js.map +1 -1
  100. package/dist/src/{logging.d.ts → logging/alerts.d.ts} +0 -5
  101. package/dist/src/logging/alerts.js +24 -0
  102. package/dist/src/logging/alerts.js.map +1 -0
  103. package/dist/src/logging/correlation/correlation.d.ts +2 -0
  104. package/dist/src/logging/correlation/correlation.js +17 -0
  105. package/dist/src/logging/correlation/correlation.js.map +1 -0
  106. package/dist/src/logging/correlation/index.d.ts +1 -0
  107. package/dist/src/logging/correlation/index.js +18 -0
  108. package/dist/src/logging/correlation/index.js.map +1 -0
  109. package/dist/src/logging/correlation/middleware.d.ts +2 -0
  110. package/dist/src/logging/correlation/middleware.js +17 -0
  111. package/dist/src/logging/correlation/middleware.js.map +1 -0
  112. package/dist/src/logging/index.d.ts +4 -0
  113. package/dist/src/logging/index.js +36 -0
  114. package/dist/src/logging/index.js.map +1 -0
  115. package/dist/src/logging/pino/logger.d.ts +2 -0
  116. package/dist/src/logging/pino/logger.js +167 -0
  117. package/dist/src/logging/pino/logger.js.map +1 -0
  118. package/dist/src/logging/pino/middleware.d.ts +4 -0
  119. package/dist/src/logging/pino/middleware.js +47 -0
  120. package/dist/src/logging/pino/middleware.js.map +1 -0
  121. package/dist/src/middleware/authenticated.js +6 -3
  122. package/dist/src/middleware/authenticated.js.map +1 -1
  123. package/dist/src/middleware/errorHandling.js +5 -7
  124. package/dist/src/middleware/errorHandling.js.map +1 -1
  125. package/dist/src/middleware/index.d.ts +2 -1
  126. package/dist/src/middleware/index.js +5 -3
  127. package/dist/src/middleware/index.js.map +1 -1
  128. package/dist/src/middleware/passport/sso/oidc.js +2 -5
  129. package/dist/src/middleware/passport/sso/oidc.js.map +1 -1
  130. package/dist/src/middleware/tenancy.d.ts +1 -1
  131. package/dist/src/migrations/migrations.js +4 -4
  132. package/dist/src/migrations/migrations.js.map +1 -1
  133. package/dist/src/objectStore/objectStore.js +3 -3
  134. package/dist/src/objectStore/objectStore.js.map +1 -1
  135. package/dist/src/plugin/utils.js +53 -2
  136. package/dist/src/plugin/utils.js.map +1 -1
  137. package/dist/src/queue/constants.d.ts +2 -1
  138. package/dist/src/queue/constants.js +1 -0
  139. package/dist/src/queue/constants.js.map +1 -1
  140. package/dist/src/redis/redlockImpl.js +4 -1
  141. package/dist/src/redis/redlockImpl.js.map +1 -1
  142. package/dist/src/security/encryption.d.ts +1 -0
  143. package/dist/src/security/encryption.js +2 -1
  144. package/dist/src/security/encryption.js.map +1 -1
  145. package/dist/src/security/permissions.d.ts +35 -2
  146. package/dist/src/security/permissions.js +9 -6
  147. package/dist/src/security/permissions.js.map +1 -1
  148. package/dist/src/tenancy/tenancy.js +1 -5
  149. package/dist/src/tenancy/tenancy.js.map +1 -1
  150. package/dist/src/users.d.ts +11 -1
  151. package/dist/src/users.js +45 -1
  152. package/dist/src/users.js.map +1 -1
  153. package/dist/src/utils/hashing.d.ts +1 -1
  154. package/dist/src/utils/hashing.js +1 -1
  155. package/dist/src/utils/hashing.js.map +1 -1
  156. package/dist/src/utils/index.d.ts +1 -0
  157. package/dist/src/utils/index.js +1 -0
  158. package/dist/src/utils/index.js.map +1 -1
  159. package/dist/src/utils/stringUtils.d.ts +1 -0
  160. package/dist/src/utils/stringUtils.js +9 -0
  161. package/dist/src/utils/stringUtils.js.map +1 -0
  162. package/dist/src/utils/utils.d.ts +0 -1
  163. package/dist/src/utils/utils.js +1 -24
  164. package/dist/src/utils/utils.js.map +1 -1
  165. package/dist/tests/core/logging.js.map +1 -0
  166. package/dist/tests/{utilities → core/utilities}/index.d.ts +1 -2
  167. package/dist/tests/{utilities → core/utilities}/index.js +2 -7
  168. package/dist/tests/core/utilities/index.js.map +1 -0
  169. package/dist/tests/core/utilities/jestUtils.js.map +1 -0
  170. package/dist/tests/core/utilities/mocks/alerts.d.ts +3 -0
  171. package/dist/tests/core/utilities/mocks/alerts.js +30 -0
  172. package/dist/tests/core/utilities/mocks/alerts.js.map +1 -0
  173. package/dist/tests/core/utilities/mocks/date.js.map +1 -0
  174. package/dist/tests/core/utilities/mocks/events.js +144 -0
  175. package/dist/tests/core/utilities/mocks/events.js.map +1 -0
  176. package/dist/tests/core/utilities/mocks/fetch.d.ts +33 -0
  177. package/dist/tests/core/utilities/mocks/fetch.js +15 -0
  178. package/dist/tests/core/utilities/mocks/fetch.js.map +1 -0
  179. package/dist/tests/{utilities → core/utilities}/mocks/index.d.ts +4 -3
  180. package/dist/tests/{utilities → core/utilities}/mocks/index.js +7 -3
  181. package/dist/tests/core/utilities/mocks/index.js.map +1 -0
  182. package/dist/tests/{utilities → core/utilities}/mocks/licenses.d.ts +1 -0
  183. package/dist/tests/{utilities → core/utilities}/mocks/licenses.js +5 -1
  184. package/dist/tests/core/utilities/mocks/licenses.js.map +1 -0
  185. package/dist/tests/core/utilities/mocks/posthog.js.map +1 -0
  186. package/dist/tests/core/utilities/structures/Chance.d.ts +7 -0
  187. package/dist/tests/core/utilities/structures/Chance.js +21 -0
  188. package/dist/tests/core/utilities/structures/Chance.js.map +1 -0
  189. package/dist/tests/{utilities → core/utilities}/structures/accounts.js +3 -25
  190. package/dist/tests/core/utilities/structures/accounts.js.map +1 -0
  191. package/dist/tests/{utilities → core/utilities}/structures/apps.js +1 -1
  192. package/dist/tests/core/utilities/structures/apps.js.map +1 -0
  193. package/dist/tests/core/utilities/structures/common.js.map +1 -0
  194. package/dist/tests/{utilities → core/utilities}/structures/db.js +1 -1
  195. package/dist/tests/core/utilities/structures/db.js.map +1 -0
  196. package/dist/tests/core/utilities/structures/generator.d.ts +2 -0
  197. package/dist/tests/{utilities → core/utilities}/structures/generator.js +2 -2
  198. package/dist/tests/core/utilities/structures/generator.js.map +1 -0
  199. package/dist/tests/{utilities → core/utilities}/structures/index.d.ts +2 -0
  200. package/dist/tests/{utilities → core/utilities}/structures/index.js +3 -1
  201. package/dist/tests/core/utilities/structures/index.js.map +1 -0
  202. package/dist/tests/core/utilities/structures/koa.js.map +1 -0
  203. package/dist/tests/core/utilities/structures/licenses.d.ts +17 -0
  204. package/dist/tests/core/utilities/structures/licenses.js +127 -0
  205. package/dist/tests/core/utilities/structures/licenses.js.map +1 -0
  206. package/dist/tests/core/utilities/structures/plugins.js.map +1 -0
  207. package/dist/tests/core/utilities/structures/quotas.d.ts +2 -0
  208. package/dist/tests/core/utilities/structures/quotas.js +71 -0
  209. package/dist/tests/core/utilities/structures/quotas.js.map +1 -0
  210. package/dist/tests/core/utilities/structures/scim.d.ts +14 -0
  211. package/dist/tests/core/utilities/structures/scim.js +67 -0
  212. package/dist/tests/core/utilities/structures/scim.js.map +1 -0
  213. package/dist/tests/core/utilities/structures/shared.js.map +1 -0
  214. package/dist/tests/core/utilities/structures/sso.js.map +1 -0
  215. package/dist/tests/{utilities → core/utilities}/structures/tenants.js +1 -1
  216. package/dist/tests/core/utilities/structures/tenants.js.map +1 -0
  217. package/dist/tests/core/utilities/structures/userGroups.js.map +1 -0
  218. package/dist/tests/core/utilities/structures/users.js.map +1 -0
  219. package/dist/tests/core/utilities/testContainerUtils.js.map +1 -0
  220. package/dist/tests/core/utilities/utils/index.d.ts +1 -0
  221. package/dist/tests/core/utilities/utils/index.js +28 -0
  222. package/dist/tests/core/utilities/utils/index.js.map +1 -0
  223. package/dist/tests/core/utilities/utils/time.d.ts +1 -0
  224. package/dist/tests/core/utilities/utils/time.js +8 -0
  225. package/dist/tests/core/utilities/utils/time.js.map +1 -0
  226. package/dist/tests/{utilities → extra}/DBTestConfiguration.d.ts +1 -1
  227. package/dist/tests/{utilities → extra}/DBTestConfiguration.js +2 -2
  228. package/dist/tests/extra/DBTestConfiguration.js.map +1 -0
  229. package/dist/tests/extra/index.d.ts +2 -0
  230. package/dist/tests/extra/index.js +33 -0
  231. package/dist/tests/extra/index.js.map +1 -0
  232. package/dist/tests/{utilities → extra}/testEnv.d.ts +1 -1
  233. package/dist/tests/{utilities → extra}/testEnv.js +1 -1
  234. package/dist/tests/extra/testEnv.js.map +1 -0
  235. package/dist/tests/index.d.ts +1 -1
  236. package/dist/tests/index.js +1 -1
  237. package/dist/tests/index.js.map +1 -1
  238. package/dist/tests/jestEnv.js +0 -1
  239. package/dist/tests/jestEnv.js.map +1 -1
  240. package/dist/tests/jestSetup.d.ts +1 -1
  241. package/dist/tests/jestSetup.js +2 -2
  242. package/dist/tests/jestSetup.js.map +1 -1
  243. package/dist/tsconfig.build.tsbuildinfo +1 -1
  244. package/package.json +13 -10
  245. package/src/auth/tests/auth.spec.ts +2 -1
  246. package/src/cache/tests/writethrough.spec.ts +4 -3
  247. package/src/configs/configs.ts +9 -0
  248. package/src/configs/tests/configs.spec.ts +2 -6
  249. package/src/constants/db.ts +1 -0
  250. package/src/constants/misc.ts +2 -0
  251. package/src/context/mainContext.ts +22 -5
  252. package/src/context/tests/index.spec.ts +16 -3
  253. package/src/context/types.ts +1 -0
  254. package/src/db/couch/DatabaseImpl.ts +1 -1
  255. package/src/db/index.ts +2 -1
  256. package/src/db/lucene.ts +156 -99
  257. package/src/db/searchIndexes/index.ts +1 -0
  258. package/src/db/searchIndexes/searchIndexes.ts +62 -0
  259. package/src/db/tests/lucene.spec.ts +101 -1
  260. package/src/db/tests/utils.spec.ts +1 -1
  261. package/src/db/utils.ts +7 -275
  262. package/src/db/views.ts +64 -25
  263. package/src/docIds/ids.ts +102 -0
  264. package/src/docIds/index.ts +2 -0
  265. package/src/docIds/params.ts +174 -0
  266. package/src/docUpdates/index.ts +29 -0
  267. package/src/environment.ts +44 -2
  268. package/src/errors/errors.ts +8 -0
  269. package/src/events/asyncEvents/index.ts +2 -0
  270. package/src/events/asyncEvents/publisher.ts +12 -0
  271. package/src/events/asyncEvents/queue.ts +22 -0
  272. package/src/events/documentId.ts +56 -0
  273. package/src/events/events.ts +10 -1
  274. package/src/events/identification.ts +3 -3
  275. package/src/events/index.ts +2 -0
  276. package/src/events/processors/LoggingProcessor.ts +3 -22
  277. package/src/events/processors/Processors.ts +9 -3
  278. package/src/events/processors/async/DocumentUpdateProcessor.ts +43 -0
  279. package/src/events/processors/posthog/PosthogProcessor.ts +1 -2
  280. package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +1 -1
  281. package/src/events/processors/types.ts +1 -18
  282. package/src/events/publishers/group.ts +6 -1
  283. package/src/events/publishers/license.ts +12 -13
  284. package/src/events/publishers/user.ts +4 -0
  285. package/src/index.ts +1 -0
  286. package/src/installation.ts +4 -5
  287. package/src/logging/alerts.ts +26 -0
  288. package/src/logging/correlation/correlation.ts +13 -0
  289. package/src/logging/correlation/index.ts +1 -0
  290. package/src/logging/correlation/middleware.ts +17 -0
  291. package/src/logging/index.ts +6 -0
  292. package/src/logging/pino/logger.ts +173 -0
  293. package/src/logging/pino/middleware.ts +45 -0
  294. package/src/middleware/authenticated.ts +9 -3
  295. package/src/middleware/errorHandling.ts +4 -4
  296. package/src/middleware/index.ts +2 -1
  297. package/src/middleware/passport/sso/oidc.ts +2 -9
  298. package/src/middleware/passport/sso/tests/sso.spec.ts +2 -1
  299. package/src/migrations/migrations.ts +4 -8
  300. package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +1 -1
  301. package/src/migrations/tests/migrations.spec.ts +1 -1
  302. package/src/objectStore/buckets/tests/app.spec.ts +1 -1
  303. package/src/objectStore/buckets/tests/global.spec.ts +1 -1
  304. package/src/objectStore/buckets/tests/plugins.spec.ts +2 -1
  305. package/src/objectStore/objectStore.ts +3 -3
  306. package/src/platform/tests/tenants.spec.ts +2 -1
  307. package/src/plugin/tests/validation.spec.ts +83 -0
  308. package/src/plugin/utils.ts +63 -3
  309. package/src/queue/constants.ts +1 -0
  310. package/src/redis/redlockImpl.ts +9 -3
  311. package/src/security/encryption.ts +1 -1
  312. package/src/security/permissions.ts +5 -5
  313. package/src/security/tests/encryption.spec.ts +31 -0
  314. package/src/security/tests/permissions.spec.ts +145 -0
  315. package/src/tenancy/tenancy.ts +2 -2
  316. package/src/tenancy/tests/tenancy.spec.ts +184 -0
  317. package/src/users.ts +56 -7
  318. package/src/utils/hashing.ts +1 -1
  319. package/src/utils/index.ts +1 -0
  320. package/src/utils/stringUtils.ts +8 -0
  321. package/src/utils/tests/utils.spec.ts +2 -1
  322. package/src/utils/utils.ts +3 -23
  323. package/tests/{utilities → core/utilities}/index.ts +1 -4
  324. package/tests/core/utilities/mocks/alerts.ts +3 -0
  325. package/tests/core/utilities/mocks/events.ts +133 -0
  326. package/tests/core/utilities/mocks/fetch.ts +17 -0
  327. package/tests/{utilities → core/utilities}/mocks/index.ts +4 -3
  328. package/tests/{utilities → core/utilities}/mocks/licenses.ts +4 -0
  329. package/tests/core/utilities/structures/Chance.ts +20 -0
  330. package/tests/{utilities → core/utilities}/structures/accounts.ts +4 -3
  331. package/tests/{utilities → core/utilities}/structures/apps.ts +1 -1
  332. package/tests/{utilities → core/utilities}/structures/db.ts +1 -1
  333. package/tests/{utilities → core/utilities}/structures/generator.ts +1 -1
  334. package/tests/{utilities → core/utilities}/structures/index.ts +2 -0
  335. package/tests/core/utilities/structures/licenses.ts +145 -0
  336. package/tests/core/utilities/structures/quotas.ts +67 -0
  337. package/tests/core/utilities/structures/scim.ts +81 -0
  338. package/tests/{utilities → core/utilities}/structures/tenants.ts +1 -1
  339. package/tests/core/utilities/utils/index.ts +1 -0
  340. package/tests/core/utilities/utils/time.ts +3 -0
  341. package/tests/{utilities → extra}/DBTestConfiguration.ts +2 -2
  342. package/tests/extra/index.ts +2 -0
  343. package/tests/{utilities → extra}/testEnv.ts +1 -1
  344. package/tests/index.ts +1 -1
  345. package/tests/jestEnv.ts +0 -1
  346. package/tests/jestSetup.ts +2 -2
  347. package/tsconfig.build.json +3 -7
  348. package/dist/src/db/conversions.js.map +0 -1
  349. package/dist/src/logging.js +0 -56
  350. package/dist/src/logging.js.map +0 -1
  351. package/dist/src/middleware/logging.d.ts +0 -2
  352. package/dist/src/middleware/logging.js +0 -106
  353. package/dist/src/middleware/logging.js.map +0 -1
  354. package/dist/src/newid.js.map +0 -1
  355. package/dist/tests/logging.js.map +0 -1
  356. package/dist/tests/utilities/DBTestConfiguration.js.map +0 -1
  357. package/dist/tests/utilities/index.js.map +0 -1
  358. package/dist/tests/utilities/jestUtils.js.map +0 -1
  359. package/dist/tests/utilities/mocks/date.js.map +0 -1
  360. package/dist/tests/utilities/mocks/events.js +0 -126
  361. package/dist/tests/utilities/mocks/events.js.map +0 -1
  362. package/dist/tests/utilities/mocks/fetch.d.ts +0 -31
  363. package/dist/tests/utilities/mocks/fetch.js +0 -8
  364. package/dist/tests/utilities/mocks/fetch.js.map +0 -1
  365. package/dist/tests/utilities/mocks/index.js.map +0 -1
  366. package/dist/tests/utilities/mocks/licenses.js.map +0 -1
  367. package/dist/tests/utilities/mocks/posthog.js.map +0 -1
  368. package/dist/tests/utilities/structures/accounts.js.map +0 -1
  369. package/dist/tests/utilities/structures/apps.js.map +0 -1
  370. package/dist/tests/utilities/structures/common.js.map +0 -1
  371. package/dist/tests/utilities/structures/db.js.map +0 -1
  372. package/dist/tests/utilities/structures/generator.d.ts +0 -1
  373. package/dist/tests/utilities/structures/generator.js.map +0 -1
  374. package/dist/tests/utilities/structures/index.js.map +0 -1
  375. package/dist/tests/utilities/structures/koa.js.map +0 -1
  376. package/dist/tests/utilities/structures/licenses.d.ts +0 -5
  377. package/dist/tests/utilities/structures/licenses.js +0 -18
  378. package/dist/tests/utilities/structures/licenses.js.map +0 -1
  379. package/dist/tests/utilities/structures/plugins.js.map +0 -1
  380. package/dist/tests/utilities/structures/shared.js.map +0 -1
  381. package/dist/tests/utilities/structures/sso.js.map +0 -1
  382. package/dist/tests/utilities/structures/tenants.js.map +0 -1
  383. package/dist/tests/utilities/structures/userGroups.js.map +0 -1
  384. package/dist/tests/utilities/structures/users.js.map +0 -1
  385. package/dist/tests/utilities/testContainerUtils.js.map +0 -1
  386. package/dist/tests/utilities/testEnv.js.map +0 -1
  387. package/src/logging.ts +0 -60
  388. package/src/middleware/logging.ts +0 -90
  389. package/tests/utilities/mocks/events.ts +0 -122
  390. package/tests/utilities/mocks/fetch.ts +0 -10
  391. package/tests/utilities/structures/licenses.ts +0 -18
  392. /package/dist/src/{db → docIds}/conversions.d.ts +0 -0
  393. /package/dist/src/{db → docIds}/conversions.js +0 -0
  394. /package/dist/src/{newid.d.ts → docIds/newid.d.ts} +0 -0
  395. /package/dist/src/{newid.js → docIds/newid.js} +0 -0
  396. /package/dist/tests/{logging.d.ts → core/logging.d.ts} +0 -0
  397. /package/dist/tests/{logging.js → core/logging.js} +0 -0
  398. /package/dist/tests/{utilities → core/utilities}/jestUtils.d.ts +0 -0
  399. /package/dist/tests/{utilities → core/utilities}/jestUtils.js +0 -0
  400. /package/dist/tests/{utilities → core/utilities}/mocks/date.d.ts +0 -0
  401. /package/dist/tests/{utilities → core/utilities}/mocks/date.js +0 -0
  402. /package/dist/tests/{utilities → core/utilities}/mocks/events.d.ts +0 -0
  403. /package/dist/tests/{utilities → core/utilities}/mocks/posthog.d.ts +0 -0
  404. /package/dist/tests/{utilities → core/utilities}/mocks/posthog.js +0 -0
  405. /package/dist/tests/{utilities → core/utilities}/structures/accounts.d.ts +0 -0
  406. /package/dist/tests/{utilities → core/utilities}/structures/apps.d.ts +0 -0
  407. /package/dist/tests/{utilities → core/utilities}/structures/common.d.ts +0 -0
  408. /package/dist/tests/{utilities → core/utilities}/structures/common.js +0 -0
  409. /package/dist/tests/{utilities → core/utilities}/structures/db.d.ts +0 -0
  410. /package/dist/tests/{utilities → core/utilities}/structures/koa.d.ts +0 -0
  411. /package/dist/tests/{utilities → core/utilities}/structures/koa.js +0 -0
  412. /package/dist/tests/{utilities → core/utilities}/structures/plugins.d.ts +0 -0
  413. /package/dist/tests/{utilities → core/utilities}/structures/plugins.js +0 -0
  414. /package/dist/tests/{utilities → core/utilities}/structures/shared.d.ts +0 -0
  415. /package/dist/tests/{utilities → core/utilities}/structures/shared.js +0 -0
  416. /package/dist/tests/{utilities → core/utilities}/structures/sso.d.ts +0 -0
  417. /package/dist/tests/{utilities → core/utilities}/structures/sso.js +0 -0
  418. /package/dist/tests/{utilities → core/utilities}/structures/tenants.d.ts +0 -0
  419. /package/dist/tests/{utilities → core/utilities}/structures/userGroups.d.ts +0 -0
  420. /package/dist/tests/{utilities → core/utilities}/structures/userGroups.js +0 -0
  421. /package/dist/tests/{utilities → core/utilities}/structures/users.d.ts +0 -0
  422. /package/dist/tests/{utilities → core/utilities}/structures/users.js +0 -0
  423. /package/dist/tests/{utilities → core/utilities}/testContainerUtils.d.ts +0 -0
  424. /package/dist/tests/{utilities → core/utilities}/testContainerUtils.js +0 -0
  425. /package/src/{db → docIds}/conversions.ts +0 -0
  426. /package/src/{newid.ts → docIds/newid.ts} +0 -0
  427. /package/tests/{logging.ts → core/logging.ts} +0 -0
  428. /package/tests/{utilities → core/utilities}/jestUtils.ts +0 -0
  429. /package/tests/{utilities → core/utilities}/mocks/date.ts +0 -0
  430. /package/tests/{utilities → core/utilities}/mocks/posthog.ts +0 -0
  431. /package/tests/{utilities → core/utilities}/structures/common.ts +0 -0
  432. /package/tests/{utilities → core/utilities}/structures/koa.ts +0 -0
  433. /package/tests/{utilities → core/utilities}/structures/plugins.ts +0 -0
  434. /package/tests/{utilities → core/utilities}/structures/shared.ts +0 -0
  435. /package/tests/{utilities → core/utilities}/structures/sso.ts +0 -0
  436. /package/tests/{utilities → core/utilities}/structures/userGroups.ts +0 -0
  437. /package/tests/{utilities → core/utilities}/structures/users.ts +0 -0
  438. /package/tests/{utilities → core/utilities}/testContainerUtils.ts +0 -0
package/src/users.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  import {
2
- ViewName,
3
- getUsersByAppParams,
4
- getProdAppID,
2
+ directCouchFind,
3
+ DocumentType,
5
4
  generateAppUserID,
5
+ getGlobalUserParams,
6
+ getProdAppID,
7
+ getUsersByAppParams,
8
+ pagination,
6
9
  queryGlobalView,
7
- UNICODE_MAX,
8
- DocumentType,
10
+ queryGlobalViewRaw,
9
11
  SEPARATOR,
10
- directCouchFind,
12
+ UNICODE_MAX,
13
+ ViewName,
11
14
  } from "./db"
12
- import { BulkDocsResponse, User } from "@budibase/types"
15
+ import { BulkDocsResponse, SearchUsersRequest, User } from "@budibase/types"
13
16
  import { getGlobalDB } from "./context"
14
17
  import * as context from "./context"
15
18
 
@@ -199,3 +202,49 @@ export const searchGlobalUsersByEmail = async (
199
202
  }
200
203
  return users
201
204
  }
205
+
206
+ const PAGE_LIMIT = 8
207
+ export const paginatedUsers = async ({
208
+ page,
209
+ email,
210
+ appId,
211
+ }: SearchUsersRequest = {}) => {
212
+ const db = getGlobalDB()
213
+ // get one extra document, to have the next page
214
+ const opts: any = {
215
+ include_docs: true,
216
+ limit: PAGE_LIMIT + 1,
217
+ }
218
+ // add a startkey if the page was specified (anchor)
219
+ if (page) {
220
+ opts.startkey = page
221
+ }
222
+ // property specifies what to use for the page/anchor
223
+ let userList: User[],
224
+ property = "_id",
225
+ getKey
226
+ if (appId) {
227
+ userList = await searchGlobalUsersByApp(appId, opts)
228
+ getKey = (doc: any) => getGlobalUserByAppPage(appId, doc)
229
+ } else if (email) {
230
+ userList = await searchGlobalUsersByEmail(email, opts)
231
+ property = "email"
232
+ } else {
233
+ // no search, query allDocs
234
+ const response = await db.allDocs(getGlobalUserParams(null, opts))
235
+ userList = response.rows.map((row: any) => row.doc)
236
+ }
237
+ return pagination(userList, PAGE_LIMIT, {
238
+ paginate: true,
239
+ property,
240
+ getKey,
241
+ })
242
+ }
243
+
244
+ export async function getUserCount() {
245
+ const response = await queryGlobalViewRaw(ViewName.USER_BY_EMAIL, {
246
+ limit: 0, // to be as fast as possible - we just want the total rows count
247
+ include_docs: false,
248
+ })
249
+ return response.total_rows
250
+ }
@@ -1,5 +1,5 @@
1
1
  import env from "../environment"
2
- export * from "../newid"
2
+ export * from "../docIds/newid"
3
3
  const bcrypt = env.JS_BCRYPT ? require("bcryptjs") : require("bcrypt")
4
4
 
5
5
  const SALT_ROUNDS = env.SALT_ROUNDS || 10
@@ -1,2 +1,3 @@
1
1
  export * from "./hashing"
2
2
  export * from "./utils"
3
+ export * from "./stringUtils"
@@ -0,0 +1,8 @@
1
+ export function validEmail(value: string) {
2
+ return (
3
+ value &&
4
+ !!value.match(
5
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
6
+ )
7
+ )
8
+ }
@@ -1,4 +1,5 @@
1
- import { structures, DBTestConfiguration } from "../../../tests"
1
+ import { structures } from "../../../tests"
2
+ import { DBTestConfiguration } from "../../../tests/extra"
2
3
  import * as utils from "../../utils"
3
4
  import * as db from "../../db"
4
5
  import { Header } from "../../constants"
@@ -46,8 +46,9 @@ export async function resolveAppUrl(ctx: Ctx) {
46
46
  }
47
47
 
48
48
  // search prod apps for a url that matches
49
- const apps: App[] = await context.doInTenant(tenantId, () =>
50
- getAllApps({ dev: false })
49
+ const apps: App[] = await context.doInTenant(
50
+ tenantId,
51
+ () => getAllApps({ dev: false }) as Promise<App[]>
51
52
  )
52
53
  const app = apps.filter(
53
54
  a => a.url && a.url.toLowerCase() === possibleAppUrl
@@ -221,27 +222,6 @@ export function isClient(ctx: Ctx) {
221
222
  return ctx.headers[Header.TYPE] === "client"
222
223
  }
223
224
 
224
- async function getBuilders() {
225
- const builders = await queryGlobalView(ViewName.USER_BY_BUILDERS, {
226
- include_docs: false,
227
- })
228
-
229
- if (!builders) {
230
- return []
231
- }
232
-
233
- if (Array.isArray(builders)) {
234
- return builders
235
- } else {
236
- return [builders]
237
- }
238
- }
239
-
240
- export async function getBuildersCount() {
241
- const builders = await getBuilders()
242
- return builders.length
243
- }
244
-
245
225
  export function timeout(timeMs: number) {
246
226
  return new Promise(resolve => setTimeout(resolve, timeMs))
247
227
  }
@@ -1,9 +1,6 @@
1
1
  export * as mocks from "./mocks"
2
2
  export * as structures from "./structures"
3
3
  export { generator } from "./structures"
4
- export * as testEnv from "./testEnv"
5
4
  export * as testContainerUtils from "./testContainerUtils"
6
-
5
+ export * as utils from "./utils"
7
6
  export * from "./jestUtils"
8
-
9
- export { default as DBTestConfiguration } from "./DBTestConfiguration"
@@ -0,0 +1,3 @@
1
+ jest.mock("../../../../src/logging/alerts")
2
+ import * as _alerts from "../../../../src/logging/alerts"
3
+ export const alerts = jest.mocked(_alerts)
@@ -0,0 +1,133 @@
1
+ import * as events from "../../../../src/events"
2
+
3
+ beforeAll(async () => {
4
+ const processors = await import("../../../../src/events/processors")
5
+ const events = await import("../../../../src/events")
6
+ jest.spyOn(processors.analyticsProcessor, "processEvent")
7
+
8
+ jest.spyOn(events.identification, "identifyTenantGroup")
9
+ jest.spyOn(events.identification, "identifyUser")
10
+
11
+ jest.spyOn(events.backfill, "appSucceeded")
12
+ jest.spyOn(events.backfill, "tenantSucceeded")
13
+
14
+ jest.spyOn(events.account, "created")
15
+ jest.spyOn(events.account, "deleted")
16
+ jest.spyOn(events.account, "verified")
17
+
18
+ jest.spyOn(events.app, "created")
19
+ jest.spyOn(events.app, "updated")
20
+ jest.spyOn(events.app, "deleted")
21
+ jest.spyOn(events.app, "published")
22
+ jest.spyOn(events.app, "unpublished")
23
+ jest.spyOn(events.app, "templateImported")
24
+ jest.spyOn(events.app, "fileImported")
25
+ jest.spyOn(events.app, "versionUpdated")
26
+ jest.spyOn(events.app, "versionReverted")
27
+ jest.spyOn(events.app, "reverted")
28
+ jest.spyOn(events.app, "exported")
29
+
30
+ jest.spyOn(events.auth, "login")
31
+ jest.spyOn(events.auth, "logout")
32
+ jest.spyOn(events.auth, "SSOCreated")
33
+ jest.spyOn(events.auth, "SSOUpdated")
34
+ jest.spyOn(events.auth, "SSOActivated")
35
+ jest.spyOn(events.auth, "SSODeactivated")
36
+
37
+ jest.spyOn(events.automation, "created")
38
+ jest.spyOn(events.automation, "deleted")
39
+ jest.spyOn(events.automation, "tested")
40
+ jest.spyOn(events.automation, "stepCreated")
41
+ jest.spyOn(events.automation, "stepDeleted")
42
+ jest.spyOn(events.automation, "triggerUpdated")
43
+
44
+ jest.spyOn(events.datasource, "created")
45
+ jest.spyOn(events.datasource, "updated")
46
+ jest.spyOn(events.datasource, "deleted")
47
+
48
+ jest.spyOn(events.email, "SMTPCreated")
49
+ jest.spyOn(events.email, "SMTPUpdated")
50
+
51
+ jest.spyOn(events.layout, "created")
52
+ jest.spyOn(events.layout, "deleted")
53
+
54
+ jest.spyOn(events.org, "nameUpdated")
55
+ jest.spyOn(events.org, "logoUpdated")
56
+ jest.spyOn(events.org, "platformURLUpdated")
57
+ jest.spyOn(events.org, "analyticsOptOut")
58
+
59
+ jest.spyOn(events.installation, "versionChecked")
60
+
61
+ jest.spyOn(events.query, "created")
62
+ jest.spyOn(events.query, "updated")
63
+ jest.spyOn(events.query, "deleted")
64
+ jest.spyOn(events.query, "imported")
65
+ jest.spyOn(events.query, "previewed")
66
+
67
+ jest.spyOn(events.role, "created")
68
+ jest.spyOn(events.role, "updated")
69
+ jest.spyOn(events.role, "deleted")
70
+ jest.spyOn(events.role, "assigned")
71
+ jest.spyOn(events.role, "unassigned")
72
+
73
+ jest.spyOn(events.rows, "imported")
74
+ jest.spyOn(events.rows, "created")
75
+
76
+ jest.spyOn(events.screen, "created")
77
+ jest.spyOn(events.screen, "deleted")
78
+
79
+ jest.spyOn(events.user, "created")
80
+ jest.spyOn(events.user, "updated")
81
+ jest.spyOn(events.user, "deleted")
82
+ jest.spyOn(events.user, "permissionAdminAssigned")
83
+ jest.spyOn(events.user, "permissionAdminRemoved")
84
+ jest.spyOn(events.user, "permissionBuilderAssigned")
85
+ jest.spyOn(events.user, "permissionBuilderRemoved")
86
+ jest.spyOn(events.user, "invited")
87
+ jest.spyOn(events.user, "inviteAccepted")
88
+ jest.spyOn(events.user, "passwordForceReset")
89
+ jest.spyOn(events.user, "passwordUpdated")
90
+ jest.spyOn(events.user, "passwordResetRequested")
91
+ jest.spyOn(events.user, "passwordReset")
92
+
93
+ jest.spyOn(events.group, "created")
94
+ jest.spyOn(events.group, "updated")
95
+ jest.spyOn(events.group, "deleted")
96
+ jest.spyOn(events.group, "usersAdded")
97
+ jest.spyOn(events.group, "usersDeleted")
98
+ jest.spyOn(events.group, "createdOnboarding")
99
+ jest.spyOn(events.group, "permissionsEdited")
100
+
101
+ jest.spyOn(events.serve, "servedBuilder")
102
+ jest.spyOn(events.serve, "servedApp")
103
+ jest.spyOn(events.serve, "servedAppPreview")
104
+
105
+ jest.spyOn(events.table, "created")
106
+ jest.spyOn(events.table, "updated")
107
+ jest.spyOn(events.table, "deleted")
108
+ jest.spyOn(events.table, "exported")
109
+ jest.spyOn(events.table, "imported")
110
+
111
+ jest.spyOn(events.view, "created")
112
+ jest.spyOn(events.view, "updated")
113
+ jest.spyOn(events.view, "deleted")
114
+ jest.spyOn(events.view, "exported")
115
+ jest.spyOn(events.view, "filterCreated")
116
+ jest.spyOn(events.view, "filterUpdated")
117
+ jest.spyOn(events.view, "filterDeleted")
118
+ jest.spyOn(events.view, "calculationCreated")
119
+ jest.spyOn(events.view, "calculationUpdated")
120
+ jest.spyOn(events.view, "calculationDeleted")
121
+
122
+ jest.spyOn(events.plugin, "init")
123
+ jest.spyOn(events.plugin, "imported")
124
+ jest.spyOn(events.plugin, "deleted")
125
+
126
+ jest.spyOn(events.license, "planChanged")
127
+ jest.spyOn(events.license, "activated")
128
+ jest.spyOn(events.license, "checkoutOpened")
129
+ jest.spyOn(events.license, "checkoutSuccess")
130
+ jest.spyOn(events.license, "portalOpened")
131
+ jest.spyOn(events.license, "paymentFailed")
132
+ jest.spyOn(events.license, "paymentRecovered")
133
+ })
@@ -0,0 +1,17 @@
1
+ const mockFetch = jest.fn((url: any, opts: any) => {
2
+ const fetch = jest.requireActual("node-fetch")
3
+ const env = jest.requireActual("../../../../src/environment").default
4
+ if (url.includes(env.COUCH_DB_URL) || url.includes("raw.github")) {
5
+ return fetch(url, opts)
6
+ }
7
+ return undefined
8
+ })
9
+
10
+ const enable = () => {
11
+ jest.mock("node-fetch", () => mockFetch)
12
+ }
13
+
14
+ export default {
15
+ ...mockFetch,
16
+ enable,
17
+ }
@@ -1,9 +1,10 @@
1
- jest.mock("../../../src/accounts")
2
- import * as _accounts from "../../../src/accounts"
1
+ jest.mock("../../../../src/accounts")
2
+ import * as _accounts from "../../../../src/accounts"
3
3
  export const accounts = jest.mocked(_accounts)
4
4
 
5
5
  export * as date from "./date"
6
6
  export * as licenses from "./licenses"
7
7
  export { default as fetch } from "./fetch"
8
- import "./posthog"
8
+ export * from "./alerts"
9
9
  import "./events"
10
+ import "./posthog"
@@ -86,6 +86,10 @@ export const useAuditLogs = () => {
86
86
  return useFeature(Feature.AUDIT_LOGS)
87
87
  }
88
88
 
89
+ export const useScimIntegration = () => {
90
+ return useFeature(Feature.SCIM)
91
+ }
92
+
89
93
  // QUOTAS
90
94
 
91
95
  export const setAutomationLogsQuota = (value: number) => {
@@ -0,0 +1,20 @@
1
+ import Chance from "chance"
2
+
3
+ export default class CustomChance extends Chance {
4
+ arrayOf<T>(
5
+ generateFn: () => T,
6
+ opts: { min?: number; max?: number } = {}
7
+ ): T[] {
8
+ const itemCount = this.integer({
9
+ min: opts.min != null ? opts.min : 1,
10
+ max: opts.max != null ? opts.max : 50,
11
+ })
12
+
13
+ const items = []
14
+ for (let i = 0; i < itemCount; i++) {
15
+ items.push(generateFn())
16
+ }
17
+
18
+ return items
19
+ }
20
+ }
@@ -1,5 +1,5 @@
1
- import { generator, uuid } from "."
2
- import * as db from "../../../src/db/utils"
1
+ import { generator, uuid, quotas } from "."
2
+ import { generateGlobalUserID } from "../../../../src/docIds"
3
3
  import {
4
4
  Account,
5
5
  AccountSSOProvider,
@@ -28,6 +28,7 @@ export const account = (): Account => {
28
28
  name: generator.name(),
29
29
  size: "10+",
30
30
  profession: "Software Engineer",
31
+ quotaUsage: quotas.usage(),
31
32
  }
32
33
  }
33
34
 
@@ -39,7 +40,7 @@ export const cloudAccount = (): CloudAccount => {
39
40
  return {
40
41
  ...account(),
41
42
  hosting: Hosting.CLOUD,
42
- budibaseUserId: db.generateGlobalUserID(),
43
+ budibaseUserId: generateGlobalUserID(),
43
44
  }
44
45
  }
45
46
 
@@ -1,6 +1,6 @@
1
1
  import { generator } from "."
2
2
  import { App } from "@budibase/types"
3
- import { DEFAULT_TENANT_ID, DocumentType } from "../../../src/constants"
3
+ import { DEFAULT_TENANT_ID, DocumentType } from "../../../../src/constants"
4
4
 
5
5
  export function app(id: string): App {
6
6
  return {
@@ -1,5 +1,5 @@
1
1
  import { structures } from ".."
2
- import { newid } from "../../../src/newid"
2
+ import { newid } from "../../../../src/docIds/newid"
3
3
 
4
4
  export function id() {
5
5
  return `db_${newid()}`
@@ -1,2 +1,2 @@
1
- import Chance from "chance"
1
+ import Chance from "./Chance"
2
2
  export const generator = new Chance()
@@ -10,3 +10,5 @@ export * as tenant from "./tenants"
10
10
  export * as users from "./users"
11
11
  export * as userGroups from "./userGroups"
12
12
  export { generator } from "./generator"
13
+ export * as scim from "./scim"
14
+ export * as quotas from "./quotas"
@@ -0,0 +1,145 @@
1
+ import {
2
+ Billing,
3
+ Customer,
4
+ Feature,
5
+ License,
6
+ PlanModel,
7
+ PlanType,
8
+ PriceDuration,
9
+ PurchasedPlan,
10
+ PurchasedPrice,
11
+ Quotas,
12
+ Subscription,
13
+ } from "@budibase/types"
14
+
15
+ export function price(): PurchasedPrice {
16
+ return {
17
+ amount: 10000,
18
+ amountMonthly: 10000,
19
+ currency: "usd",
20
+ duration: PriceDuration.MONTHLY,
21
+ priceId: "price_123",
22
+ dayPasses: undefined,
23
+ isPerUser: true,
24
+ }
25
+ }
26
+
27
+ export const plan = (type: PlanType = PlanType.FREE): PurchasedPlan => {
28
+ return {
29
+ type,
30
+ usesInvoicing: false,
31
+ model: PlanModel.PER_USER,
32
+ price: type !== PlanType.FREE ? price() : undefined,
33
+ }
34
+ }
35
+
36
+ export function quotas(): Quotas {
37
+ return {
38
+ usage: {
39
+ monthly: {
40
+ queries: {
41
+ name: "Queries",
42
+ value: 1,
43
+ triggers: [],
44
+ },
45
+ automations: {
46
+ name: "Queries",
47
+ value: 1,
48
+ triggers: [],
49
+ },
50
+ dayPasses: {
51
+ name: "Queries",
52
+ value: 1,
53
+ triggers: [],
54
+ },
55
+ },
56
+ static: {
57
+ rows: {
58
+ name: "Rows",
59
+ value: 1,
60
+ triggers: [],
61
+ },
62
+ apps: {
63
+ name: "Apps",
64
+ value: 1,
65
+ triggers: [],
66
+ },
67
+ users: {
68
+ name: "Users",
69
+ value: 1,
70
+ triggers: [],
71
+ },
72
+ userGroups: {
73
+ name: "User Groups",
74
+ value: 1,
75
+ triggers: [],
76
+ },
77
+ plugins: {
78
+ name: "Plugins",
79
+ value: 1,
80
+ triggers: [],
81
+ },
82
+ },
83
+ },
84
+ constant: {
85
+ automationLogRetentionDays: {
86
+ name: "Automation Logs",
87
+ value: 1,
88
+ triggers: [],
89
+ },
90
+ appBackupRetentionDays: {
91
+ name: "Backups",
92
+ value: 1,
93
+ triggers: [],
94
+ },
95
+ },
96
+ }
97
+ }
98
+
99
+ export function billing(
100
+ opts: { customer?: Customer; subscription?: Subscription } = {}
101
+ ): Billing {
102
+ return {
103
+ customer: opts.customer || customer(),
104
+ subscription: opts.subscription || subscription(),
105
+ }
106
+ }
107
+
108
+ export function customer(): Customer {
109
+ return {
110
+ balance: 0,
111
+ currency: "usd",
112
+ }
113
+ }
114
+
115
+ export function subscription(): Subscription {
116
+ return {
117
+ amount: 10000,
118
+ cancelAt: undefined,
119
+ currency: "usd",
120
+ currentPeriodEnd: 0,
121
+ currentPeriodStart: 0,
122
+ downgradeAt: 0,
123
+ duration: PriceDuration.MONTHLY,
124
+ pastDueAt: undefined,
125
+ quantity: 0,
126
+ status: "active",
127
+ }
128
+ }
129
+
130
+ export const license = (
131
+ opts: {
132
+ quotas?: Quotas
133
+ plan?: PurchasedPlan
134
+ planType?: PlanType
135
+ features?: Feature[]
136
+ billing?: Billing
137
+ } = {}
138
+ ): License => {
139
+ return {
140
+ features: opts.features || [],
141
+ quotas: opts.quotas || quotas(),
142
+ plan: opts.plan || plan(opts.planType),
143
+ billing: opts.billing || billing(),
144
+ }
145
+ }
@@ -0,0 +1,67 @@
1
+ import { MonthlyQuotaName, QuotaUsage } from "@budibase/types"
2
+
3
+ export const usage = (): QuotaUsage => {
4
+ return {
5
+ _id: "usage_quota",
6
+ quotaReset: new Date().toISOString(),
7
+ apps: {
8
+ app_1: {
9
+ // @ts-ignore - the apps definition doesn't match up to actual usage
10
+ usageQuota: {
11
+ rows: 0,
12
+ },
13
+ },
14
+ },
15
+ monthly: {
16
+ "01-2023": {
17
+ automations: 0,
18
+ dayPasses: 0,
19
+ queries: 0,
20
+ triggers: {},
21
+ breakdown: {
22
+ rowQueries: {
23
+ parent: MonthlyQuotaName.QUERIES,
24
+ values: {
25
+ row_1: 0,
26
+ row_2: 0,
27
+ },
28
+ },
29
+ datasourceQueries: {
30
+ parent: MonthlyQuotaName.QUERIES,
31
+ values: {
32
+ ds_1: 0,
33
+ ds_2: 0,
34
+ },
35
+ },
36
+ automations: {
37
+ parent: MonthlyQuotaName.AUTOMATIONS,
38
+ values: {
39
+ auto_1: 0,
40
+ auto_2: 0,
41
+ },
42
+ },
43
+ },
44
+ },
45
+ "02-2023": {
46
+ automations: 0,
47
+ dayPasses: 0,
48
+ queries: 0,
49
+ triggers: {},
50
+ },
51
+ current: {
52
+ automations: 0,
53
+ dayPasses: 0,
54
+ queries: 0,
55
+ triggers: {},
56
+ },
57
+ },
58
+ usageQuota: {
59
+ apps: 0,
60
+ plugins: 0,
61
+ users: 0,
62
+ userGroups: 0,
63
+ rows: 0,
64
+ triggers: {},
65
+ },
66
+ }
67
+ }