@budibase/server 2.0.39 → 2.0.40-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/__mocks__/node-fetch.ts +12 -2
  3. package/builder/assets/backups-default.8c011f1b.png +0 -0
  4. package/builder/assets/{index.e0ddd30b.css → index.442de33f.css} +2 -2
  5. package/builder/assets/{index.b20dee52.js → index.b09e13ca.js} +340 -332
  6. package/builder/index.html +2 -2
  7. package/coverage/clover.xml +1125 -1250
  8. package/coverage/coverage-final.json +73 -77
  9. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  10. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +79 -67
  12. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/dev.js.html +21 -21
  14. package/coverage/lcov-report/api/controllers/index.html +17 -47
  15. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  16. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  18. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  19. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/validation.js.html +4 -4
  22. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  24. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/internal.js.html +13 -13
  27. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
  30. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
  32. package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
  33. package/coverage/lcov-report/api/controllers/table/index.html +16 -16
  34. package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
  35. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  36. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/index.js.html +3 -3
  40. package/coverage/lcov-report/api/controllers/view/utils.js.html +13 -13
  41. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -8
  42. package/coverage/lcov-report/api/index.html +1 -1
  43. package/coverage/lcov-report/api/index.js.html +30 -30
  44. package/coverage/lcov-report/api/routes/analytics.js.html +7 -7
  45. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  46. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  47. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  48. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  49. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  50. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  52. package/coverage/lcov-report/api/routes/index.html +5 -35
  53. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  54. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  55. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  56. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  57. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  58. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  59. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  60. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  61. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  62. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  64. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  65. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  66. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  67. package/coverage/lcov-report/api/routes/utils/validators.js.html +45 -45
  68. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  69. package/coverage/lcov-report/automations/actions.js.html +1 -1
  70. package/coverage/lcov-report/automations/automationUtils.js.html +6 -6
  71. package/coverage/lcov-report/automations/bullboard.js.html +24 -84
  72. package/coverage/lcov-report/automations/index.html +21 -21
  73. package/coverage/lcov-report/automations/index.js.html +9 -9
  74. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  75. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  76. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  77. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  78. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/index.html +15 -15
  81. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -3
  89. package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
  90. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  91. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  92. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  93. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  94. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggers.js.html +49 -49
  100. package/coverage/lcov-report/constants/index.html +5 -5
  101. package/coverage/lcov-report/constants/index.js.html +10 -28
  102. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  103. package/coverage/lcov-report/constants/screens.js.html +1 -1
  104. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  105. package/coverage/lcov-report/db/index.html +19 -19
  106. package/coverage/lcov-report/db/index.js.html +1 -1
  107. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
  108. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  109. package/coverage/lcov-report/db/linkedRows/index.js.html +28 -28
  110. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +15 -15
  111. package/coverage/lcov-report/db/newid.js.html +2 -2
  112. package/coverage/lcov-report/db/utils.js.html +37 -316
  113. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  114. package/coverage/lcov-report/events/index.html +1 -1
  115. package/coverage/lcov-report/events/index.js.html +3 -3
  116. package/coverage/lcov-report/events/utils.js.html +9 -9
  117. package/coverage/lcov-report/index.html +88 -88
  118. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  119. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  120. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  121. package/coverage/lcov-report/middleware/builder.js.html +19 -19
  122. package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
  123. package/coverage/lcov-report/middleware/index.html +1 -1
  124. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  125. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  126. package/coverage/lcov-report/middleware/resourceId.js.html +28 -28
  127. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  128. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  129. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  130. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  131. package/coverage/lcov-report/utilities/csvParser.js.html +15 -12
  132. package/coverage/lcov-report/utilities/global.js.html +31 -31
  133. package/coverage/lcov-report/utilities/index.html +28 -28
  134. package/coverage/lcov-report/utilities/index.js.html +8 -8
  135. package/coverage/lcov-report/utilities/plugins.js.html +1 -1
  136. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
  137. package/coverage/lcov-report/utilities/queue/index.html +21 -21
  138. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  139. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  140. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  141. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +72 -57
  142. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
  143. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  144. package/coverage/lcov-report/utilities/security.js.html +2 -2
  145. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  146. package/coverage/lcov-report/utilities/usageQuota/index.html +14 -14
  147. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +23 -11
  148. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  149. package/coverage/lcov-report/utilities/users.js.html +1 -1
  150. package/coverage/lcov-report/utilities/workerRequests.js.html +46 -46
  151. package/coverage/lcov.info +1691 -1899
  152. package/dist/api/controllers/application.js +4 -7
  153. package/dist/api/controllers/backup.js +19 -13
  154. package/dist/api/controllers/cloud.js +38 -35
  155. package/dist/api/controllers/deploy/index.js +11 -2
  156. package/dist/api/controllers/dev.js +1 -1
  157. package/dist/api/controllers/query/index.js +7 -2
  158. package/dist/api/controllers/row/index.js +40 -66
  159. package/dist/api/controllers/row/internal.js +1 -1
  160. package/dist/api/controllers/static/index.js +3 -2
  161. package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
  162. package/dist/api/controllers/static/templates/preview.hbs +10 -0
  163. package/dist/api/controllers/table/bulkFormula.js +4 -3
  164. package/dist/api/controllers/table/external.js +5 -4
  165. package/dist/api/controllers/table/index.js +4 -4
  166. package/dist/api/controllers/table/internal.js +10 -3
  167. package/dist/api/controllers/table/utils.js +7 -49
  168. package/dist/api/controllers/view/index.js +2 -2
  169. package/dist/api/controllers/webhook.js +88 -89
  170. package/dist/api/routes/backup.js +34 -7
  171. package/dist/api/routes/index.js +9 -4
  172. package/dist/api/routes/utils/validators.js +2 -2
  173. package/dist/api/routes/webhook.js +39 -11
  174. package/dist/app.js +2 -68
  175. package/dist/automations/automationUtils.js +2 -2
  176. package/dist/automations/bullboard.js +12 -35
  177. package/dist/automations/index.js +4 -4
  178. package/dist/automations/steps/updateRow.js +2 -2
  179. package/dist/automations/triggers.js +6 -6
  180. package/dist/automations/utils.js +23 -49
  181. package/dist/constants/index.js +4 -8
  182. package/dist/db/utils.js +10 -75
  183. package/dist/index.js +1 -0
  184. package/dist/integrations/arangodb.js +2 -0
  185. package/dist/integrations/base/sqlTable.js +1 -0
  186. package/dist/integrations/elasticsearch.js +26 -2
  187. package/dist/integrations/mongodb.js +300 -11
  188. package/dist/integrations/rest.js +38 -5
  189. package/dist/migrations/functions/backfill/app/tables.js +5 -8
  190. package/dist/migrations/functions/{quotas1.js → syncQuotas.js} +3 -7
  191. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
  192. package/dist/migrations/functions/{pluginCount.js → usageQuotas/syncPlugins.js} +1 -3
  193. package/dist/migrations/functions/usageQuotas/syncRows.js +9 -5
  194. package/dist/migrations/index.js +10 -38
  195. package/dist/package.json +14 -14
  196. package/dist/sdk/app/automations/index.js +29 -0
  197. package/dist/sdk/app/automations/webhook.js +54 -0
  198. package/dist/sdk/app/backups/constants.js +5 -0
  199. package/dist/sdk/app/backups/exports.js +172 -0
  200. package/dist/sdk/app/backups/imports.js +190 -0
  201. package/dist/sdk/app/backups/index.js +29 -0
  202. package/dist/sdk/app/backups/statistics.js +73 -0
  203. package/dist/sdk/app/tables/index.js +61 -0
  204. package/dist/sdk/index.js +17 -0
  205. package/dist/startup.js +152 -0
  206. package/dist/tests/utilities/TestConfiguration.js +12 -2
  207. package/dist/threads/automation.js +12 -17
  208. package/dist/tsconfig.build.tsbuildinfo +1 -1
  209. package/dist/utilities/csvParser.js +1 -0
  210. package/dist/utilities/fileSystem/index.js +3 -95
  211. package/dist/utilities/fileSystem/utilities.js +2 -1
  212. package/dist/utilities/rowProcessor/index.js +5 -0
  213. package/dist/utilities/usageQuota/rows.js +6 -4
  214. package/package.json +15 -15
  215. package/specs/openapi.json +3 -0
  216. package/specs/openapi.yaml +3 -0
  217. package/src/api/controllers/application.ts +5 -12
  218. package/src/api/controllers/{backup.js → backup.ts} +7 -7
  219. package/src/api/controllers/cloud.js +44 -40
  220. package/src/api/controllers/deploy/index.ts +20 -8
  221. package/src/api/controllers/dev.js +1 -1
  222. package/src/api/controllers/query/index.ts +8 -2
  223. package/src/api/controllers/row/index.ts +50 -65
  224. package/src/api/controllers/row/internal.js +1 -1
  225. package/src/api/controllers/static/index.ts +4 -2
  226. package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
  227. package/src/api/controllers/static/templates/preview.hbs +10 -0
  228. package/src/api/controllers/table/bulkFormula.js +4 -3
  229. package/src/api/controllers/table/external.js +4 -4
  230. package/src/api/controllers/table/index.js +4 -4
  231. package/src/api/controllers/table/internal.ts +8 -9
  232. package/src/api/controllers/table/utils.ts +4 -53
  233. package/src/api/controllers/view/index.js +2 -2
  234. package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
  235. package/src/api/routes/backup.ts +10 -0
  236. package/src/api/routes/index.ts +11 -5
  237. package/src/api/routes/tests/backup.spec.js +1 -1
  238. package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
  239. package/src/api/routes/tests/row.spec.js +22 -27
  240. package/src/api/routes/utils/validators.js +2 -2
  241. package/src/api/routes/{webhook.js → webhook.ts} +7 -6
  242. package/src/app.ts +3 -91
  243. package/src/automations/automationUtils.js +2 -2
  244. package/src/automations/bullboard.js +14 -34
  245. package/src/automations/index.js +4 -4
  246. package/src/automations/steps/updateRow.js +2 -2
  247. package/src/automations/tests/automation.spec.js +1 -6
  248. package/src/automations/triggers.js +6 -6
  249. package/src/automations/utils.ts +30 -32
  250. package/src/constants/index.js +4 -10
  251. package/src/db/utils.js +17 -110
  252. package/src/definitions/automations.ts +1 -18
  253. package/src/definitions/datasource.ts +1 -0
  254. package/src/index.ts +1 -0
  255. package/src/integrations/arangodb.ts +2 -0
  256. package/src/integrations/base/sqlTable.ts +1 -0
  257. package/src/integrations/elasticsearch.ts +32 -2
  258. package/src/integrations/mongodb.ts +290 -27
  259. package/src/integrations/rest.ts +17 -5
  260. package/src/integrations/tests/mongo.spec.ts +19 -19
  261. package/src/integrations/tests/rest.spec.ts +38 -22
  262. package/src/migrations/functions/backfill/app/tables.ts +7 -13
  263. package/src/migrations/functions/backfill/global.ts +1 -1
  264. package/src/migrations/functions/{quotas1.ts → syncQuotas.ts} +3 -8
  265. package/src/migrations/functions/tests/{quotas1.spec.js → syncQuotas.spec.js} +6 -5
  266. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
  267. package/src/migrations/functions/usageQuotas/syncApps.ts +0 -1
  268. package/src/migrations/functions/usageQuotas/syncPlugins.ts +10 -0
  269. package/src/migrations/functions/usageQuotas/syncRows.ts +15 -6
  270. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +9 -1
  271. package/src/migrations/index.ts +21 -45
  272. package/src/migrations/tests/index.spec.ts +0 -1
  273. package/src/sdk/app/automations/index.ts +5 -0
  274. package/src/sdk/app/automations/webhook.ts +43 -0
  275. package/src/sdk/app/backups/constants.ts +2 -0
  276. package/src/sdk/app/backups/exports.ts +171 -0
  277. package/src/sdk/app/backups/imports.ts +206 -0
  278. package/src/sdk/app/backups/index.ts +9 -0
  279. package/src/sdk/app/backups/statistics.ts +78 -0
  280. package/src/sdk/app/tables/index.ts +61 -0
  281. package/src/sdk/index.ts +15 -0
  282. package/src/startup.ts +138 -0
  283. package/src/tests/utilities/TestConfiguration.js +12 -2
  284. package/src/threads/automation.ts +20 -27
  285. package/src/utilities/csvParser.js +1 -0
  286. package/src/utilities/fileSystem/index.js +2 -119
  287. package/src/utilities/fileSystem/utilities.js +2 -0
  288. package/src/utilities/rowProcessor/index.js +5 -0
  289. package/src/utilities/usageQuota/rows.js +7 -3
  290. package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
  291. package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
  292. package/coverage/lcov-report/api/routes/backup.js.html +0 -115
  293. package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
  294. package/dist/automations/listeners.js +0 -102
  295. package/src/api/routes/backup.js +0 -10
  296. package/src/automations/listeners.ts +0 -78
  297. package/src/migrations/functions/pluginCount.ts +0 -12
