@budibase/server 1.3.13 → 1.3.15-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 (283) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/builder/assets/{index.e50bda9f.css → index.ecdac070.css} +2 -2
  3. package/builder/assets/index.ed9ae6a1.js +995 -0
  4. package/builder/index.html +2 -4
  5. package/coverage/clover.xml +377 -313
  6. package/coverage/coverage-final.json +22 -22
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/backup.js.html +8 -5
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/component.js.html +82 -13
  13. package/coverage/lcov-report/api/controllers/datasource.js.html +20 -20
  14. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/index.html +32 -32
  16. package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
  17. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/screen.js.html +204 -12
  32. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  45. package/coverage/lcov-report/api/index.html +1 -1
  46. package/coverage/lcov-report/api/index.js.html +12 -12
  47. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/index.html +1 -1
  58. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  72. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  75. package/coverage/lcov-report/automations/actions.js.html +1 -1
  76. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  77. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  78. package/coverage/lcov-report/automations/index.html +24 -24
  79. package/coverage/lcov-report/automations/index.js.html +18 -9
  80. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/index.html +1 -1
  87. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggers.js.html +126 -24
  106. package/coverage/lcov-report/constants/index.html +1 -1
  107. package/coverage/lcov-report/constants/index.js.html +1 -1
  108. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  109. package/coverage/lcov-report/constants/screens.js.html +1 -1
  110. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  111. package/coverage/lcov-report/db/index.html +18 -18
  112. package/coverage/lcov-report/db/index.js.html +1 -1
  113. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  116. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  117. package/coverage/lcov-report/db/newid.js.html +2 -2
  118. package/coverage/lcov-report/db/utils.js.html +56 -20
  119. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  120. package/coverage/lcov-report/events/index.html +1 -1
  121. package/coverage/lcov-report/events/index.js.html +1 -1
  122. package/coverage/lcov-report/events/utils.js.html +1 -1
  123. package/coverage/lcov-report/index.html +48 -48
  124. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  125. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  126. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  127. package/coverage/lcov-report/middleware/builder.js.html +12 -12
  128. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  129. package/coverage/lcov-report/middleware/index.html +1 -1
  130. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  131. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  132. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  133. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  134. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  135. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  136. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  137. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  138. package/coverage/lcov-report/utilities/global.js.html +16 -16
  139. package/coverage/lcov-report/utilities/index.html +19 -19
  140. package/coverage/lcov-report/utilities/index.js.html +66 -42
  141. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  142. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  143. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  144. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  145. package/coverage/lcov-report/utilities/rowProcessor/index.html +5 -5
  146. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  147. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
  148. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  149. package/coverage/lcov-report/utilities/security.js.html +2 -2
  150. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  151. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  152. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +6 -3
  153. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  154. package/coverage/lcov-report/utilities/users.js.html +1 -1
  155. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  156. package/coverage/lcov.info +692 -564
  157. package/dist/api/controllers/application.js +6 -9
  158. package/dist/api/controllers/backup.js +2 -1
  159. package/dist/api/controllers/component.js +18 -1
  160. package/dist/api/controllers/datasource.js +4 -4
  161. package/dist/api/controllers/deploy/index.js +17 -2
  162. package/dist/api/controllers/integration.js +4 -4
  163. package/dist/api/controllers/plugin/file.js +24 -0
  164. package/dist/api/controllers/plugin/github.js +69 -0
  165. package/dist/api/controllers/plugin/index.js +189 -0
  166. package/dist/api/controllers/plugin/npm.js +58 -0
  167. package/dist/api/controllers/plugin/uploaders.js +11 -0
  168. package/dist/api/controllers/plugin/url.js +24 -0
  169. package/dist/api/controllers/plugin/utils.js +26 -0
  170. package/dist/api/controllers/row/ExternalRequest.js +1 -1
  171. package/dist/api/controllers/screen.js +51 -2
  172. package/dist/api/controllers/static/index.js +1 -0
  173. package/dist/api/controllers/static/templates/BudibaseApp.svelte +10 -0
  174. package/dist/api/controllers/static/templates/preview.hbs +3 -1
  175. package/dist/api/routes/index.js +2 -0
  176. package/dist/api/routes/plugin.js +39 -0
  177. package/dist/app.js +9 -0
  178. package/dist/automations/index.js +10 -5
  179. package/dist/automations/triggers.js +39 -5
  180. package/dist/automations/utils.js +16 -7
  181. package/dist/db/utils.js +10 -1
  182. package/dist/environment.js +1 -0
  183. package/dist/integrations/airtable.js +126 -129
  184. package/dist/integrations/arangodb.js +86 -89
  185. package/dist/integrations/base/query.js +2 -2
  186. package/dist/integrations/couchdb.js +80 -83
  187. package/dist/integrations/dynamodb.js +161 -164
  188. package/dist/integrations/elasticsearch.js +135 -138
  189. package/dist/integrations/firebase.js +154 -157
  190. package/dist/integrations/googlesheets.js +323 -327
  191. package/dist/integrations/index.js +93 -51
  192. package/dist/integrations/microsoftSqlServer.js +240 -243
  193. package/dist/integrations/mongodb.js +239 -242
  194. package/dist/integrations/mysql.js +215 -219
  195. package/dist/integrations/oracle.js +318 -322
  196. package/dist/integrations/postgres.js +262 -265
  197. package/dist/integrations/redis.js +134 -139
  198. package/dist/integrations/rest.js +293 -281
  199. package/dist/integrations/s3.js +61 -64
  200. package/dist/integrations/snowflake.js +83 -86
  201. package/dist/package.json +8 -6
  202. package/dist/threads/automation.js +6 -0
  203. package/dist/threads/query.js +2 -2
  204. package/dist/tsconfig.build.tsbuildinfo +1 -1
  205. package/dist/utilities/fileSystem/index.js +116 -7
  206. package/dist/utilities/index.js +8 -0
  207. package/dist/utilities/rowProcessor/utils.js +1 -1
  208. package/dist/utilities/usageQuota/rows.js +2 -1
  209. package/dist/watch.js +77 -0
  210. package/package.json +9 -7
  211. package/scripts/dev/manage.js +1 -0
  212. package/src/api/controllers/application.ts +2 -6
  213. package/src/api/controllers/backup.js +2 -1
  214. package/src/api/controllers/component.js +25 -2
  215. package/src/api/controllers/datasource.js +4 -4
  216. package/src/api/controllers/deploy/index.ts +17 -4
  217. package/src/api/controllers/integration.js +4 -4
  218. package/src/api/controllers/plugin/file.ts +15 -0
  219. package/src/api/controllers/plugin/github.ts +75 -0
  220. package/src/api/controllers/plugin/index.ts +202 -0
  221. package/src/api/controllers/plugin/npm.ts +56 -0
  222. package/src/api/controllers/plugin/uploaders.ts +4 -0
  223. package/src/api/controllers/plugin/url.ts +12 -0
  224. package/src/api/controllers/plugin/utils.ts +19 -0
  225. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  226. package/src/api/controllers/screen.js +65 -1
  227. package/src/api/controllers/static/index.ts +1 -0
  228. package/src/api/controllers/static/templates/BudibaseApp.svelte +10 -0
  229. package/src/api/controllers/static/templates/preview.hbs +3 -1
  230. package/src/api/routes/index.ts +2 -0
  231. package/src/api/routes/plugin.ts +14 -0
  232. package/src/api/routes/tests/query.spec.js +11 -28
  233. package/src/app.ts +12 -0
  234. package/src/automations/index.js +6 -3
  235. package/src/automations/triggers.js +44 -10
  236. package/src/automations/utils.ts +21 -9
  237. package/src/db/utils.js +12 -0
  238. package/src/definitions/datasource.ts +1 -0
  239. package/src/environment.js +1 -0
  240. package/src/integrations/airtable.ts +116 -118
  241. package/src/integrations/arangodb.ts +87 -89
  242. package/src/integrations/base/query.ts +2 -2
  243. package/src/integrations/couchdb.ts +83 -89
  244. package/src/integrations/dynamodb.ts +173 -175
  245. package/src/integrations/elasticsearch.ts +120 -122
  246. package/src/integrations/firebase.ts +157 -159
  247. package/src/integrations/googlesheets.ts +328 -338
  248. package/src/integrations/index.ts +59 -21
  249. package/src/integrations/microsoftSqlServer.ts +249 -251
  250. package/src/integrations/mongodb.ts +261 -258
  251. package/src/integrations/mysql.ts +229 -234
  252. package/src/integrations/oracle.ts +373 -380
  253. package/src/integrations/postgres.ts +264 -268
  254. package/src/integrations/redis.ts +128 -132
  255. package/src/integrations/rest.ts +325 -317
  256. package/src/integrations/s3.ts +68 -71
  257. package/src/integrations/snowflake.ts +80 -82
  258. package/src/integrations/tests/{airtable.spec.js → airtable.spec.ts} +21 -18
  259. package/src/integrations/tests/{arangodb.spec.js → arangodb.spec.ts} +12 -9
  260. package/src/integrations/tests/{couchdb.spec.js → couchdb.spec.ts} +33 -27
  261. package/src/integrations/tests/{dynamodb.spec.js → dynamodb.spec.ts} +45 -41
  262. package/src/integrations/tests/{elasticsearch.spec.js → elasticsearch.spec.ts} +22 -21
  263. package/src/integrations/tests/{firebase.spec.js → firebase.spec.ts} +33 -28
  264. package/src/integrations/tests/{microsoftSqlServer.spec.js → microsoftSqlServer.spec.ts} +12 -11
  265. package/src/integrations/tests/{mongo.spec.js → mongo.spec.ts} +46 -35
  266. package/src/integrations/tests/{mysql.spec.js → mysql.spec.ts} +17 -15
  267. package/src/integrations/tests/{oracle.spec.js → oracle.spec.ts} +19 -17
  268. package/src/integrations/tests/{postgres.spec.js → postgres.spec.ts} +19 -17
  269. package/src/integrations/tests/{redis.spec.js → redis.spec.ts} +27 -18
  270. package/src/integrations/tests/{rest.spec.js → rest.spec.ts} +57 -14
  271. package/src/integrations/tests/{s3.spec.js → s3.spec.ts} +10 -8
  272. package/src/integrations/tests/{sql.spec.js → sql.spec.ts} +228 -177
  273. package/src/module.d.ts +2 -0
  274. package/src/threads/automation.ts +6 -0
  275. package/src/threads/query.ts +2 -2
  276. package/src/utilities/fileSystem/index.js +135 -6
  277. package/src/utilities/index.js +8 -0
  278. package/src/utilities/rowProcessor/utils.js +1 -1
  279. package/src/utilities/usageQuota/rows.js +2 -1
  280. package/src/watch.ts +38 -0
  281. package/builder/assets/index.fb22f106.js +0 -875
  282. package/builder/assets/vendor.5e1fe644.css +0 -1
  283. package/builder/assets/vendor.67dbd8fa.js +0 -248
