@budibase/server 1.0.19-alpha.0 → 1.0.19-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 (194) hide show
  1. package/__mocks__/node-fetch.ts +3 -0
  2. package/builder/assets/bb-spaceship.8f6e81e1.svg +227 -0
  3. package/builder/assets/{index.9337c392.css → index.2fc6da87.css} +1 -1
  4. package/builder/assets/{index.f0651cb7.js → index.b0718f41.js} +190 -186
  5. package/builder/index.html +2 -2
  6. package/coverage/clover.xml +313 -275
  7. package/coverage/coverage-final.json +13 -13
  8. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/application.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/index.html +18 -18
  20. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/index.html +11 -11
  25. package/coverage/lcov-report/api/controllers/query/index.js.html +15 -9
  26. package/coverage/lcov-report/api/controllers/query/validation.js.html +5 -2
  27. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  39. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/user.js.html +108 -9
  44. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  46. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  47. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  48. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  49. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  50. package/coverage/lcov-report/api/index.html +1 -1
  51. package/coverage/lcov-report/api/index.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/index.html +1 -1
  65. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/user.js.html +32 -2
  80. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  82. package/coverage/lcov-report/automations/actions.js.html +1 -1
  83. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  84. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  85. package/coverage/lcov-report/automations/index.html +1 -1
  86. package/coverage/lcov-report/automations/index.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/index.html +1 -1
  96. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  99. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  100. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  101. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  102. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  103. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  104. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  108. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  109. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  110. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  111. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  112. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  113. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  114. package/coverage/lcov-report/automations/utils.js.html +1 -1
  115. package/coverage/lcov-report/constants/index.html +1 -1
  116. package/coverage/lcov-report/constants/index.js.html +22 -22
  117. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  118. package/coverage/lcov-report/constants/screens.js.html +1 -1
  119. package/coverage/lcov-report/db/client.js.html +18 -18
  120. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  121. package/coverage/lcov-report/db/index.html +15 -15
  122. package/coverage/lcov-report/db/index.js.html +3 -3
  123. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  124. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  125. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  126. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  127. package/coverage/lcov-report/db/newid.js.html +3 -3
  128. package/coverage/lcov-report/db/utils.js.html +90 -63
  129. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  130. package/coverage/lcov-report/events/index.html +1 -1
  131. package/coverage/lcov-report/events/index.js.html +1 -1
  132. package/coverage/lcov-report/events/utils.js.html +1 -1
  133. package/coverage/lcov-report/index.html +51 -51
  134. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  135. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  136. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  137. package/coverage/lcov-report/middleware/authorized.js.html +2 -2
  138. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  139. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  140. package/coverage/lcov-report/middleware/index.html +1 -1
  141. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  142. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  143. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  144. package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
  145. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  146. package/coverage/lcov-report/threads/automation.js.html +1 -1
  147. package/coverage/lcov-report/threads/index.html +20 -20
  148. package/coverage/lcov-report/threads/index.js.html +1 -1
  149. package/coverage/lcov-report/threads/query.js.html +63 -12
  150. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  151. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  152. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  153. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  154. package/coverage/lcov-report/utilities/global.js.html +1 -1
  155. package/coverage/lcov-report/utilities/index.html +19 -19
  156. package/coverage/lcov-report/utilities/index.js.html +66 -33
  157. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  158. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  159. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  160. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  161. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  162. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  163. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  164. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  165. package/coverage/lcov-report/utilities/security.js.html +2 -2
  166. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  167. package/coverage/lcov-report/utilities/users.js.html +1 -1
  168. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  169. package/coverage/lcov.info +490 -424
  170. package/dist/api/controllers/query/index.js +4 -2
  171. package/dist/api/controllers/query/validation.js +1 -0
  172. package/dist/api/controllers/user.js +37 -1
  173. package/dist/api/routes/user.js +3 -1
  174. package/dist/db/utils.js +8 -0
  175. package/dist/integrations/rest.js +110 -113
  176. package/dist/package.json +4 -4
  177. package/dist/threads/query.js +14 -2
  178. package/dist/tsconfig.tsbuildinfo +1 -1
  179. package/dist/utilities/index.js +10 -0
  180. package/package.json +5 -5
  181. package/src/api/controllers/query/import/sources/base/index.ts +1 -2
  182. package/src/api/controllers/query/import/sources/openapi2.ts +1 -1
  183. package/src/api/controllers/query/index.js +4 -2
  184. package/src/api/controllers/query/validation.js +1 -0
  185. package/src/api/controllers/user.js +33 -0
  186. package/src/api/routes/user.js +10 -0
  187. package/src/db/utils.js +9 -0
  188. package/src/definitions/common.ts +2 -38
  189. package/src/definitions/datasource.ts +50 -1
  190. package/src/integrations/base/IntegrationBase.ts +4 -4
  191. package/src/integrations/rest.ts +111 -137
  192. package/src/integrations/tests/rest.spec.js +16 -7
  193. package/src/threads/query.js +19 -2
  194. package/src/utilities/index.js +11 -0
