@budibase/server 1.0.27-alpha.0 → 1.0.27

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 (234) hide show
  1. package/__mocks__/node-fetch.ts +0 -3
  2. package/builder/assets/{index.4a13c4cb.css → index.4fb3f887.css} +1 -1
  3. package/builder/assets/{index.e2f56628.js → index.593a5d3e.js} +204 -208
  4. package/builder/assets/{vendor.f9faf6ab.js → vendor.470042a4.js} +88 -88
  5. package/builder/index.html +3 -3
  6. package/coverage/clover.xml +512 -589
  7. package/coverage/coverage-final.json +19 -20
  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 +10 -22
  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 +14 -14
  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 +43 -28
  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.js.html → query.js.html} +27 -159
  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/index.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/internalSearch.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 +1 -1
  34. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/user.js.html +9 -108
  42. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  44. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  47. package/coverage/lcov-report/api/controllers/webhook.js.html +6 -18
  48. package/coverage/lcov-report/api/index.html +1 -1
  49. package/coverage/lcov-report/api/index.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/index.html +9 -9
  63. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/query.js.html +98 -11
  69. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/user.js.html +2 -32
  78. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  80. package/coverage/lcov-report/automations/actions.js.html +1 -1
  81. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  82. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  83. package/coverage/lcov-report/automations/index.html +20 -20
  84. package/coverage/lcov-report/automations/index.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/index.html +1 -1
  94. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -5
  96. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  99. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  100. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  101. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  102. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  108. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  109. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  110. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  111. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  112. package/coverage/lcov-report/automations/utils.js.html +11 -44
  113. package/coverage/lcov-report/constants/index.html +1 -1
  114. package/coverage/lcov-report/constants/index.js.html +22 -22
  115. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  116. package/coverage/lcov-report/constants/screens.js.html +1 -1
  117. package/coverage/lcov-report/db/client.js.html +18 -18
  118. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  119. package/coverage/lcov-report/db/index.html +15 -15
  120. package/coverage/lcov-report/db/index.js.html +3 -3
  121. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  122. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  123. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  124. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  125. package/coverage/lcov-report/db/newid.js.html +4 -4
  126. package/coverage/lcov-report/db/utils.js.html +64 -91
  127. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  128. package/coverage/lcov-report/events/index.html +1 -1
  129. package/coverage/lcov-report/events/index.js.html +1 -1
  130. package/coverage/lcov-report/events/utils.js.html +1 -1
  131. package/coverage/lcov-report/index.html +60 -75
  132. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  133. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  134. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  135. package/coverage/lcov-report/middleware/authorized.js.html +2 -2
  136. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  137. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  138. package/coverage/lcov-report/middleware/index.html +1 -1
  139. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  140. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  141. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  142. package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
  143. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  144. package/coverage/lcov-report/threads/automation.js.html +1 -1
  145. package/coverage/lcov-report/threads/index.html +19 -19
  146. package/coverage/lcov-report/threads/index.js.html +1 -1
  147. package/coverage/lcov-report/threads/query.js.html +12 -63
  148. package/coverage/lcov-report/threads/utils.js.html +1 -1
  149. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  150. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  151. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  152. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  153. package/coverage/lcov-report/utilities/global.js.html +1 -1
  154. package/coverage/lcov-report/utilities/index.html +19 -19
  155. package/coverage/lcov-report/utilities/index.js.html +33 -66
  156. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  157. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  158. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  159. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  160. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  161. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  162. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  163. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  164. package/coverage/lcov-report/utilities/security.js.html +2 -2
  165. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  166. package/coverage/lcov-report/utilities/users.js.html +1 -1
  167. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  168. package/coverage/lcov.info +851 -969
  169. package/dist/api/controllers/automation.js +5 -7
  170. package/dist/api/controllers/{query/index.js → query.js} +6 -42
  171. package/dist/api/controllers/user.js +1 -37
  172. package/dist/api/controllers/webhook.js +0 -4
  173. package/dist/api/routes/query.js +32 -2
  174. package/dist/api/routes/user.js +1 -3
  175. package/dist/automations/steps/outgoingWebhook.js +3 -2
  176. package/dist/automations/utils.js +0 -10
  177. package/dist/db/utils.js +0 -8
  178. package/dist/definitions/datasource.js +1 -6
  179. package/dist/integrations/rest.js +117 -207
  180. package/dist/package.json +0 -6
  181. package/dist/threads/query.js +2 -14
  182. package/dist/tsconfig.tsbuildinfo +1 -1
  183. package/dist/utilities/index.js +0 -10
  184. package/package.json +5 -11
  185. package/src/api/controllers/automation.js +4 -8
  186. package/src/api/controllers/{query/index.js → query.js} +6 -50
  187. package/src/api/controllers/user.js +0 -33
  188. package/src/api/controllers/webhook.js +0 -4
  189. package/src/api/routes/query.js +34 -5
  190. package/src/api/routes/user.js +0 -10
  191. package/src/automations/steps/outgoingWebhook.js +3 -2
  192. package/src/automations/utils.js +0 -11
  193. package/src/db/utils.js +0 -9
  194. package/src/definitions/common.ts +16 -2
  195. package/src/definitions/datasource.ts +1 -73
  196. package/src/integrations/base/IntegrationBase.ts +4 -4
  197. package/src/integrations/oracle.ts +1 -1
  198. package/src/integrations/rest.ts +137 -227
  199. package/src/integrations/tests/rest.spec.js +19 -167
  200. package/src/threads/query.js +2 -19
  201. package/src/utilities/index.js +0 -11
  202. package/builder/assets/bb-spaceship.8f6e81e1.svg +0 -227
  203. package/coverage/lcov-report/api/controllers/query/index.html +0 -126
  204. package/coverage/lcov-report/api/controllers/query/validation.js.html +0 -203
  205. package/dist/api/controllers/query/import/index.js +0 -79
  206. package/dist/api/controllers/query/import/sources/base/index.js +0 -63
  207. package/dist/api/controllers/query/import/sources/base/openapi.js +0 -42
  208. package/dist/api/controllers/query/import/sources/curl.js +0 -90
  209. package/dist/api/controllers/query/import/sources/openapi2.js +0 -139
  210. package/dist/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +0 -253
  211. package/dist/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +0 -1054
  212. package/dist/api/controllers/query/validation.js +0 -37
  213. package/src/api/controllers/query/import/index.ts +0 -85
  214. package/src/api/controllers/query/import/sources/base/index.ts +0 -85
  215. package/src/api/controllers/query/import/sources/base/openapi.ts +0 -24
  216. package/src/api/controllers/query/import/sources/curl.ts +0 -94
  217. package/src/api/controllers/query/import/sources/openapi2.ts +0 -159
  218. package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +0 -104
  219. package/src/api/controllers/query/import/sources/tests/curl/data/delete.txt +0 -1
  220. package/src/api/controllers/query/import/sources/tests/curl/data/empty-body.txt +0 -2
  221. package/src/api/controllers/query/import/sources/tests/curl/data/get.txt +0 -1
  222. package/src/api/controllers/query/import/sources/tests/curl/data/headers.txt +0 -3
  223. package/src/api/controllers/query/import/sources/tests/curl/data/patch.txt +0 -2
  224. package/src/api/controllers/query/import/sources/tests/curl/data/path.txt +0 -1
  225. package/src/api/controllers/query/import/sources/tests/curl/data/post.txt +0 -2
  226. package/src/api/controllers/query/import/sources/tests/curl/data/put.txt +0 -2
  227. package/src/api/controllers/query/import/sources/tests/curl/data/query.txt +0 -1
  228. package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +0 -253
  229. package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.yaml +0 -160
  230. package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +0 -1054
  231. package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.yaml +0 -711
  232. package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +0 -239
  233. package/src/api/controllers/query/import/tests/index.spec.js +0 -115
  234. package/src/api/controllers/query/validation.js +0 -41