@@ -8,10 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  const types_1 = require("@budibase/types");
13
16
  const datasource_1 = require("../definitions/datasource");
14
17
  const lodash_1 = require("lodash");
18
+ const querystring_1 = __importDefault(require("querystring"));
19
+ const fetch = require("node-fetch");
20
+ const { formatBytes } = require("../utilities");
21
+ const { performance } = require("perf_hooks");
22
+ const FormData = require("form-data");
23
+ const { URLSearchParams } = require("url");
15
24
  const BodyTypes = {
16
25
  NONE: "none",
17
26
  FORM_DATA: "form",
@@ -45,305 +54,308 @@ const coreFields = {
45
54
  type: types_1.DatasourceFieldType.OBJECT,
46
55
  },
47
56
  };
48
- var RestModule;
49
- (function (RestModule) {
50
- const fetch = require("node-fetch");
51
- const { formatBytes } = require("../utilities");
52
- const { performance } = require("perf_hooks");
53
- const FormData = require("form-data");
54
- const { URLSearchParams } = require("url");
55
- const { parseStringPromise: xmlParser, Builder: XmlBuilder, } = require("xml2js");
56
- const SCHEMA = {
57
- docs: "https://github.com/node-fetch/node-fetch",
58
- description: "With the REST API datasource, you can connect, query and pull data from multiple REST APIs. You can then use the retrieved data to build apps.",
59
- friendlyName: "REST API",
60
- type: "API",
61
- datasource: {
62
- url: {
63
- type: types_1.DatasourceFieldType.STRING,
64
- default: "",
65
- required: false,
66
- deprecated: true,
67
- },
68
- defaultHeaders: {
69
- type: types_1.DatasourceFieldType.OBJECT,
70
- required: false,
71
- default: {},
72
- },
57
+ const { parseStringPromise: xmlParser, Builder: XmlBuilder } = require("xml2js");
58
+ const SCHEMA = {
59
+ docs: "https://github.com/node-fetch/node-fetch",
60
+ description: "With the REST API datasource, you can connect, query and pull data from multiple REST APIs. You can then use the retrieved data to build apps.",
61
+ friendlyName: "REST API",
62
+ type: "API",
63
+ datasource: {
64
+ url: {
65
+ type: types_1.DatasourceFieldType.STRING,
66
+ default: "",
67
+ required: false,
68
+ deprecated: true,
73
69
  },
74
- query: {
75
- create: {
76
- readable: true,
77
- displayName: "POST",
78
- type: types_1.QueryType.FIELDS,
79
- fields: coreFields,
80
- },
81
- read: {
82
- displayName: "GET",
83
- readable: true,
84
- type: types_1.QueryType.FIELDS,
85
- fields: coreFields,
86
- },
87
- update: {
88
- displayName: "PUT",
89
- readable: true,
90
- type: types_1.QueryType.FIELDS,
91
- fields: coreFields,
92
- },
93
- patch: {
94
- displayName: "PATCH",
95
- readable: true,
96
- type: types_1.QueryType.FIELDS,
97
- fields: coreFields,
98
- },
99
- delete: {
100
- displayName: "DELETE",
101
- type: types_1.QueryType.FIELDS,
102
- fields: coreFields,
103
- },
70
+ defaultHeaders: {
71
+ type: types_1.DatasourceFieldType.OBJECT,
72
+ required: false,
73
+ default: {},
104
74
  },
105
- };
106
- class RestIntegration {
107
- constructor(config) {
108
- this.headers = {};
109
- this.startTimeMs = performance.now();
110
- this.config = config;
111
- }
112
- parseResponse(response, pagination) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- let data, raw, headers;
115
- const contentType = response.headers.get("content-type") || "";
116
- try {
117
- if (contentType.includes("application/json")) {
118
- data = yield response.json();
119
- raw = JSON.stringify(data);
120
- }
121
- else if (contentType.includes("text/xml") ||
122
- contentType.includes("application/xml")) {
123
- const rawXml = yield response.text();
124
- data =
125
- (yield xmlParser(rawXml, {
126
- explicitArray: false,
127
- trim: true,
128
- explicitRoot: false,
129
- })) || {};
130
- // there is only one structure, its an array, return the array so it appears as rows
131
- const keys = Object.keys(data);
132
- if (keys.length === 1 && Array.isArray(data[keys[0]])) {
133
- data = data[keys[0]];
134
- }
135
- raw = rawXml;
136
- }
137
- else {
138
- data = yield response.text();
139
- raw = data;
140
- }
141
- }
142
- catch (err) {
143
- throw "Failed to parse response body.";
144
- }
145
- const size = formatBytes(response.headers.get("content-length") || Buffer.byteLength(raw, "utf8"));
146
- const time = `${Math.round(performance.now() - this.startTimeMs)}ms`;
147
- headers = response.headers.raw();
148
- for (let [key, value] of Object.entries(headers)) {
149
- headers[key] = Array.isArray(value) ? value[0] : value;
150
- }
151
- // Check if a pagination cursor exists in the response
152
- let nextCursor = null;
153
- if (pagination === null || pagination === void 0 ? void 0 : pagination.responseParam) {
154
- nextCursor = (0, lodash_1.get)(data, pagination.responseParam);
155
- }
156
- return {
157
- data,
158
- info: {
159
- code: response.status,
160
- size,
161
- time,
162
- },
163
- extra: {
164
- raw,
165
- headers,
166
- },
167
- pagination: {
168
- cursor: nextCursor,
169
- },
170
- };
171
- });
172
- }
173
- getUrl(path, queryString, pagination, paginationValues) {
174
- // Add pagination params to query string if required
175
- if ((pagination === null || pagination === void 0 ? void 0 : pagination.location) === "query" && paginationValues) {
176
- const { pageParam, sizeParam } = pagination;
177
- const params = new URLSearchParams();
178
- // Append page number or cursor param if configured
179
- if (pageParam && paginationValues.page != null) {
180
- params.append(pageParam, paginationValues.page);
75
+ legacyHttpParser: {
76
+ display: "Legacy HTTP Support",
77
+ type: types_1.DatasourceFieldType.BOOLEAN,
78
+ required: false,
79
+ default: false,
80
+ },
81
+ },
82
+ query: {
83
+ create: {
84
+ readable: true,
85
+ displayName: "POST",
86
+ type: types_1.QueryType.FIELDS,
87
+ fields: coreFields,
88
+ },
89
+ read: {
90
+ displayName: "GET",
91
+ readable: true,
92
+ type: types_1.QueryType.FIELDS,
93
+ fields: coreFields,
94
+ },
95
+ update: {
96
+ displayName: "PUT",
97
+ readable: true,
98
+ type: types_1.QueryType.FIELDS,
99
+ fields: coreFields,
100
+ },
101
+ patch: {
102
+ displayName: "PATCH",
103
+ readable: true,
104
+ type: types_1.QueryType.FIELDS,
105
+ fields: coreFields,
106
+ },
107
+ delete: {
108
+ displayName: "DELETE",
109
+ type: types_1.QueryType.FIELDS,
110
+ fields: coreFields,
111
+ },
112
+ },
113
+ };
114
+ class RestIntegration {
115
+ constructor(config) {
116
+ this.headers = {};
117
+ this.startTimeMs = performance.now();
118
+ this.config = config;
119
+ }
120
+ parseResponse(response, pagination) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ let data, raw, headers;
123
+ const contentType = response.headers.get("content-type") || "";
124
+ try {
125
+ if (contentType.includes("application/json")) {
126
+ data = yield response.json();
127
+ raw = JSON.stringify(data);
181
128
  }
182
- // Append page size param if configured
183
- if (sizeParam && paginationValues.limit != null) {
184
- params.append(sizeParam, paginationValues.limit);
129
+ else if (contentType.includes("text/xml") ||
130
+ contentType.includes("application/xml")) {
131
+ const rawXml = yield response.text();
132
+ data =
133
+ (yield xmlParser(rawXml, {
134
+ explicitArray: false,
135
+ trim: true,
136
+ explicitRoot: false,
137
+ })) || {};
138
+ // there is only one structure, its an array, return the array so it appears as rows
139
+ const keys = Object.keys(data);
140
+ if (keys.length === 1 && Array.isArray(data[keys[0]])) {
141
+ data = data[keys[0]];
142
+ }
143
+ raw = rawXml;
185
144
  }
186
- // Prepend query string with pagination params
187
- let paginationString = params.toString();
188
- if (paginationString) {
189
- queryString = `${paginationString}&${queryString}`;
145
+ else {
146
+ data = yield response.text();
147
+ raw = data;
190
148
  }
191
149
  }
192
- const main = `${path}?${queryString}`;
193
- let complete = main;
194
- if (this.config.url && !main.startsWith("http")) {
195
- complete = !this.config.url ? main : `${this.config.url}/${main}`;
150
+ catch (err) {
151
+ throw "Failed to parse response body.";
196
152
  }
197
- if (!complete.startsWith("http")) {
198
- complete = `http://${complete}`;
153
+ const size = formatBytes(response.headers.get("content-length") || Buffer.byteLength(raw, "utf8"));
154
+ const time = `${Math.round(performance.now() - this.startTimeMs)}ms`;
155
+ headers = response.headers.raw();
156
+ for (let [key, value] of Object.entries(headers)) {
157
+ headers[key] = Array.isArray(value) ? value[0] : value;
199
158
  }
200
- return complete;
201
- }
202
- addBody(bodyType, body, input, pagination, paginationValues) {
203
- if (!input.headers) {
204
- input.headers = {};
159
+ // Check if a pagination cursor exists in the response
160
+ let nextCursor = null;
161
+ if (pagination === null || pagination === void 0 ? void 0 : pagination.responseParam) {
162
+ nextCursor = (0, lodash_1.get)(data, pagination.responseParam);
205
163
  }
206
- if (bodyType === BodyTypes.NONE) {
207
- return input;
164
+ return {
165
+ data,
166
+ info: {
167
+ code: response.status,
168
+ size,
169
+ time,
170
+ },
171
+ extra: {
172
+ raw,
173
+ headers,
174
+ },
175
+ pagination: {
176
+ cursor: nextCursor,
177
+ },
178
+ };
179
+ });
180
+ }
181
+ getUrl(path, queryString, pagination, paginationValues) {
182
+ // Add pagination params to query string if required
183
+ if ((pagination === null || pagination === void 0 ? void 0 : pagination.location) === "query" && paginationValues) {
184
+ const { pageParam, sizeParam } = pagination;
185
+ const params = new URLSearchParams();
186
+ // Append page number or cursor param if configured
187
+ if (pageParam && paginationValues.page != null) {
188
+ params.append(pageParam, paginationValues.page);
208
189
  }
209
- let error, object = {}, string = "";
210
- try {
211
- if (body) {
212
- string = typeof body !== "string" ? JSON.stringify(body) : body;
213
- object = typeof body === "object" ? body : JSON.parse(body);
214
- }
190
+ // Append page size param if configured
191
+ if (sizeParam && paginationValues.limit != null) {
192
+ params.append(sizeParam, paginationValues.limit);
215
193
  }
216
- catch (err) {
217
- error = err;
194
+ // Prepend query string with pagination params
195
+ let paginationString = params.toString();
196
+ if (paginationString) {
197
+ queryString = `${paginationString}&${queryString}`;
218
198
  }
219
- // Util to add pagination values to a certain body type
220
- const addPaginationToBody = (insertFn) => {
221
- if ((pagination === null || pagination === void 0 ? void 0 : pagination.location) === "body") {
222
- if ((pagination === null || pagination === void 0 ? void 0 : pagination.pageParam) && (paginationValues === null || paginationValues === void 0 ? void 0 : paginationValues.page) != null) {
223
- insertFn(pagination.pageParam, paginationValues.page);
224
- }
225
- if ((pagination === null || pagination === void 0 ? void 0 : pagination.sizeParam) && (paginationValues === null || paginationValues === void 0 ? void 0 : paginationValues.limit) != null) {
226
- insertFn(pagination.sizeParam, paginationValues.limit);
227
- }
228
- }
229
- };
230
- switch (bodyType) {
231
- case BodyTypes.TEXT:
232
- // content type defaults to plaintext
233
- input.body = string;
234
- break;
235
- case BodyTypes.ENCODED:
236
- const params = new URLSearchParams();
237
- for (let [key, value] of Object.entries(object)) {
238
- params.append(key, value);
239
- }
240
- addPaginationToBody((key, value) => {
241
- params.append(key, value);
242
- });
243
- input.body = params;
244
- break;
245
- case BodyTypes.FORM_DATA:
246
- const form = new FormData();
247
- for (let [key, value] of Object.entries(object)) {
248
- form.append(key, value);
249
- }
250
- addPaginationToBody((key, value) => {
251
- form.append(key, value);
252
- });
253
- input.body = form;
254
- break;
255
- case BodyTypes.XML:
256
- if (object != null && Object.keys(object).length) {
257
- string = new XmlBuilder().buildObject(object);
258
- }
259
- input.body = string;
260
- input.headers["Content-Type"] = "application/xml";
261
- break;
262
- case BodyTypes.JSON:
263
- // if JSON error, throw it
264
- if (error) {
265
- throw "Invalid JSON for request body";
266
- }
267
- addPaginationToBody((key, value) => {
268
- object[key] = value;
269
- });
270
- input.body = JSON.stringify(object);
271
- input.headers["Content-Type"] = "application/json";
272
- break;
273
- }
274
- return input;
275
199
  }
276
- getAuthHeaders(authConfigId) {
277
- let headers = {};
278
- if (this.config.authConfigs && authConfigId) {
279
- const authConfig = this.config.authConfigs.filter(c => c._id === authConfigId)[0];
280
- // check the config still exists before proceeding
281
- // if not - do nothing
282
- if (authConfig) {
283
- let config;
284
- switch (authConfig.type) {
285
- case datasource_1.AuthType.BASIC:
286
- config = authConfig.config;
287
- headers.Authorization = `Basic ${Buffer.from(`${config.username}:${config.password}`).toString("base64")}`;
288
- break;
289
- case datasource_1.AuthType.BEARER:
290
- config = authConfig.config;
291
- headers.Authorization = `Bearer ${config.token}`;
292
- break;
293
- }
294
- }
295
- }
296
- return headers;
200
+ // make sure the query string is fully encoded
201
+ const main = `${path}?${querystring_1.default.encode(querystring_1.default.decode(queryString))}`;
202
+ let complete = main;
203
+ if (this.config.url && !main.startsWith("http")) {
204
+ complete = !this.config.url ? main : `${this.config.url}/${main}`;
297
205
  }
298
- _req(query) {
299
- return __awaiter(this, void 0, void 0, function* () {
300
- const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody, authConfigId, pagination, paginationValues, } = query;
301
- const authHeaders = this.getAuthHeaders(authConfigId);
302
- this.headers = Object.assign(Object.assign(Object.assign({}, this.config.defaultHeaders), headers), authHeaders);
303
- if (disabledHeaders) {
304
- for (let headerKey of Object.keys(this.headers)) {
305
- if (disabledHeaders[headerKey]) {
306
- delete this.headers[headerKey];
307
- }
308
- }
309
- }
310
- let input = { method, headers: this.headers };
311
- input = this.addBody(bodyType, requestBody, input, pagination, paginationValues);
312
- this.startTimeMs = performance.now();
313
- const url = this.getUrl(path, queryString, pagination, paginationValues);
314
- const response = yield fetch(url, input);
315
- return yield this.parseResponse(response, pagination);
316
- });
206
+ if (!complete.startsWith("http")) {
207
+ complete = `http://${complete}`;
317
208
  }
318
- create(opts) {
319
- return __awaiter(this, void 0, void 0, function* () {
320
- return this._req(Object.assign(Object.assign({}, opts), { method: "POST" }));
321
- });
209
+ return complete;
210
+ }
211
+ addBody(bodyType, body, input, pagination, paginationValues) {
212
+ if (!input.headers) {
213
+ input.headers = {};
322
214
  }
323
- read(opts) {
324
- return __awaiter(this, void 0, void 0, function* () {
325
- return this._req(Object.assign(Object.assign({}, opts), { method: "GET" }));
326
- });
215
+ if (bodyType === BodyTypes.NONE) {
216
+ return input;
327
217
  }
328
- update(opts) {
329
- return __awaiter(this, void 0, void 0, function* () {
330
- return this._req(Object.assign(Object.assign({}, opts), { method: "PUT" }));
331
- });
218
+ let error, object = {}, string = "";
219
+ try {
220
+ if (body) {
221
+ string = typeof body !== "string" ? JSON.stringify(body) : body;
222
+ object = typeof body === "object" ? body : JSON.parse(body);
223
+ }
332
224
  }
333
- patch(opts) {
334
- return __awaiter(this, void 0, void 0, function* () {
335
- return this._req(Object.assign(Object.assign({}, opts), { method: "PATCH" }));
336
- });
225
+ catch (err) {
226
+ error = err;
227
+ }
228
+ // Util to add pagination values to a certain body type
229
+ const addPaginationToBody = (insertFn) => {
230
+ if ((pagination === null || pagination === void 0 ? void 0 : pagination.location) === "body") {
231
+ if ((pagination === null || pagination === void 0 ? void 0 : pagination.pageParam) && (paginationValues === null || paginationValues === void 0 ? void 0 : paginationValues.page) != null) {
232
+ insertFn(pagination.pageParam, paginationValues.page);
233
+ }
234
+ if ((pagination === null || pagination === void 0 ? void 0 : pagination.sizeParam) && (paginationValues === null || paginationValues === void 0 ? void 0 : paginationValues.limit) != null) {
235
+ insertFn(pagination.sizeParam, paginationValues.limit);
236
+ }
237
+ }
238
+ };
239
+ switch (bodyType) {
240
+ case BodyTypes.TEXT:
241
+ // content type defaults to plaintext
242
+ input.body = string;
243
+ break;
244
+ case BodyTypes.ENCODED:
245
+ const params = new URLSearchParams();
246
+ for (let [key, value] of Object.entries(object)) {
247
+ params.append(key, value);
248
+ }
249
+ addPaginationToBody((key, value) => {
250
+ params.append(key, value);
251
+ });
252
+ input.body = params;
253
+ break;
254
+ case BodyTypes.FORM_DATA:
255
+ const form = new FormData();
256
+ for (let [key, value] of Object.entries(object)) {
257
+ form.append(key, value);
258
+ }
259
+ addPaginationToBody((key, value) => {
260
+ form.append(key, value);
261
+ });
262
+ input.body = form;
263
+ break;
264
+ case BodyTypes.XML:
265
+ if (object != null && Object.keys(object).length) {
266
+ string = new XmlBuilder().buildObject(object);
267
+ }
268
+ input.body = string;
269
+ input.headers["Content-Type"] = "application/xml";
270
+ break;
271
+ case BodyTypes.JSON:
272
+ // if JSON error, throw it
273
+ if (error) {
274
+ throw "Invalid JSON for request body";
275
+ }
276
+ addPaginationToBody((key, value) => {
277
+ object[key] = value;
278
+ });
279
+ input.body = JSON.stringify(object);
280
+ input.headers["Content-Type"] = "application/json";
281
+ break;
337
282
  }
338
- delete(opts) {
339
- return __awaiter(this, void 0, void 0, function* () {
340
- return this._req(Object.assign(Object.assign({}, opts), { method: "DELETE" }));
341
- });
283
+ return input;
284
+ }
285
+ getAuthHeaders(authConfigId) {
286
+ let headers = {};
287
+ if (this.config.authConfigs && authConfigId) {
288
+ const authConfig = this.config.authConfigs.filter(c => c._id === authConfigId)[0];
289
+ // check the config still exists before proceeding
290
+ // if not - do nothing
291
+ if (authConfig) {
292
+ let config;
293
+ switch (authConfig.type) {
294
+ case datasource_1.AuthType.BASIC:
295
+ config = authConfig.config;
296
+ headers.Authorization = `Basic ${Buffer.from(`${config.username}:${config.password}`).toString("base64")}`;
297
+ break;
298
+ case datasource_1.AuthType.BEARER:
299
+ config = authConfig.config;
300
+ headers.Authorization = `Bearer ${config.token}`;
301
+ break;
302
+ }
303
+ }
342
304
  }
305
+ return headers;
306
+ }
307
+ _req(query) {
308
+ return __awaiter(this, void 0, void 0, function* () {
309
+ const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody, authConfigId, pagination, paginationValues, } = query;
310
+ const authHeaders = this.getAuthHeaders(authConfigId);
311
+ this.headers = Object.assign(Object.assign(Object.assign({}, this.config.defaultHeaders), headers), authHeaders);
312
+ if (disabledHeaders) {
313
+ for (let headerKey of Object.keys(this.headers)) {
314
+ if (disabledHeaders[headerKey]) {
315
+ delete this.headers[headerKey];
316
+ }
317
+ }
318
+ }
319
+ let input = { method, headers: this.headers };
320
+ input = this.addBody(bodyType, requestBody, input, pagination, paginationValues);
321
+ if (this.config.legacyHttpParser) {
322
+ // https://github.com/nodejs/node/issues/43798
323
+ input.extraHttpOptions = { insecureHTTPParser: true };
324
+ }
325
+ this.startTimeMs = performance.now();
326
+ const url = this.getUrl(path, queryString, pagination, paginationValues);
327
+ const response = yield fetch(url, input);
328
+ return yield this.parseResponse(response, pagination);
329
+ });
330
+ }
331
+ create(opts) {
332
+ return __awaiter(this, void 0, void 0, function* () {
333
+ return this._req(Object.assign(Object.assign({}, opts), { method: "POST" }));
334
+ });
335
+ }
336
+ read(opts) {
337
+ return __awaiter(this, void 0, void 0, function* () {
338
+ return this._req(Object.assign(Object.assign({}, opts), { method: "GET" }));
339
+ });
343
340
  }
344
- module.exports = {
345
- schema: SCHEMA,
346
- integration: RestIntegration,
347
- AuthType: datasource_1.AuthType,
348
- };
349
- })(RestModule || (RestModule = {}));
341
+ update(opts) {
342
+ return __awaiter(this, void 0, void 0, function* () {
343
+ return this._req(Object.assign(Object.assign({}, opts), { method: "PUT" }));
344
+ });
345
+ }
346
+ patch(opts) {
347
+ return __awaiter(this, void 0, void 0, function* () {
348
+ return this._req(Object.assign(Object.assign({}, opts), { method: "PATCH" }));
349
+ });
350
+ }
351
+ delete(opts) {
352
+ return __awaiter(this, void 0, void 0, function* () {
353
+ return this._req(Object.assign(Object.assign({}, opts), { method: "DELETE" }));
354
+ });
355
+ }
356
+ }
357
+ exports.default = {
358
+ schema: SCHEMA,
359
+ integration: RestIntegration,
360
+ AuthType: datasource_1.AuthType,
361
+ };