@budibase/server 1.3.12-alpha.2 → 1.3.13

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