@@ -1,37 +0,0 @@
1
- "use strict";
2
- const joiValidator = require("../../../middleware/joi-validator");
3
- const Joi = require("joi");
4
- exports.queryValidation = () => {
5
- return Joi.object({
6
- _id: Joi.string(),
7
- _rev: Joi.string(),
8
- name: Joi.string().required(),
9
- fields: Joi.object().required(),
10
- datasourceId: Joi.string().required(),
11
- readable: Joi.boolean(),
12
- parameters: Joi.array().items(Joi.object({
13
- name: Joi.string(),
14
- default: Joi.string().allow(""),
15
- })),
16
- queryVerb: Joi.string().allow().required(),
17
- extra: Joi.object().optional(),
18
- schema: Joi.object({}).required().unknown(true),
19
- transformer: Joi.string().optional(),
20
- flags: Joi.object().optional(),
21
- });
22
- };
23
- exports.generateQueryValidation = () => {
24
- // prettier-ignore
25
- return joiValidator.body(exports.queryValidation());
26
- };
27
- exports.generateQueryPreviewValidation = () => {
28
- // prettier-ignore
29
- return joiValidator.body(Joi.object({
30
- fields: Joi.object().required(),
31
- queryVerb: Joi.string().allow().required(),
32
- extra: Joi.object().optional(),
33
- datasourceId: Joi.string().required(),
34
- transformer: Joi.string().optional(),
35
- parameters: Joi.object({}).required().unknown(true)
36
- }));
37
- };
@@ -1,85 +0,0 @@
1
- import CouchDB from "../../../../db"
2
- import { queryValidation } from "../validation"
3
- import { generateQueryID } from "../../../../db/utils"
4
- import { ImportInfo, ImportSource } from "./sources/base"
5
- import { OpenAPI2 } from "./sources/openapi2"
6
- import { Query } from "./../../../../definitions/common"
7
- import { Curl } from "./sources/curl"
8
- interface ImportResult {
9
- errorQueries: Query[]
10
- queries: Query[]
11
- }
12
-
13
- export class RestImporter {
14
- data: string
15
- sources: ImportSource[]
16
- source!: ImportSource
17
-
18
- constructor(data: string) {
19
- this.data = data
20
- this.sources = [new OpenAPI2(), new Curl()]
21
- }
22
-
23
- init = async () => {
24
- for (let source of this.sources) {
25
- if (await source.isSupported(this.data)) {
26
- this.source = source
27
- break
28
- }
29
- }
30
- }
31
-
32
- getInfo = async (): Promise<ImportInfo> => {
33
- return this.source.getInfo()
34
- }
35
-
36
- importQueries = async (
37
- appId: string,
38
- datasourceId: string
39
- ): Promise<ImportResult> => {
40
- // constuct the queries
41
- let queries = await this.source.getQueries(datasourceId)
42
-
43
- // validate queries
44
- const errorQueries: Query[] = []
45
- const schema = queryValidation()
46
- queries = queries
47
- .filter(query => {
48
- const validation = schema.validate(query)
49
- if (validation.error) {
50
- errorQueries.push(query)
51
- return false
52
- }
53
- return true
54
- })
55
- .map(query => {
56
- query._id = generateQueryID(query.datasourceId)
57
- return query
58
- })
59
-
60
- // persist queries
61
- const db = new CouchDB(appId)
62
- const response = await db.bulkDocs(queries)
63
-
64
- // create index to seperate queries and errors
65
- const queryIndex = queries.reduce((acc, query) => {
66
- if (query._id) {
67
- acc[query._id] = query
68
- }
69
- return acc
70
- }, {} as { [key: string]: Query })
71
-
72
- // check for failed writes
73
- response.forEach((query: any) => {
74
- if (!query.ok) {
75
- errorQueries.push(queryIndex[query.id])
76
- delete queryIndex[query.id]
77
- }
78
- })
79
-
80
- return {
81
- errorQueries,
82
- queries: Object.values(queryIndex),
83
- }
84
- }
85
- }
@@ -1,85 +0,0 @@
1
- import { Query, QueryParameter } from "../../../../../../definitions/datasource"
2
-
3
- export interface ImportInfo {
4
- url: string
5
- name: string
6
- }
7
-
8
- enum MethodToVerb {
9
- get = "read",
10
- post = "create",
11
- put = "update",
12
- patch = "patch",
13
- delete = "delete",
14
- }
15
-
16
- export abstract class ImportSource {
17
- abstract isSupported(data: string): Promise<boolean>
18
- abstract getInfo(): Promise<ImportInfo>
19
- abstract getQueries(datasourceId: string): Promise<Query[]>
20
-
21
- constructQuery = (
22
- datasourceId: string,
23
- name: string,
24
- method: string,
25
- path: string,
26
- queryString: string,
27
- headers: object = {},
28
- parameters: QueryParameter[] = [],
29
- body: object | undefined = undefined
30
- ): Query => {
31
- const readable = true
32
- const queryVerb = this.verbFromMethod(method)
33
- const transformer = "return data"
34
- const schema = {}
35
- path = this.processPath(path)
36
- queryString = this.processQuery(queryString)
37
- const requestBody = JSON.stringify(body, null, 2)
38
-
39
- const query: Query = {
40
- datasourceId,
41
- name,
42
- parameters,
43
- fields: {
44
- headers,
45
- queryString,
46
- path,
47
- requestBody,
48
- },
49
- transformer,
50
- schema,
51
- readable,
52
- queryVerb,
53
- }
54
-
55
- return query
56
- }
57
-
58
- verbFromMethod = (method: string) => {
59
- const verb = (<any>MethodToVerb)[method]
60
- if (!verb) {
61
- throw new Error(`Unsupported method: ${method}`)
62
- }
63
- return verb
64
- }
65
-
66
- processPath = (path: string): string => {
67
- if (path?.startsWith("/")) {
68
- path = path.substring(1)
69
- }
70
-
71
- // add extra braces around params for binding
72
- path = path.replace(/[{]/g, "{{")
73
- path = path.replace(/[}]/g, "}}")
74
-
75
- return path
76
- }
77
-
78
- processQuery = (queryString: string): string => {
79
- if (queryString?.startsWith("?")) {
80
- return queryString.substring(1)
81
- }
82
-
83
- return queryString
84
- }
85
- }
@@ -1,24 +0,0 @@
1
- import { ImportSource } from "."
2
- import SwaggerParser from "@apidevtools/swagger-parser"
3
- import { OpenAPI } from "openapi-types"
4
- const yaml = require("js-yaml")
5
-
6
- export abstract class OpenAPISource extends ImportSource {
7
- parseData = async (data: string): Promise<OpenAPI.Document> => {
8
- let json: OpenAPI.Document
9
- try {
10
- json = JSON.parse(data)
11
- } catch (jsonErr) {
12
- // couldn't parse json
13
- // try to convert yaml -> json
14
- try {
15
- json = yaml.load(data)
16
- } catch (yamlErr) {
17
- // couldn't parse yaml
18
- throw new Error("Could not parse JSON or YAML")
19
- }
20
- }
21
-
22
- return SwaggerParser.validate(json, {})
23
- }
24
- }
@@ -1,94 +0,0 @@
1
- import { ImportSource, ImportInfo } from "./base"
2
- import { Query } from "../../../../../definitions/common"
3
- import { URL } from "url"
4
- const curlconverter = require("curlconverter")
5
-
6
- const parseCurl = (data: string): any => {
7
- const curlJson = curlconverter.toJsonString(data)
8
- return JSON.parse(curlJson)
9
- }
10
-
11
- /**
12
- * The curl converter parses the request body into the key field of an object
13
- * e.g. --d '{"key":"val"}' produces an object { "{"key":"val"}" : "" }
14
- * This is not what we want, so we need to parse out the key from the object
15
- */
16
- const parseBody = (curl: any) => {
17
- if (curl.data) {
18
- const keys = Object.keys(curl.data)
19
- if (keys.length) {
20
- const key = keys[0]
21
- try {
22
- return JSON.parse(key)
23
- } catch (e) {
24
- // do nothing
25
- }
26
- }
27
- }
28
- return undefined
29
- }
30
-
31
- const parseCookie = (curl: any) => {
32
- if (curl.cookies) {
33
- return Object.entries(curl.cookies).reduce((acc, entry) => {
34
- const [key, value] = entry
35
- return acc + `${key}=${value}; `
36
- }, "")
37
- }
38
-
39
- return null
40
- }
41
-
42
- /**
43
- * Curl
44
- * https://curl.se/docs/manpage.html
45
- */
46
- export class Curl extends ImportSource {
47
- curl: any
48
-
49
- isSupported = async (data: string): Promise<boolean> => {
50
- try {
51
- const curl = parseCurl(data)
52
- this.curl = curl
53
- } catch (err) {
54
- return false
55
- }
56
- return true
57
- }
58
-
59
- getInfo = async (): Promise<ImportInfo> => {
60
- const url = new URL(this.curl.url)
61
- return {
62
- url: url.origin,
63
- name: url.hostname,
64
- }
65
- }
66
-
67
- getQueries = async (datasourceId: string): Promise<Query[]> => {
68
- const url = new URL(this.curl.raw_url)
69
- const name = url.pathname
70
- const path = url.pathname
71
- const method = this.curl.method
72
- const queryString = url.search
73
- const headers = this.curl.headers
74
- const requestBody = parseBody(this.curl)
75
-
76
- const cookieHeader = parseCookie(this.curl)
77
- if (cookieHeader) {
78
- headers["Cookie"] = cookieHeader
79
- }
80
-
81
- const query = this.constructQuery(
82
- datasourceId,
83
- name,
84
- method,
85
- path,
86
- queryString,
87
- headers,
88
- [],
89
- requestBody
90
- )
91
-
92
- return [query]
93
- }
94
- }
@@ -1,159 +0,0 @@
1
- import { ImportInfo } from "./base"
2
- import { Query, QueryParameter } from "../../../../../definitions/datasource"
3
- import { OpenAPIV2 } from "openapi-types"
4
- import { OpenAPISource } from "./base/openapi"
5
-
6
- const parameterNotRef = (
7
- param: OpenAPIV2.Parameter | OpenAPIV2.ReferenceObject
8
- ): param is OpenAPIV2.Parameter => {
9
- // all refs are deferenced by parser library
10
- return true
11
- }
12
-
13
- const isOpenAPI2 = (document: any): document is OpenAPIV2.Document => {
14
- if (document.swagger === "2.0") {
15
- return true
16
- } else {
17
- return false
18
- }
19
- }
20
-
21
- const methods: string[] = Object.values(OpenAPIV2.HttpMethods)
22
-
23
- const isOperation = (
24
- key: string,
25
- pathItem: any
26
- ): pathItem is OpenAPIV2.OperationObject => {
27
- return methods.includes(key)
28
- }
29
-
30
- const isParameter = (
31
- key: string,
32
- pathItem: any
33
- ): pathItem is OpenAPIV2.Parameter => {
34
- return !isOperation(key, pathItem)
35
- }
36
-
37
- /**
38
- * OpenAPI Version 2.0 - aka "Swagger"
39
- * https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md
40
- */
41
- export class OpenAPI2 extends OpenAPISource {
42
- document!: OpenAPIV2.Document
43
-
44
- isSupported = async (data: string): Promise<boolean> => {
45
- try {
46
- const document: any = await this.parseData(data)
47
- if (isOpenAPI2(document)) {
48
- this.document = document
49
- return true
50
- } else {
51
- return false
52
- }
53
- } catch (err) {
54
- return false
55
- }
56
- }
57
-
58
- getInfo = async (): Promise<ImportInfo> => {
59
- const scheme = this.document.schemes?.includes("https") ? "https" : "http"
60
- const basePath = this.document.basePath || ""
61
- const host = this.document.host || "<host>"
62
- const url = `${scheme}://${host}${basePath}`
63
- const name = this.document.info.title || "Swagger Import"
64
-
65
- return {
66
- url: url,
67
- name: name,
68
- }
69
- }
70
-
71
- getQueries = async (datasourceId: string): Promise<Query[]> => {
72
- const queries = []
73
-
74
- for (let [path, pathItem] of Object.entries(this.document.paths)) {
75
- // parameters that apply to every operation in the path
76
- let pathParams: OpenAPIV2.Parameter[] = []
77
-
78
- for (let [key, opOrParams] of Object.entries(pathItem)) {
79
- if (isParameter(key, opOrParams)) {
80
- const pathParameters = opOrParams as OpenAPIV2.Parameter[]
81
- pathParams.push(...pathParameters)
82
- continue
83
- }
84
- // can not be a parameter, must be an operation
85
- const operation = opOrParams as OpenAPIV2.OperationObject
86
-
87
- const methodName = key
88
- const name = operation.operationId || path
89
- let queryString = ""
90
- const headers: any = {}
91
- let requestBody = undefined
92
- const parameters: QueryParameter[] = []
93
-
94
- if (operation.consumes) {
95
- headers["Content-Type"] = operation.consumes[0]
96
- }
97
-
98
- // combine the path parameters with the operation parameters
99
- const operationParams = operation.parameters || []
100
- const allParams = [...pathParams, ...operationParams]
101
-
102
- for (let param of allParams) {
103
- if (parameterNotRef(param)) {
104
- switch (param.in) {
105
- case "query":
106
- let prefix = ""
107
- if (queryString) {
108
- prefix = "&"
109
- }
110
- queryString = `${queryString}${prefix}${param.name}={{${param.name}}}`
111
- break
112
- case "header":
113
- headers[param.name] = `{{${param.name}}}`
114
- break
115
- case "path":
116
- // do nothing: param is already in the path
117
- break
118
- case "formData":
119
- // future enhancement
120
- break
121
- case "body":
122
- // set the request body to the example provided
123
- // future enhancement: generate an example from the schema
124
- let bodyParam: OpenAPIV2.InBodyParameterObject =
125
- param as OpenAPIV2.InBodyParameterObject
126
- if (param.schema.example) {
127
- const schema = bodyParam.schema as OpenAPIV2.SchemaObject
128
- requestBody = schema.example
129
- }
130
- break
131
- }
132
-
133
- // add the parameter if it can be bound in our config
134
- if (["query", "header", "path"].includes(param.in)) {
135
- parameters.push({
136
- name: param.name,
137
- default: param.default || "",
138
- })
139
- }
140
- }
141
- }
142
-
143
- const query = this.constructQuery(
144
- datasourceId,
145
- name,
146
- methodName,
147
- path,
148
- queryString,
149
- headers,
150
- parameters,
151
- requestBody
152
- )
153
- queries.push(query)
154
- }
155
- }
156
-
157
- return queries
158
- }
159
- }
@@ -1,104 +0,0 @@
1
- const { Curl } = require("../../curl")
2
- const fs = require("fs")
3
- const path = require('path')
4
-
5
- const getData = (file) => {
6
- return fs.readFileSync(path.join(__dirname, `./data/${file}.txt`), "utf8")
7
- }
8
-
9
- describe("Curl Import", () => {
10
- let curl
11
-
12
- beforeEach(() => {
13
- curl = new Curl()
14
- })
15
-
16
- it("validates unsupported data", async () => {
17
- let data
18
- let supported
19
-
20
- // JSON
21
- data = "{}"
22
- supported = await curl.isSupported(data)
23
- expect(supported).toBe(false)
24
-
25
- // Empty
26
- data = ""
27
- supported = await curl.isSupported(data)
28
- expect(supported).toBe(false)
29
- })
30
-
31
- const init = async (file) => {
32
- await curl.isSupported(getData(file))
33
- }
34
-
35
- it("returns import info", async () => {
36
- await init("get")
37
- const info = await curl.getInfo()
38
- expect(info.url).toBe("http://example.com")
39
- expect(info.name).toBe("example.com")
40
- })
41
-
42
- describe("Returns queries", () => {
43
-
44
- const getQueries = async (file) => {
45
- await init(file)
46
- const queries = await curl.getQueries()
47
- expect(queries.length).toBe(1)
48
- return queries
49
- }
50
-
51
- const testVerb = async (file, verb) => {
52
- const queries = await getQueries(file)
53
- expect(queries[0].queryVerb).toBe(verb)
54
- }
55
-
56
- it("populates verb", async () => {
57
- await testVerb("get", "read")
58
- await testVerb("post", "create")
59
- await testVerb("put", "update")
60
- await testVerb("delete", "delete")
61
- await testVerb("patch", "patch")
62
- })
63
-
64
- const testPath = async (file, urlPath) => {
65
- const queries = await getQueries(file)
66
- expect(queries[0].fields.path).toBe(urlPath)
67
- }
68
-
69
- it("populates path", async () => {
70
- await testPath("get", "")
71
- await testPath("path", "paths/abc")
72
- })
73
-
74
- const testHeaders = async (file, headers) => {
75
- const queries = await getQueries(file)
76
- expect(queries[0].fields.headers).toStrictEqual(headers)
77
- }
78
-
79
- it("populates headers", async () => {
80
- await testHeaders("get", {})
81
- await testHeaders("headers", { "x-bb-header-1" : "123", "x-bb-header-2" : "456"} )
82
- })
83
-
84
- const testQuery = async (file, queryString) => {
85
- const queries = await getQueries(file)
86
- expect(queries[0].fields.queryString).toBe(queryString)
87
- }
88
- it("populates query", async () => {
89
- await testQuery("get", "")
90
- await testQuery("query", "q1=v1&q1=v2")
91
- })
92
-
93
- const testBody = async (file, body) => {
94
- const queries = await getQueries(file)
95
- expect(queries[0].fields.requestBody).toStrictEqual(JSON.stringify(body, null, 2))
96
- }
97
-
98
- it("populates body", async () => {
99
- await testBody("get", undefined)
100
- await testBody("post", { "key" : "val" })
101
- await testBody("empty-body", {})
102
- })
103
- })
104
- })
@@ -1 +0,0 @@
1
- curl -X DELETE 'http://example.com'
@@ -1,2 +0,0 @@
1
- curl -X POST 'http://example.com' \
2
- --data-raw '{}'
@@ -1 +0,0 @@
1
- curl 'http://example.com'
@@ -1,3 +0,0 @@
1
- curl 'http://example.com' \
2
- -H 'x-bb-header-1: 123' \
3
- -H 'x-bb-header-2: 456'
@@ -1,2 +0,0 @@
1
- curl -X PATCH 'http://example.com/paths/abc' \
2
- --data-raw '{ "key" : "val" }'
@@ -1 +0,0 @@
1
- curl 'http://example.com/paths/abc'
@@ -1,2 +0,0 @@
1
- curl -X POST 'http://example.com' \
2
- --data-raw '{ "key" : "val" }'
@@ -1,2 +0,0 @@
1
- curl -X PUT 'http://example.com/paths/abc' \
2
- --data-raw '{ "key" : "val" }'
@@ -1 +0,0 @@
1
- curl 'http://example.com/paths/abc?q1=v1&q1=v2'