@@ -6,13 +6,12 @@ import {
6
6
  } from "@budibase/types"
7
7
  import {
8
8
  MongoClient,
9
- ObjectID,
10
- FilterQuery,
11
- UpdateQuery,
12
- FindOneAndUpdateOption,
13
- UpdateOneOptions,
14
- UpdateManyOptions,
15
- CommonOptions,
9
+ ObjectId,
10
+ Filter,
11
+ UpdateFilter,
12
+ FindOneAndUpdateOptions,
13
+ UpdateOptions,
14
+ OperationOptions,
16
15
  } from "mongodb"
17
16
 
18
17
  interface MongoDBConfig {
@@ -57,6 +56,232 @@ const SCHEMA: Integration = {
57
56
  delete: {
58
57
  type: QueryType.JSON,
59
58
  },
59
+ aggregate: {
60
+ type: QueryType.JSON,
61
+ steps: [
62
+ {
63
+ key: "$addFields",
64
+ template: "{\n\t\n}",
65
+ },
66
+ {
67
+ key: "$bucket",
68
+ template: `{
69
+ "groupBy": "",
70
+ "boundaries": [],
71
+ "default": "",
72
+ "output": {}
73
+ }`,
74
+ },
75
+ {
76
+ key: "$bucketAuto",
77
+ template: `{
78
+ "groupBy": "",
79
+ "buckets": 1,
80
+ "output": {},
81
+ "granularity": "R5"
82
+ }`,
83
+ },
84
+ {
85
+ key: "$changeStream",
86
+ template: `{
87
+ "allChangesForCluster": true,
88
+ "fullDocument": "",
89
+ "fullDocumentBeforeChange": "",
90
+ "resumeAfter": 1,
91
+ "showExpandedEvents": true,
92
+ "startAfter": {},
93
+ "startAtOperationTime": ""
94
+ }`,
95
+ },
96
+ {
97
+ key: "$collStats",
98
+ template: `{
99
+ "latencyStats": { "histograms": true } },
100
+ "storageStats": { "scale": 1 } },
101
+ "count": {},
102
+ "queryExecStats": {}
103
+ }`,
104
+ },
105
+ {
106
+ key: "$count",
107
+ template: ``,
108
+ },
109
+ {
110
+ key: "$densify",
111
+ template: `{
112
+ "field": "",
113
+ "partitionByFields": [],
114
+ "range": {
115
+ "step": 1,
116
+ "unit": 1,
117
+ "bounds": "full"
118
+ }
119
+ }`,
120
+ },
121
+ {
122
+ key: "$documents",
123
+ template: `[]`,
124
+ },
125
+ {
126
+ key: "$facet",
127
+ template: `{\n\t\n}`,
128
+ },
129
+ {
130
+ key: "$fill",
131
+ template: `{
132
+ "partitionBy": "",
133
+ "partitionByFields": [],
134
+ "sortBy": {},
135
+ "output": {}
136
+ }`,
137
+ },
138
+ {
139
+ key: "$geoNear",
140
+ template: `{
141
+ "near": {
142
+ "type": "Point",
143
+ "coordinates": [
144
+ -73.98142, 40.71782
145
+ ]
146
+ },
147
+ "key": "location",
148
+ "distanceField": "dist.calculated",
149
+ "query": { "category": "Parks" }
150
+ }`,
151
+ },
152
+ {
153
+ key: "$graphLookup",
154
+ template: `{
155
+ "from": "",
156
+ "startWith": "",
157
+ "connectFromField": "",
158
+ "connectToField": "",
159
+ "as": "",
160
+ "maxDepth": 1,
161
+ "depthField": "",
162
+ "restrictSearchWithMatch": {}
163
+ }`,
164
+ },
165
+ {
166
+ key: "$group",
167
+ template: `{
168
+ "_id": ""
169
+ }`,
170
+ },
171
+ {
172
+ key: "$indexStats",
173
+ template: "{\n\t\n}",
174
+ },
175
+ {
176
+ key: "$limit",
177
+ template: `1`,
178
+ },
179
+ {
180
+ key: "$listLocalSessions",
181
+ template: `{\n\t\n}`,
182
+ },
183
+ {
184
+ key: "$listSessions",
185
+ template: `{\n\t\n}`,
186
+ },
187
+ {
188
+ key: "$lookup",
189
+ template: `{
190
+ "from": "",
191
+ "localField": "",
192
+ "foreignField": "",
193
+ "as": ""
194
+ }`,
195
+ },
196
+ {
197
+ key: "$match",
198
+ template: "{\n\t\n}",
199
+ },
200
+ {
201
+ key: "$merge",
202
+ template: `{
203
+ "into": {},
204
+ "on": "_id",
205
+ "whenMatched": "replace",
206
+ "whenNotMatched": "insert"
207
+ }`,
208
+ },
209
+ {
210
+ key: "$out",
211
+ template: `{
212
+ "db": "",
213
+ "coll": ""
214
+ }`,
215
+ },
216
+ {
217
+ key: "$planCacheStats",
218
+ template: "{\n\t\n}",
219
+ },
220
+ {
221
+ key: "$project",
222
+ template: "{\n\t\n}",
223
+ },
224
+ {
225
+ key: "$redact",
226
+ template: "",
227
+ },
228
+ {
229
+ key: "$replaceRoot",
230
+ template: `{ "newRoot": "" }`,
231
+ },
232
+ {
233
+ key: "$replaceWith",
234
+ template: ``,
235
+ },
236
+ {
237
+ key: "$sample",
238
+ template: `{ "size": 3 }`,
239
+ },
240
+ {
241
+ key: "$set",
242
+ template: "{\n\t\n}",
243
+ },
244
+ {
245
+ key: "$setWindowFields",
246
+ template: `{
247
+ "partitionBy": "",
248
+ "sortBy": {},
249
+ "output": {}
250
+ }`,
251
+ },
252
+ {
253
+ key: "$skip",
254
+ template: `1`,
255
+ },
256
+ {
257
+ key: "$sort",
258
+ template: "{\n\t\n}",
259
+ },
260
+ {
261
+ key: "$sortByCount",
262
+ template: "",
263
+ },
264
+ {
265
+ key: "$unionWith",
266
+ template: `{
267
+ "coll": "",
268
+ "pipeline": []
269
+ }`,
270
+ },
271
+ {
272
+ key: "$unset",
273
+ template: "",
274
+ },
275
+ {
276
+ key: "$unwind",
277
+ template: `{
278
+ "path": "",
279
+ "includeArrayIndex": "",
280
+ "preserveNullAndEmptyArrays": true
281
+ }`,
282
+ },
283
+ ],
284
+ },
60
285
  },
61
286
  extra: {
62
287
  collection: {
@@ -64,8 +289,8 @@ const SCHEMA: Integration = {
64
289
  type: DatasourceFieldType.STRING,
65
290
  required: true,
66
291
  },
67
- actionTypes: {
68
- displayName: "Action Types",
292
+ actionType: {
293
+ displayName: "Query Type",
69
294
  type: DatasourceFieldType.LIST,
70
295
  required: true,
71
296
  data: {
@@ -73,6 +298,7 @@ const SCHEMA: Integration = {
73
298
  create: ["insertOne", "insertMany"],
74
299
  update: ["updateOne", "updateMany"],
75
300
  delete: ["deleteOne", "deleteMany"],
301
+ aggregate: ["json", "pipeline"],
76
302
  },
77
303
  },
78
304
  },
@@ -104,7 +330,7 @@ class MongoIntegration implements IntegrationBase {
104
330
  ) {
105
331
  const id = json[field].match(/(?<=objectid\(['"]).*(?=['"]\))/gi)?.[0]
106
332
  if (id) {
107
- json[field] = ObjectID.createFromHexString(id)
333
+ json[field] = ObjectId.createFromHexString(id)
108
334
  }
109
335
  }
110
336
  }
@@ -168,7 +394,7 @@ class MongoIntegration implements IntegrationBase {
168
394
 
169
395
  // For mongodb we add an extra actionType to specify
170
396
  // which method we want to call on the collection
171
- switch (query.extra.actionTypes) {
397
+ switch (query.extra.actionType) {
172
398
  case "insertOne": {
173
399
  return await collection.insertOne(json)
174
400
  }
@@ -177,7 +403,7 @@ class MongoIntegration implements IntegrationBase {
177
403
  }
178
404
  default: {
179
405
  throw new Error(
180
- `actionType ${query.extra.actionTypes} does not exist on DB for create`
406
+ `actionType ${query.extra.actionType} does not exist on DB for create`
181
407
  )
182
408
  }
183
409
  }
@@ -196,7 +422,7 @@ class MongoIntegration implements IntegrationBase {
196
422
  const collection = db.collection(query.extra.collection)
197
423
  let json = this.createObjectIds(query.json)
198
424
 
199
- switch (query.extra.actionTypes) {
425
+ switch (query.extra.actionType) {
200
426
  case "find": {
201
427
  return await collection.find(json).toArray()
202
428
  }
@@ -208,9 +434,9 @@ class MongoIntegration implements IntegrationBase {
208
434
  json = this.parseQueryParams(query.json, "update")
209
435
  }
210
436
  let findAndUpdateJson = this.createObjectIds(json) as {
211
- filter: FilterQuery<any>
212
- update: UpdateQuery<any>
213
- options: FindOneAndUpdateOption<any>
437
+ filter: Filter<any>
438
+ update: UpdateFilter<any>
439
+ options: FindOneAndUpdateOptions
214
440
  }
215
441
  return await collection.findOneAndUpdate(
216
442
  findAndUpdateJson.filter,
@@ -226,7 +452,7 @@ class MongoIntegration implements IntegrationBase {
226
452
  }
227
453
  default: {
228
454
  throw new Error(
229
- `actionType ${query.extra.actionTypes} does not exist on DB for read`
455
+ `actionType ${query.extra.actionType} does not exist on DB for read`
230
456
  )
231
457
  }
232
458
  }
@@ -248,29 +474,29 @@ class MongoIntegration implements IntegrationBase {
248
474
  queryJson = this.parseQueryParams(queryJson, "update")
249
475
  }
250
476
  let json = this.createObjectIds(queryJson) as {
251
- filter: FilterQuery<any>
252
- update: UpdateQuery<any>
477
+ filter: Filter<any>
478
+ update: UpdateFilter<any>
253
479
  options: object
254
480
  }
255
481
 
256
- switch (query.extra.actionTypes) {
482
+ switch (query.extra.actionType) {
257
483
  case "updateOne": {
258
484
  return await collection.updateOne(
259
485
  json.filter,
260
486
  json.update,
261
- json.options as UpdateOneOptions
487
+ json.options as UpdateOptions
262
488
  )
263
489
  }
264
490
  case "updateMany": {
265
491
  return await collection.updateMany(
266
492
  json.filter,
267
493
  json.update,
268
- json.options as UpdateManyOptions
494
+ json.options as UpdateOptions
269
495
  )
270
496
  }
271
497
  default: {
272
498
  throw new Error(
273
- `actionType ${query.extra.actionTypes} does not exist on DB for update`
499
+ `actionType ${query.extra.actionType} does not exist on DB for update`
274
500
  )
275
501
  }
276
502
  }
@@ -292,8 +518,8 @@ class MongoIntegration implements IntegrationBase {
292
518
  queryJson = this.parseQueryParams(queryJson, "delete")
293
519
  }
294
520
  let json = this.createObjectIds(queryJson) as {
295
- filter: FilterQuery<any>
296
- options: CommonOptions
521
+ filter: Filter<any>
522
+ options: OperationOptions
297
523
  }
298
524
  if (!json.options) {
299
525
  json = {
@@ -302,7 +528,7 @@ class MongoIntegration implements IntegrationBase {
302
528
  }
303
529
  }
304
530
 
305
- switch (query.extra.actionTypes) {
531
+ switch (query.extra.actionType) {
306
532
  case "deleteOne": {
307
533
  return await collection.deleteOne(json.filter, json.options)
308
534
  }
@@ -311,7 +537,7 @@ class MongoIntegration implements IntegrationBase {
311
537
  }
312
538
  default: {
313
539
  throw new Error(
314
- `actionType ${query.extra.actionTypes} does not exist on DB for delete`
540
+ `actionType ${query.extra.actionType} does not exist on DB for delete`
315
541
  )
316
542
  }
317
543
  }
@@ -322,6 +548,43 @@ class MongoIntegration implements IntegrationBase {
322
548
  await this.client.close()
323
549
  }
324
550
  }
551
+
552
+ async aggregate(query: {
553
+ json: object
554
+ steps: any[]
555
+ extra: { [key: string]: string }
556
+ }) {
557
+ try {
558
+ await this.connect()
559
+ const db = this.client.db(this.config.db)
560
+ const collection = db.collection(query.extra.collection)
561
+ let response = []
562
+ if (query.extra?.actionType === "pipeline") {
563
+ for await (const doc of collection.aggregate(
564
+ query.steps.map(({ key, value }) => {
565
+ let temp: any = {}
566
+ temp[key] = JSON.parse(value.value)
567
+ return this.createObjectIds(temp)
568
+ })
569
+ )) {
570
+ response.push(doc)
571
+ }
572
+ } else {
573
+ const stages: Array<any> = query.json as Array<any>
574
+ for await (const doc of collection.aggregate(
575
+ stages ? this.createObjectIds(stages) : []
576
+ )) {
577
+ response.push(doc)
578
+ }
579
+ }
580
+ return response
581
+ } catch (err) {
582
+ console.error("Error writing to mongodb", err)
583
+ throw err
584
+ } finally {
585
+ await this.client.close()
586
+ }
587
+ }
325
588
  }
326
589
 
327
590
  export default {
@@ -14,6 +14,7 @@ import {
14
14
  BearerAuthConfig,
15
15
  } from "../definitions/datasource"
16
16
  import { get } from "lodash"
17
+ import * as https from "https"
17
18
  import qs from "querystring"
18
19
  const fetch = require("node-fetch")
19
20
  const { formatBytes } = require("../utilities")
@@ -76,11 +77,11 @@ const SCHEMA: Integration = {
76
77
  required: false,
77
78
  default: {},
78
79
  },
79
- legacyHttpParser: {
80
- display: "Legacy HTTP Support",
80
+ rejectUnauthorized: {
81
+ display: "Reject Unauthorized",
81
82
  type: DatasourceFieldType.BOOLEAN,
83
+ default: true,
82
84
  required: false,
83
- default: false,
84
85
  },
85
86
  },
86
87
  query: {
@@ -218,8 +219,12 @@ class RestIntegration implements IntegrationBase {
218
219
  }
219
220
  }
220
221
 
221
- // make sure the query string is fully encoded
222
- const main = `${path}?${qs.encode(qs.decode(queryString))}`
222
+ if (queryString) {
223
+ // make sure the query string is fully encoded
224
+ queryString = "?" + qs.encode(qs.decode(queryString))
225
+ }
226
+ const main = `${path}${queryString}`
227
+
223
228
  let complete = main
224
229
  if (this.config.url && !main.startsWith("http")) {
225
230
  complete = !this.config.url ? main : `${this.config.url}/${main}`
@@ -381,6 +386,13 @@ class RestIntegration implements IntegrationBase {
381
386
  paginationValues
382
387
  )
383
388
 
389
+ if (this.config.rejectUnauthorized == false) {
390
+ input.agent = new https.Agent({
391
+ rejectUnauthorized: false,
392
+ })
393
+ }
394
+
395
+ // Deprecated by rejectUnauthorized
384
396
  if (this.config.legacyHttpParser) {
385
397
  // https://github.com/nodejs/node/issues/43798
386
398
  input.extraHttpOptions = { insecureHTTPParser: true }
@@ -34,7 +34,7 @@ describe("MongoDB Integration", () => {
34
34
  await config.integration.create({
35
35
  index: indexName,
36
36
  json: body,
37
- extra: { collection: "testCollection", actionTypes: "insertOne" },
37
+ extra: { collection: "testCollection", actionType: "insertOne" },
38
38
  })
39
39
  expect(config.integration.client.insertOne).toHaveBeenCalledWith(body)
40
40
  })
@@ -44,7 +44,7 @@ describe("MongoDB Integration", () => {
44
44
  json: {
45
45
  address: "test",
46
46
  },
47
- extra: { collection: "testCollection", actionTypes: "find" },
47
+ extra: { collection: "testCollection", actionType: "find" },
48
48
  }
49
49
  const response = await config.integration.read(query)
50
50
  expect(config.integration.client.find).toHaveBeenCalledWith(query.json)
@@ -61,7 +61,7 @@ describe("MongoDB Integration", () => {
61
61
  opt: "option",
62
62
  },
63
63
  },
64
- extra: { collection: "testCollection", actionTypes: "deleteOne" },
64
+ extra: { collection: "testCollection", actionType: "deleteOne" },
65
65
  }
66
66
  await config.integration.delete(query)
67
67
  expect(config.integration.client.deleteOne).toHaveBeenCalledWith(
@@ -83,7 +83,7 @@ describe("MongoDB Integration", () => {
83
83
  upsert: false,
84
84
  },
85
85
  },
86
- extra: { collection: "testCollection", actionTypes: "updateOne" },
86
+ extra: { collection: "testCollection", actionType: "updateOne" },
87
87
  }
88
88
  await config.integration.update(query)
89
89
  expect(config.integration.client.updateOne).toHaveBeenCalledWith(
@@ -97,7 +97,7 @@ describe("MongoDB Integration", () => {
97
97
  const restore = disableConsole()
98
98
 
99
99
  const query = {
100
- extra: { collection: "testCollection", actionTypes: "deleteOne" },
100
+ extra: { collection: "testCollection", actionType: "deleteOne" },
101
101
  }
102
102
 
103
103
  let error = null
@@ -125,19 +125,19 @@ describe("MongoDB Integration", () => {
125
125
  upsert: false,
126
126
  },
127
127
  },
128
- extra: { collection: "testCollection", actionTypes: "updateOne" },
128
+ extra: { collection: "testCollection", actionType: "updateOne" },
129
129
  }
130
130
  await config.integration.update(query)
131
131
  expect(config.integration.client.updateOne).toHaveBeenCalled()
132
132
 
133
133
  const args = config.integration.client.updateOne.mock.calls[0]
134
134
  expect(args[0]).toEqual({
135
- _id: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
136
- name: mongo.ObjectID.createFromHexString("BBBB12345678ABCD12345678"),
135
+ _id: mongo.ObjectId.createFromHexString("ACBD12345678ABCD12345678"),
136
+ name: mongo.ObjectId.createFromHexString("BBBB12345678ABCD12345678"),
137
137
  })
138
138
  expect(args[1]).toEqual({
139
- _id: mongo.ObjectID.createFromHexString("FFFF12345678ABCD12345678"),
140
- name: mongo.ObjectID.createFromHexString("CCCC12345678ABCD12345678"),
139
+ _id: mongo.ObjectId.createFromHexString("FFFF12345678ABCD12345678"),
140
+ name: mongo.ObjectId.createFromHexString("CCCC12345678ABCD12345678"),
141
141
  })
142
142
  expect(args[2]).toEqual({
143
143
  upsert: false,
@@ -161,7 +161,7 @@ describe("MongoDB Integration", () => {
161
161
  upsert: true,
162
162
  },
163
163
  },
164
- extra: { collection: "testCollection", actionTypes: "updateOne" },
164
+ extra: { collection: "testCollection", actionType: "updateOne" },
165
165
  }
166
166
  await config.integration.update(query)
167
167
  expect(config.integration.client.updateOne).toHaveBeenCalled()
@@ -169,12 +169,12 @@ describe("MongoDB Integration", () => {
169
169
  const args = config.integration.client.updateOne.mock.calls[0]
170
170
  expect(args[0]).toEqual({
171
171
  _id: {
172
- $eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
172
+ $eq: mongo.ObjectId.createFromHexString("ACBD12345678ABCD12345678"),
173
173
  },
174
174
  })
175
175
  expect(args[1]).toEqual({
176
176
  $set: {
177
- _id: mongo.ObjectID.createFromHexString("FFFF12345678ABCD12345678"),
177
+ _id: mongo.ObjectId.createFromHexString("FFFF12345678ABCD12345678"),
178
178
  },
179
179
  })
180
180
  expect(args[2]).toEqual({
@@ -200,7 +200,7 @@ describe("MongoDB Integration", () => {
200
200
  upsert: false,
201
201
  },
202
202
  },
203
- extra: { collection: "testCollection", actionTypes: "findOneAndUpdate" },
203
+ extra: { collection: "testCollection", actionType: "findOneAndUpdate" },
204
204
  }
205
205
  await config.integration.read(query)
206
206
  expect(config.integration.client.findOneAndUpdate).toHaveBeenCalled()
@@ -208,7 +208,7 @@ describe("MongoDB Integration", () => {
208
208
  const args = config.integration.client.findOneAndUpdate.mock.calls[0]
209
209
  expect(args[0]).toEqual({
210
210
  _id: {
211
- $eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
211
+ $eq: mongo.ObjectId.createFromHexString("ACBD12345678ABCD12345678"),
212
212
  },
213
213
  })
214
214
  expect(args[1]).toEqual({
@@ -245,7 +245,7 @@ describe("MongoDB Integration", () => {
245
245
  {
246
246
  "upsert": true
247
247
  }`,
248
- extra: { collection: "testCollection", actionTypes: "updateOne" },
248
+ extra: { collection: "testCollection", actionType: "updateOne" },
249
249
  }
250
250
  await config.integration.update(query)
251
251
  expect(config.integration.client.updateOne).toHaveBeenCalled()
@@ -253,7 +253,7 @@ describe("MongoDB Integration", () => {
253
253
  const args = config.integration.client.updateOne.mock.calls[0]
254
254
  expect(args[0]).toEqual({
255
255
  _id: {
256
- $eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
256
+ $eq: mongo.ObjectId.createFromHexString("ACBD12345678ABCD12345678"),
257
257
  },
258
258
  })
259
259
  expect(args[1]).toEqual({
@@ -300,7 +300,7 @@ describe("MongoDB Integration", () => {
300
300
  "upsert": true,
301
301
  "extra": "ad\\"{\\"d"
302
302
  }`,
303
- extra: { collection: "testCollection", actionTypes: "updateOne" },
303
+ extra: { collection: "testCollection", actionType: "updateOne" },
304
304
  }
305
305
  await config.integration.update(query)
306
306
  expect(config.integration.client.updateOne).toHaveBeenCalled()
@@ -308,7 +308,7 @@ describe("MongoDB Integration", () => {
308
308
  const args = config.integration.client.updateOne.mock.calls[0]
309
309
  expect(args[0]).toEqual({
310
310
  _id: {
311
- $eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"),
311
+ $eq: mongo.ObjectId.createFromHexString("ACBD12345678ABCD12345678"),
312
312
  },
313
313
  })
314
314
  expect(args[1]).toEqual({