@@ -112,7 +112,7 @@ function enrichQueryFields(fields, parameters = {}) {
112
112
  enrichedQuery.requestBody);
113
113
  }
114
114
  catch (err) {
115
- throw { message: `JSON Invalid - error: ${err}` };
115
+ // no json found, ignore
116
116
  }
117
117
  delete enrichedQuery.customData;
118
118
  }
@@ -138,7 +138,7 @@ exports.preview = function (ctx) {
138
138
  const { fields, parameters, queryVerb, transformer } = ctx.request.body;
139
139
  const enrichedQuery = yield enrichQueryFields(fields, parameters);
140
140
  try {
141
- const { rows, keys } = yield Runner.run({
141
+ const { rows, keys, info, extra } = yield Runner.run({
142
142
  datasource,
143
143
  queryVerb,
144
144
  query: enrichedQuery,
@@ -147,6 +147,8 @@ exports.preview = function (ctx) {
147
147
  ctx.body = {
148
148
  rows,
149
149
  schemaFields: [...new Set(keys)],
150
+ info,
151
+ extra,
150
152
  };
151
153
  }
152
154
  catch (err) {
@@ -17,6 +17,7 @@ exports.queryValidation = () => {
17
17
  extra: Joi.object().optional(),
18
18
  schema: Joi.object({}).required().unknown(true),
19
19
  transformer: Joi.string().optional(),
20
+ flags: Joi.object().optional(),
20
21
  });
21
22
  };
22
23
  exports.generateQueryValidation = () => {
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  const CouchDB = require("../../db");
12
- const { generateUserMetadataID, getUserMetadataParams, } = require("../../db/utils");
12
+ const { generateUserMetadataID, getUserMetadataParams, generateUserFlagID, } = require("../../db/utils");
13
13
  const { InternalTables } = require("../../db/utils");
14
14
  const { getGlobalUsers, getRawGlobalUser } = require("../../utilities/global");
15
15
  const { getFullUser } = require("../../utilities/users");
@@ -189,3 +189,39 @@ exports.findMetadata = function (ctx) {
189
189
  ctx.body = yield getFullUser(ctx, ctx.params.id);
190
190
  });
191
191
  };
192
+ exports.setFlag = function (ctx) {
193
+ return __awaiter(this, void 0, void 0, function* () {
194
+ const userId = ctx.user._id;
195
+ const { flag, value } = ctx.request.body;
196
+ if (!flag) {
197
+ ctx.throw(400, "Must supply a 'flag' field in request body.");
198
+ }
199
+ const flagDocId = generateUserFlagID(userId);
200
+ const db = new CouchDB(ctx.appId);
201
+ let doc;
202
+ try {
203
+ doc = yield db.get(flagDocId);
204
+ }
205
+ catch (err) {
206
+ doc = { _id: flagDocId };
207
+ }
208
+ doc[flag] = value || true;
209
+ yield db.put(doc);
210
+ ctx.body = { message: "Flag set successfully" };
211
+ });
212
+ };
213
+ exports.getFlags = function (ctx) {
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ const userId = ctx.user._id;
216
+ const docId = generateUserFlagID(userId);
217
+ const db = new CouchDB(ctx.appId);
218
+ let doc;
219
+ try {
220
+ doc = yield db.get(docId);
221
+ }
222
+ catch (err) {
223
+ doc = { _id: docId };
224
+ }
225
+ ctx.body = doc;
226
+ });
227
+ };
@@ -10,5 +10,7 @@ router
10
10
  .put("/api/users/metadata", authorized(PermissionTypes.USER, PermissionLevels.WRITE), controller.updateMetadata)
11
11
  .post("/api/users/metadata/self", authorized(PermissionTypes.USER, PermissionLevels.WRITE), controller.updateSelfMetadata)
12
12
  .delete("/api/users/metadata/:id", authorized(PermissionTypes.USER, PermissionLevels.WRITE), controller.destroyMetadata)
13
- .post("/api/users/metadata/sync/:id", authorized(PermissionTypes.USER, PermissionLevels.WRITE), controller.syncUser);
13
+ .post("/api/users/metadata/sync/:id", authorized(PermissionTypes.USER, PermissionLevels.WRITE), controller.syncUser)
14
+ .post("/api/users/flags", authorized(PermissionTypes.USER, PermissionLevels.WRITE), controller.setFlag)
15
+ .get("/api/users/flags", authorized(PermissionTypes.USER, PermissionLevels.READ), controller.getFlags);
14
16
  module.exports = router;
package/dist/db/utils.js CHANGED
@@ -28,6 +28,7 @@ const DocumentTypes = {
28
28
  DEPLOYMENTS: "deployments",
29
29
  METADATA: "metadata",
30
30
  MEM_VIEW: "view",
31
+ USER_FLAG: "flag",
31
32
  };
32
33
  const ViewNames = {
33
34
  LINK: "by_link",
@@ -271,6 +272,13 @@ exports.getQueryParams = (datasourceId = null, otherProps = {}) => {
271
272
  }
272
273
  return getDocParams(DocumentTypes.QUERY, `${datasourceId}${SEPARATOR}`, otherProps);
273
274
  };
275
+ /**
276
+ * Generates a new flag document ID.
277
+ * @returns {string} The ID of the flag document that was generated.
278
+ */
279
+ exports.generateUserFlagID = userId => {
280
+ return `${DocumentTypes.USER_FLAG}${SEPARATOR}${userId}`;
281
+ };
274
282
  exports.generateMetadataID = (type, entityId) => {
275
283
  return `${DocumentTypes.METADATA}${SEPARATOR}${type}${SEPARATOR}${entityId}`;
276
284
  };
@@ -10,18 +10,50 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const datasource_1 = require("../definitions/datasource");
13
+ const BodyTypes = {
14
+ NONE: "none",
15
+ FORM_DATA: "form",
16
+ ENCODED: "encoded",
17
+ JSON: "json",
18
+ TEXT: "text",
19
+ };
20
+ const coreFields = {
21
+ path: {
22
+ type: datasource_1.DatasourceFieldTypes.STRING,
23
+ display: "URL",
24
+ },
25
+ queryString: {
26
+ type: datasource_1.DatasourceFieldTypes.STRING,
27
+ },
28
+ headers: {
29
+ type: datasource_1.DatasourceFieldTypes.OBJECT,
30
+ },
31
+ enabledHeaders: {
32
+ type: datasource_1.DatasourceFieldTypes.OBJECT,
33
+ },
34
+ requestBody: {
35
+ type: datasource_1.DatasourceFieldTypes.JSON,
36
+ },
37
+ bodyType: {
38
+ type: datasource_1.DatasourceFieldTypes.STRING,
39
+ enum: Object.values(BodyTypes),
40
+ },
41
+ };
13
42
  var RestModule;
14
43
  (function (RestModule) {
15
44
  const fetch = require("node-fetch");
45
+ const { formatBytes } = require("../utilities");
46
+ const { performance } = require("perf_hooks");
16
47
  const SCHEMA = {
17
48
  docs: "https://github.com/node-fetch/node-fetch",
18
- description: "Representational state transfer (REST) is a de-facto standard for a software architecture for interactive applications that typically use multiple Web services. ",
49
+ 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.",
19
50
  friendlyName: "REST API",
20
51
  datasource: {
21
52
  url: {
22
53
  type: datasource_1.DatasourceFieldTypes.STRING,
23
- default: "localhost",
24
- required: true,
54
+ default: "",
55
+ required: false,
56
+ deprecated: true,
25
57
  },
26
58
  defaultHeaders: {
27
59
  type: datasource_1.DatasourceFieldTypes.OBJECT,
@@ -34,169 +66,134 @@ var RestModule;
34
66
  readable: true,
35
67
  displayName: "POST",
36
68
  type: datasource_1.QueryTypes.FIELDS,
37
- urlDisplay: true,
38
- fields: {
39
- path: {
40
- type: datasource_1.DatasourceFieldTypes.STRING,
41
- },
42
- queryString: {
43
- type: datasource_1.DatasourceFieldTypes.STRING,
44
- },
45
- headers: {
46
- type: datasource_1.DatasourceFieldTypes.OBJECT,
47
- },
48
- requestBody: {
49
- type: datasource_1.DatasourceFieldTypes.JSON,
50
- },
51
- },
69
+ fields: coreFields,
52
70
  },
53
71
  read: {
54
72
  displayName: "GET",
55
73
  readable: true,
56
74
  type: datasource_1.QueryTypes.FIELDS,
57
- urlDisplay: true,
58
- fields: {
59
- path: {
60
- type: datasource_1.DatasourceFieldTypes.STRING,
61
- },
62
- queryString: {
63
- type: datasource_1.DatasourceFieldTypes.STRING,
64
- },
65
- headers: {
66
- type: datasource_1.DatasourceFieldTypes.OBJECT,
67
- },
68
- },
75
+ fields: coreFields,
69
76
  },
70
77
  update: {
71
78
  displayName: "PUT",
72
79
  readable: true,
73
80
  type: datasource_1.QueryTypes.FIELDS,
74
- urlDisplay: true,
75
- fields: {
76
- path: {
77
- type: datasource_1.DatasourceFieldTypes.STRING,
78
- },
79
- queryString: {
80
- type: datasource_1.DatasourceFieldTypes.STRING,
81
- },
82
- headers: {
83
- type: datasource_1.DatasourceFieldTypes.OBJECT,
84
- },
85
- requestBody: {
86
- type: datasource_1.DatasourceFieldTypes.JSON,
87
- },
88
- },
81
+ fields: coreFields,
89
82
  },
90
83
  patch: {
91
84
  displayName: "PATCH",
92
85
  readable: true,
93
86
  type: datasource_1.QueryTypes.FIELDS,
94
- urlDisplay: true,
95
- fields: {
96
- path: {
97
- type: datasource_1.DatasourceFieldTypes.STRING,
98
- },
99
- queryString: {
100
- type: datasource_1.DatasourceFieldTypes.STRING,
101
- },
102
- headers: {
103
- type: datasource_1.DatasourceFieldTypes.OBJECT,
104
- },
105
- requestBody: {
106
- type: datasource_1.DatasourceFieldTypes.JSON,
107
- },
108
- },
87
+ fields: coreFields,
109
88
  },
110
89
  delete: {
111
90
  displayName: "DELETE",
112
91
  type: datasource_1.QueryTypes.FIELDS,
113
- urlDisplay: true,
114
- fields: {
115
- path: {
116
- type: datasource_1.DatasourceFieldTypes.STRING,
117
- },
118
- queryString: {
119
- type: datasource_1.DatasourceFieldTypes.STRING,
120
- },
121
- headers: {
122
- type: datasource_1.DatasourceFieldTypes.OBJECT,
123
- },
124
- requestBody: {
125
- type: datasource_1.DatasourceFieldTypes.JSON,
126
- },
127
- },
92
+ fields: coreFields,
128
93
  },
129
94
  },
130
95
  };
131
96
  class RestIntegration {
132
97
  constructor(config) {
133
98
  this.headers = {};
99
+ this.startTimeMs = performance.now();
134
100
  this.config = config;
135
101
  }
136
102
  parseResponse(response) {
137
103
  return __awaiter(this, void 0, void 0, function* () {
104
+ let data, raw, headers;
138
105
  const contentType = response.headers.get("content-type");
139
106
  if (contentType && contentType.indexOf("application/json") !== -1) {
140
- return yield response.json();
107
+ data = yield response.json();
108
+ raw = JSON.stringify(data);
141
109
  }
142
110
  else {
143
- return yield response.text();
111
+ data = yield response.text();
112
+ raw = data;
144
113
  }
114
+ const size = formatBytes(response.headers.get("content-length") || Buffer.byteLength(raw, "utf8"));
115
+ const time = `${Math.round(performance.now() - this.startTimeMs)}ms`;
116
+ headers = response.headers.raw();
117
+ for (let [key, value] of Object.entries(headers)) {
118
+ headers[key] = Array.isArray(value) ? value[0] : value;
119
+ }
120
+ return {
121
+ data,
122
+ info: {
123
+ code: response.status,
124
+ size,
125
+ time,
126
+ },
127
+ extra: {
128
+ raw,
129
+ headers,
130
+ },
131
+ };
145
132
  });
146
133
  }
147
134
  getUrl(path, queryString) {
148
- return `${this.config.url}/${path}?${queryString}`;
135
+ const main = `${path}?${queryString}`;
136
+ let complete = main;
137
+ if (this.config.url && !main.startsWith(this.config.url)) {
138
+ complete = !this.config.url ? main : `${this.config.url}/${main}`;
139
+ }
140
+ if (!complete.startsWith("http")) {
141
+ complete = `http://${complete}`;
142
+ }
143
+ return complete;
149
144
  }
150
- create({ path = "", queryString = "", headers = {}, json = {} }) {
145
+ _req(query) {
151
146
  return __awaiter(this, void 0, void 0, function* () {
147
+ const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody } = query;
152
148
  this.headers = Object.assign(Object.assign({}, this.config.defaultHeaders), headers);
153
- const response = yield fetch(this.getUrl(path, queryString), {
154
- method: "POST",
155
- headers: this.headers,
156
- body: JSON.stringify(json),
157
- });
149
+ if (disabledHeaders) {
150
+ for (let headerKey of Object.keys(this.headers)) {
151
+ if (disabledHeaders[headerKey]) {
152
+ delete this.headers[headerKey];
153
+ }
154
+ }
155
+ }
156
+ let json;
157
+ if (bodyType === BodyTypes.JSON && requestBody) {
158
+ try {
159
+ json = JSON.parse(requestBody);
160
+ }
161
+ catch (err) {
162
+ throw "Invalid JSON for request body";
163
+ }
164
+ }
165
+ const input = { method, headers: this.headers };
166
+ if (json && typeof json === "object" && Object.keys(json).length > 0) {
167
+ input.body = JSON.stringify(json);
168
+ }
169
+ this.startTimeMs = performance.now();
170
+ const response = yield fetch(this.getUrl(path, queryString), input);
158
171
  return yield this.parseResponse(response);
159
172
  });
160
173
  }
161
- read({ path = "", queryString = "", headers = {} }) {
174
+ create(opts) {
162
175
  return __awaiter(this, void 0, void 0, function* () {
163
- this.headers = Object.assign(Object.assign({}, this.config.defaultHeaders), headers);
164
- const response = yield fetch(this.getUrl(path, queryString), {
165
- headers: this.headers,
166
- });
167
- return yield this.parseResponse(response);
176
+ return this._req(Object.assign(Object.assign({}, opts), { method: "POST" }));
168
177
  });
169
178
  }
170
- update({ path = "", queryString = "", headers = {}, json = {} }) {
179
+ read(opts) {
171
180
  return __awaiter(this, void 0, void 0, function* () {
172
- this.headers = Object.assign(Object.assign({}, this.config.defaultHeaders), headers);
173
- const response = yield fetch(this.getUrl(path, queryString), {
174
- method: "PUT",
175
- headers: this.headers,
176
- body: JSON.stringify(json),
177
- });
178
- return yield this.parseResponse(response);
181
+ return this._req(Object.assign(Object.assign({}, opts), { method: "GET" }));
179
182
  });
180
183
  }
181
- patch({ path = "", queryString = "", headers = {}, json = {} }) {
184
+ update(opts) {
182
185
  return __awaiter(this, void 0, void 0, function* () {
183
- this.headers = Object.assign(Object.assign({}, this.config.defaultHeaders), headers);
184
- const response = yield fetch(this.getUrl(path, queryString), {
185
- method: "PATCH",
186
- headers: this.headers,
187
- body: JSON.stringify(json),
188
- });
189
- return yield this.parseResponse(response);
186
+ return this._req(Object.assign(Object.assign({}, opts), { method: "PUT" }));
190
187
  });
191
188
  }
192
- delete({ path = "", queryString = "", headers = {} }) {
189
+ patch(opts) {
193
190
  return __awaiter(this, void 0, void 0, function* () {
194
- this.headers = Object.assign(Object.assign({}, this.config.defaultHeaders), headers);
195
- const response = yield fetch(this.getUrl(path, queryString), {
196
- method: "DELETE",
197
- headers: this.headers,
198
- });
199
- return yield this.parseResponse(response);
191
+ return this._req(Object.assign(Object.assign({}, opts), { method: "PATCH" }));
192
+ });
193
+ }
194
+ delete(opts) {
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ return this._req(Object.assign(Object.assign({}, opts), { method: "DELETE" }));
200
197
  });
201
198
  }
202
199
  }
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.0.18",
4
+ "version": "1.0.19-alpha.0",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -70,9 +70,9 @@
70
70
  "license": "GPL-3.0",
71
71
  "dependencies": {
72
72
  "@apidevtools/swagger-parser": "^10.0.3",
73
- "@budibase/auth": "^1.0.18",
74
- "@budibase/client": "^1.0.18",
75
- "@budibase/string-templates": "^1.0.18",
73
+ "@budibase/auth": "^1.0.19-alpha.0",
74
+ "@budibase/client": "^1.0.19-alpha.0",
75
+ "@budibase/string-templates": "^1.0.19-alpha.0",
76
76
  "@bull-board/api": "^3.7.0",
77
77
  "@bull-board/koa": "^3.7.0",
78
78
  "@elastic/elasticsearch": "7.10.0",
@@ -24,6 +24,12 @@ function formatResponse(resp) {
24
24
  }
25
25
  return resp;
26
26
  }
27
+ function hasExtraData(response) {
28
+ return (typeof response === "object" &&
29
+ !Array.isArray(response) &&
30
+ response.data != null &&
31
+ response.info != null);
32
+ }
27
33
  function runAndTransform(datasource, queryVerb, query, transformer) {
28
34
  return __awaiter(this, void 0, void 0, function* () {
29
35
  const Integration = integrations[datasource.source];
@@ -31,7 +37,13 @@ function runAndTransform(datasource, queryVerb, query, transformer) {
31
37
  throw "Integration type does not exist.";
32
38
  }
33
39
  const integration = new Integration(datasource.config);
34
- let rows = formatResponse(yield integration[queryVerb](query));
40
+ let output = formatResponse(yield integration[queryVerb](query));
41
+ let rows = output, info = undefined, extra = undefined;
42
+ if (hasExtraData(output)) {
43
+ rows = output.data;
44
+ info = output.info;
45
+ extra = output.extra;
46
+ }
35
47
  // transform as required
36
48
  if (transformer) {
37
49
  const runner = new ScriptRunner(transformer, { data: rows });
@@ -50,7 +62,7 @@ function runAndTransform(datasource, queryVerb, query, transformer) {
50
62
  if (integration.end) {
51
63
  integration.end();
52
64
  }
53
- return { rows, keys };
65
+ return { rows, keys, info, extra };
54
66
  });
55
67
  }
56
68
  module.exports = (input, callback) => {