@budibase/server 1.0.35 → 1.0.39
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.
- package/__mocks__/node-fetch.ts +21 -0
- package/builder/assets/bb-spaceship.8f6e81e1.svg +227 -0
- package/builder/assets/index.3079d0f9.js +1348 -0
- package/builder/assets/{index.4fb3f887.css → index.39e01193.css} +1 -1
- package/builder/assets/{vendor.470042a4.js → vendor.f9faf6ab.js} +88 -88
- package/builder/index.html +3 -3
- package/coverage/clover.xml +1589 -1344
- package/coverage/coverage-final.json +75 -74
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +3 -3
- package/coverage/lcov-report/api/controllers/application.js.html +73 -64
- package/coverage/lcov-report/api/controllers/auth.js.html +2 -2
- package/coverage/lcov-report/api/controllers/automation.js.html +22 -10
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +13 -4
- package/coverage/lcov-report/api/controllers/component.js.html +4 -4
- package/coverage/lcov-report/api/controllers/datasource.js.html +170 -68
- package/coverage/lcov-report/api/controllers/dev.js.html +3 -3
- package/coverage/lcov-report/api/controllers/hosting.js.html +3 -3
- package/coverage/lcov-report/api/controllers/index.html +39 -54
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +3 -3
- package/coverage/lcov-report/api/controllers/query/index.html +126 -0
- package/coverage/lcov-report/api/controllers/{query.js.html → query/index.js.html} +225 -120
- package/coverage/lcov-report/api/controllers/query/validation.js.html +206 -0
- package/coverage/lcov-report/api/controllers/role.js.html +2 -2
- package/coverage/lcov-report/api/controllers/routing.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +22 -22
- package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +38 -11
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +8 -5
- package/coverage/lcov-report/api/controllers/row/utils.js.html +29 -20
- package/coverage/lcov-report/api/controllers/screen.js.html +2 -2
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +120 -12
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +19 -7
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +6 -6
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +2 -2
- package/coverage/lcov-report/api/routes/application.js.html +2 -2
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +2 -2
- package/coverage/lcov-report/api/routes/backup.js.html +2 -2
- package/coverage/lcov-report/api/routes/cloud.js.html +2 -2
- package/coverage/lcov-report/api/routes/component.js.html +2 -2
- package/coverage/lcov-report/api/routes/datasource.js.html +2 -2
- package/coverage/lcov-report/api/routes/deploy.js.html +2 -2
- package/coverage/lcov-report/api/routes/dev.js.html +2 -2
- package/coverage/lcov-report/api/routes/hosting.js.html +2 -2
- package/coverage/lcov-report/api/routes/index.html +9 -9
- package/coverage/lcov-report/api/routes/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +2 -2
- package/coverage/lcov-report/api/routes/layout.js.html +2 -2
- package/coverage/lcov-report/api/routes/metadata.js.html +2 -2
- package/coverage/lcov-report/api/routes/permission.js.html +12 -3
- package/coverage/lcov-report/api/routes/query.js.html +20 -86
- package/coverage/lcov-report/api/routes/role.js.html +2 -2
- package/coverage/lcov-report/api/routes/routing.js.html +2 -2
- package/coverage/lcov-report/api/routes/row.js.html +2 -2
- package/coverage/lcov-report/api/routes/screen.js.html +2 -2
- package/coverage/lcov-report/api/routes/script.js.html +2 -2
- package/coverage/lcov-report/api/routes/static.js.html +2 -2
- package/coverage/lcov-report/api/routes/table.js.html +2 -2
- package/coverage/lcov-report/api/routes/templates.js.html +2 -2
- package/coverage/lcov-report/api/routes/user.js.html +33 -3
- package/coverage/lcov-report/api/routes/view.js.html +2 -2
- package/coverage/lcov-report/api/routes/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +2 -2
- package/coverage/lcov-report/automations/index.html +20 -20
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +32 -8
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +11 -11
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +5 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/automations/utils.js.html +49 -16
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +25 -25
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +2 -2
- package/coverage/lcov-report/db/client.js.html +19 -19
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +108 -81
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +99 -84
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +12 -12
- package/coverage/lcov-report/middleware/builder.js.html +10 -10
- package/coverage/lcov-report/middleware/currentapp.js.html +48 -36
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +11 -11
- package/coverage/lcov-report/middleware/resourceId.js.html +18 -18
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +2 -2
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +3 -3
- package/coverage/lcov-report/threads/index.html +32 -32
- package/coverage/lcov-report/threads/index.js.html +12 -12
- package/coverage/lcov-report/threads/query.js.html +560 -65
- package/coverage/lcov-report/threads/utils.js.html +210 -15
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +2 -2
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +28 -19
- package/coverage/lcov-report/utilities/index.html +19 -19
- package/coverage/lcov-report/utilities/index.js.html +70 -37
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +19 -19
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +247 -10
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +14 -5
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +22 -22
- package/coverage/lcov.info +2735 -2313
- package/dist/api/controllers/apikeys.js +2 -2
- package/dist/api/controllers/application.js +4 -4
- package/dist/api/controllers/auth.js +1 -1
- package/dist/api/controllers/automation.js +7 -5
- package/dist/api/controllers/cloud.js +2 -2
- package/dist/api/controllers/datasource.js +29 -0
- package/dist/api/controllers/deploy/index.js +2 -2
- package/dist/api/controllers/dev.js +2 -2
- package/dist/api/controllers/hosting.js +2 -2
- package/dist/api/controllers/permission.js +2 -2
- package/dist/api/controllers/query/import/index.js +79 -0
- package/dist/api/controllers/query/import/sources/base/index.js +64 -0
- package/dist/api/controllers/query/import/sources/base/openapi.js +42 -0
- package/dist/api/controllers/query/import/sources/curl.js +96 -0
- package/dist/api/controllers/query/import/sources/openapi2.js +142 -0
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
- package/dist/api/controllers/{query.js → query/index.js} +88 -56
- package/dist/api/controllers/query/validation.js +38 -0
- package/dist/api/controllers/role.js +1 -1
- package/dist/api/controllers/routing.js +1 -1
- package/dist/api/controllers/row/internal.js +14 -6
- package/dist/api/controllers/row/internalSearch.js +3 -2
- package/dist/api/controllers/row/utils.js +13 -6
- package/dist/api/controllers/screen.js +1 -1
- package/dist/api/controllers/user.js +40 -4
- package/dist/api/controllers/webhook.js +5 -1
- package/dist/api/index.js +1 -1
- package/dist/api/routes/apikeys.js +1 -1
- package/dist/api/routes/application.js +1 -1
- package/dist/api/routes/automation.js +1 -1
- package/dist/api/routes/backup.js +1 -1
- package/dist/api/routes/cloud.js +1 -1
- package/dist/api/routes/component.js +1 -1
- package/dist/api/routes/datasource.js +1 -1
- package/dist/api/routes/deploy.js +1 -1
- package/dist/api/routes/dev.js +1 -1
- package/dist/api/routes/hosting.js +1 -1
- package/dist/api/routes/integration.js +1 -1
- package/dist/api/routes/layout.js +1 -1
- package/dist/api/routes/metadata.js +1 -1
- package/dist/api/routes/permission.js +1 -1
- package/dist/api/routes/query.js +6 -34
- package/dist/api/routes/role.js +1 -1
- package/dist/api/routes/routing.js +1 -1
- package/dist/api/routes/row.js +1 -1
- package/dist/api/routes/screen.js +1 -1
- package/dist/api/routes/script.js +1 -1
- package/dist/api/routes/static.js +1 -1
- package/dist/api/routes/table.js +1 -1
- package/dist/api/routes/templates.js +1 -1
- package/dist/api/routes/tests/utilities/TestFunctions.js +1 -1
- package/dist/api/routes/user.js +4 -2
- package/dist/api/routes/view.js +1 -1
- package/dist/api/routes/webhook.js +1 -1
- package/dist/app.js +1 -1
- package/dist/automations/bullboard.js +1 -1
- package/dist/automations/steps/executeQuery.js +9 -2
- package/dist/automations/steps/outgoingWebhook.js +2 -3
- package/dist/automations/utils.js +11 -1
- package/dist/constants/index.js +3 -3
- package/dist/constants/screens.js +1 -1
- package/dist/db/client.js +1 -1
- package/dist/db/utils.js +9 -1
- package/dist/definitions/datasource.js +6 -1
- package/dist/integrations/base/sqlTable.js +1 -1
- package/dist/integrations/rest.js +259 -120
- package/dist/integrations/utils.js +40 -37
- package/dist/middleware/authorized.js +2 -2
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +6 -6
- package/dist/middleware/usageQuota.js +1 -1
- package/dist/package.json +11 -4
- package/dist/tests/utilities/TestConfiguration.js +55 -8
- package/dist/tests/utilities/structures.js +2 -2
- package/dist/threads/automation.js +2 -2
- package/dist/threads/query.js +195 -38
- package/dist/threads/utils.js +62 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/budibaseDir.js +1 -1
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/dist/utilities/global.js +5 -5
- package/dist/utilities/index.js +11 -1
- package/dist/utilities/redis.js +1 -1
- package/dist/utilities/rowProcessor/index.js +76 -0
- package/dist/utilities/security.js +2 -2
- package/dist/utilities/usageQuota.js +2 -2
- package/dist/utilities/workerRequests.js +3 -3
- package/package.json +12 -5
- package/scripts/replicateApp.js +1 -1
- package/src/api/controllers/apikeys.js +2 -2
- package/src/api/controllers/application.js +7 -4
- package/src/api/controllers/auth.js +1 -1
- package/src/api/controllers/automation.js +8 -4
- package/src/api/controllers/cloud.js +5 -2
- package/src/api/controllers/datasource.js +34 -0
- package/src/api/controllers/deploy/index.js +2 -2
- package/src/api/controllers/dev.js +2 -2
- package/src/api/controllers/hosting.js +2 -2
- package/src/api/controllers/permission.js +2 -2
- package/src/api/controllers/query/import/index.ts +85 -0
- package/src/api/controllers/query/import/sources/base/index.ts +87 -0
- package/src/api/controllers/query/import/sources/base/openapi.ts +24 -0
- package/src/api/controllers/query/import/sources/curl.ts +102 -0
- package/src/api/controllers/query/import/sources/openapi2.ts +163 -0
- package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +103 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/delete.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/empty-body.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/get.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/headers.txt +3 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/patch.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/path.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/post.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/put.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/query.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.yaml +160 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.yaml +711 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +238 -0
- package/src/api/controllers/query/import/tests/index.spec.js +109 -0
- package/src/api/controllers/query/index.js +196 -0
- package/src/api/controllers/query/validation.js +42 -0
- package/src/api/controllers/role.js +1 -1
- package/src/api/controllers/routing.js +1 -1
- package/src/api/controllers/row/internal.js +14 -5
- package/src/api/controllers/row/internalSearch.js +3 -2
- package/src/api/controllers/row/utils.js +11 -8
- package/src/api/controllers/screen.js +1 -1
- package/src/api/controllers/user.js +39 -3
- package/src/api/controllers/webhook.js +5 -1
- package/src/api/index.js +1 -1
- package/src/api/routes/apikeys.js +1 -1
- package/src/api/routes/application.js +1 -1
- package/src/api/routes/automation.js +1 -1
- package/src/api/routes/backup.js +1 -1
- package/src/api/routes/cloud.js +1 -1
- package/src/api/routes/component.js +1 -1
- package/src/api/routes/datasource.js +1 -1
- package/src/api/routes/deploy.js +1 -1
- package/src/api/routes/dev.js +1 -1
- package/src/api/routes/hosting.js +1 -1
- package/src/api/routes/integration.js +1 -1
- package/src/api/routes/layout.js +1 -1
- package/src/api/routes/metadata.js +1 -1
- package/src/api/routes/permission.js +4 -1
- package/src/api/routes/query.js +14 -36
- package/src/api/routes/role.js +1 -1
- package/src/api/routes/routing.js +1 -1
- package/src/api/routes/row.js +1 -1
- package/src/api/routes/screen.js +1 -1
- package/src/api/routes/script.js +1 -1
- package/src/api/routes/static.js +1 -1
- package/src/api/routes/table.js +1 -1
- package/src/api/routes/templates.js +1 -1
- package/src/api/routes/tests/datasource.spec.js +45 -0
- package/src/api/routes/tests/permissions.spec.js +1 -1
- package/src/api/routes/tests/query.spec.js +70 -1
- package/src/api/routes/tests/role.spec.js +2 -2
- package/src/api/routes/tests/routing.spec.js +1 -1
- package/src/api/routes/tests/user.spec.js +1 -1
- package/src/api/routes/tests/utilities/TestFunctions.js +1 -1
- package/src/api/routes/user.js +11 -1
- package/src/api/routes/view.js +1 -1
- package/src/api/routes/webhook.js +1 -1
- package/src/app.ts +1 -1
- package/src/automations/bullboard.js +1 -1
- package/src/automations/steps/executeQuery.js +10 -2
- package/src/automations/steps/outgoingWebhook.js +2 -3
- package/src/automations/utils.js +12 -1
- package/src/constants/index.js +3 -3
- package/src/constants/screens.js +1 -1
- package/src/db/client.js +1 -1
- package/src/db/utils.js +10 -1
- package/src/definitions/common.ts +2 -16
- package/src/definitions/datasource.ts +98 -1
- package/src/integrations/base/IntegrationBase.ts +4 -4
- package/src/integrations/base/sqlTable.ts +1 -1
- package/src/integrations/rest.ts +311 -138
- package/src/integrations/tests/rest.spec.js +432 -21
- package/src/integrations/utils.ts +8 -7
- package/src/middleware/authorized.js +2 -2
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +11 -7
- package/src/middleware/tests/authorized.spec.js +2 -2
- package/src/middleware/tests/currentapp.spec.js +35 -41
- package/src/middleware/tests/usageQuota.spec.js +1 -1
- package/src/middleware/usageQuota.js +1 -1
- package/src/tests/utilities/TestConfiguration.js +65 -8
- package/src/tests/utilities/structures.js +2 -2
- package/src/threads/automation.js +2 -2
- package/src/threads/query.js +204 -39
- package/src/threads/utils.js +66 -1
- package/src/utilities/budibaseDir.js +1 -1
- package/src/utilities/fileSystem/utilities.js +3 -1
- package/src/utilities/global.js +8 -5
- package/src/utilities/index.js +12 -1
- package/src/utilities/redis.js +1 -1
- package/src/utilities/rowProcessor/index.js +79 -0
- package/src/utilities/security.js +5 -2
- package/src/utilities/usageQuota.js +2 -2
- package/src/utilities/workerRequests.js +3 -3
- package/builder/assets/index.9ac33cf1.js +0 -1316
- package/src/api/controllers/query.js +0 -161
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Query, QueryParameter } from "../../../../../../definitions/datasource"
|
|
2
|
+
import { URL } from "url"
|
|
3
|
+
|
|
4
|
+
export interface ImportInfo {
|
|
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
|
+
url: URL,
|
|
27
|
+
queryString: string,
|
|
28
|
+
headers: object = {},
|
|
29
|
+
parameters: QueryParameter[] = [],
|
|
30
|
+
body: object | undefined = undefined
|
|
31
|
+
): Query => {
|
|
32
|
+
const readable = true
|
|
33
|
+
const queryVerb = this.verbFromMethod(method)
|
|
34
|
+
const transformer = "return data"
|
|
35
|
+
const schema = {}
|
|
36
|
+
path = this.processPath(path)
|
|
37
|
+
path = `${url.origin}/${path}`
|
|
38
|
+
queryString = this.processQuery(queryString)
|
|
39
|
+
const requestBody = JSON.stringify(body, null, 2)
|
|
40
|
+
|
|
41
|
+
const query: Query = {
|
|
42
|
+
datasourceId,
|
|
43
|
+
name,
|
|
44
|
+
parameters,
|
|
45
|
+
fields: {
|
|
46
|
+
headers,
|
|
47
|
+
queryString,
|
|
48
|
+
path,
|
|
49
|
+
requestBody,
|
|
50
|
+
},
|
|
51
|
+
transformer,
|
|
52
|
+
schema,
|
|
53
|
+
readable,
|
|
54
|
+
queryVerb,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return query
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
verbFromMethod = (method: string) => {
|
|
61
|
+
const verb = (<any>MethodToVerb)[method]
|
|
62
|
+
if (!verb) {
|
|
63
|
+
throw new Error(`Unsupported method: ${method}`)
|
|
64
|
+
}
|
|
65
|
+
return verb
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
processPath = (path: string): string => {
|
|
69
|
+
if (path?.startsWith("/")) {
|
|
70
|
+
path = path.substring(1)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// add extra braces around params for binding
|
|
74
|
+
path = path.replace(/[{]/g, "{{")
|
|
75
|
+
path = path.replace(/[}]/g, "}}")
|
|
76
|
+
|
|
77
|
+
return path
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
processQuery = (queryString: string): string => {
|
|
81
|
+
if (queryString?.startsWith("?")) {
|
|
82
|
+
return queryString.substring(1)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return queryString
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
let key = keys[0]
|
|
21
|
+
try {
|
|
22
|
+
// filter out the dollar syntax used by curl for shell support
|
|
23
|
+
if (key.startsWith("$")) {
|
|
24
|
+
key = key.substring(1)
|
|
25
|
+
}
|
|
26
|
+
return JSON.parse(key)
|
|
27
|
+
} catch (e) {
|
|
28
|
+
// do nothing
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const parseCookie = (curl: any) => {
|
|
36
|
+
if (curl.cookies) {
|
|
37
|
+
return Object.entries(curl.cookies).reduce((acc, entry) => {
|
|
38
|
+
const [key, value] = entry
|
|
39
|
+
return acc + `${key}=${value}; `
|
|
40
|
+
}, "")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Curl
|
|
48
|
+
* https://curl.se/docs/manpage.html
|
|
49
|
+
*/
|
|
50
|
+
export class Curl extends ImportSource {
|
|
51
|
+
curl: any
|
|
52
|
+
|
|
53
|
+
isSupported = async (data: string): Promise<boolean> => {
|
|
54
|
+
try {
|
|
55
|
+
const curl = parseCurl(data)
|
|
56
|
+
this.curl = curl
|
|
57
|
+
} catch (err) {
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getUrl = (): URL => {
|
|
64
|
+
return new URL(this.curl.raw_url)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getInfo = async (): Promise<ImportInfo> => {
|
|
68
|
+
const url = this.getUrl()
|
|
69
|
+
return {
|
|
70
|
+
name: url.hostname,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getQueries = async (datasourceId: string): Promise<Query[]> => {
|
|
75
|
+
const url = this.getUrl()
|
|
76
|
+
const name = url.pathname
|
|
77
|
+
const path = url.pathname
|
|
78
|
+
const method = this.curl.method
|
|
79
|
+
const queryString = url.search
|
|
80
|
+
const headers = this.curl.headers
|
|
81
|
+
const requestBody = parseBody(this.curl)
|
|
82
|
+
|
|
83
|
+
const cookieHeader = parseCookie(this.curl)
|
|
84
|
+
if (cookieHeader) {
|
|
85
|
+
headers["Cookie"] = cookieHeader
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const query = this.constructQuery(
|
|
89
|
+
datasourceId,
|
|
90
|
+
name,
|
|
91
|
+
method,
|
|
92
|
+
path,
|
|
93
|
+
url,
|
|
94
|
+
queryString,
|
|
95
|
+
headers,
|
|
96
|
+
[],
|
|
97
|
+
requestBody
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
return [query]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
import { URL } from "url"
|
|
6
|
+
|
|
7
|
+
const parameterNotRef = (
|
|
8
|
+
param: OpenAPIV2.Parameter | OpenAPIV2.ReferenceObject
|
|
9
|
+
): param is OpenAPIV2.Parameter => {
|
|
10
|
+
// all refs are deferenced by parser library
|
|
11
|
+
return true
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const isOpenAPI2 = (document: any): document is OpenAPIV2.Document => {
|
|
15
|
+
if (document.swagger === "2.0") {
|
|
16
|
+
return true
|
|
17
|
+
} else {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const methods: string[] = Object.values(OpenAPIV2.HttpMethods)
|
|
23
|
+
|
|
24
|
+
const isOperation = (
|
|
25
|
+
key: string,
|
|
26
|
+
pathItem: any
|
|
27
|
+
): pathItem is OpenAPIV2.OperationObject => {
|
|
28
|
+
return methods.includes(key)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const isParameter = (
|
|
32
|
+
key: string,
|
|
33
|
+
pathItem: any
|
|
34
|
+
): pathItem is OpenAPIV2.Parameter => {
|
|
35
|
+
return !isOperation(key, pathItem)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* OpenAPI Version 2.0 - aka "Swagger"
|
|
40
|
+
* https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md
|
|
41
|
+
*/
|
|
42
|
+
export class OpenAPI2 extends OpenAPISource {
|
|
43
|
+
document!: OpenAPIV2.Document
|
|
44
|
+
|
|
45
|
+
isSupported = async (data: string): Promise<boolean> => {
|
|
46
|
+
try {
|
|
47
|
+
const document: any = await this.parseData(data)
|
|
48
|
+
if (isOpenAPI2(document)) {
|
|
49
|
+
this.document = document
|
|
50
|
+
return true
|
|
51
|
+
} else {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
getUrl = (): URL => {
|
|
60
|
+
const scheme = this.document.schemes?.includes("https") ? "https" : "http"
|
|
61
|
+
const basePath = this.document.basePath || ""
|
|
62
|
+
const host = this.document.host || "<host>"
|
|
63
|
+
return new URL(`${scheme}://${host}${basePath}`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getInfo = async (): Promise<ImportInfo> => {
|
|
67
|
+
const name = this.document.info.title || "Swagger Import"
|
|
68
|
+
return {
|
|
69
|
+
name,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getQueries = async (datasourceId: string): Promise<Query[]> => {
|
|
74
|
+
const url = this.getUrl()
|
|
75
|
+
const queries = []
|
|
76
|
+
|
|
77
|
+
for (let [path, pathItem] of Object.entries(this.document.paths)) {
|
|
78
|
+
// parameters that apply to every operation in the path
|
|
79
|
+
let pathParams: OpenAPIV2.Parameter[] = []
|
|
80
|
+
|
|
81
|
+
for (let [key, opOrParams] of Object.entries(pathItem)) {
|
|
82
|
+
if (isParameter(key, opOrParams)) {
|
|
83
|
+
const pathParameters = opOrParams as OpenAPIV2.Parameter[]
|
|
84
|
+
pathParams.push(...pathParameters)
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
// can not be a parameter, must be an operation
|
|
88
|
+
const operation = opOrParams as OpenAPIV2.OperationObject
|
|
89
|
+
|
|
90
|
+
const methodName = key
|
|
91
|
+
const name = operation.operationId || path
|
|
92
|
+
let queryString = ""
|
|
93
|
+
const headers: any = {}
|
|
94
|
+
let requestBody = undefined
|
|
95
|
+
const parameters: QueryParameter[] = []
|
|
96
|
+
|
|
97
|
+
if (operation.consumes) {
|
|
98
|
+
headers["Content-Type"] = operation.consumes[0]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// combine the path parameters with the operation parameters
|
|
102
|
+
const operationParams = operation.parameters || []
|
|
103
|
+
const allParams = [...pathParams, ...operationParams]
|
|
104
|
+
|
|
105
|
+
for (let param of allParams) {
|
|
106
|
+
if (parameterNotRef(param)) {
|
|
107
|
+
switch (param.in) {
|
|
108
|
+
case "query":
|
|
109
|
+
let prefix = ""
|
|
110
|
+
if (queryString) {
|
|
111
|
+
prefix = "&"
|
|
112
|
+
}
|
|
113
|
+
queryString = `${queryString}${prefix}${param.name}={{${param.name}}}`
|
|
114
|
+
break
|
|
115
|
+
case "header":
|
|
116
|
+
headers[param.name] = `{{${param.name}}}`
|
|
117
|
+
break
|
|
118
|
+
case "path":
|
|
119
|
+
// do nothing: param is already in the path
|
|
120
|
+
break
|
|
121
|
+
case "formData":
|
|
122
|
+
// future enhancement
|
|
123
|
+
break
|
|
124
|
+
case "body":
|
|
125
|
+
// set the request body to the example provided
|
|
126
|
+
// future enhancement: generate an example from the schema
|
|
127
|
+
let bodyParam: OpenAPIV2.InBodyParameterObject =
|
|
128
|
+
param as OpenAPIV2.InBodyParameterObject
|
|
129
|
+
if (param.schema.example) {
|
|
130
|
+
const schema = bodyParam.schema as OpenAPIV2.SchemaObject
|
|
131
|
+
requestBody = schema.example
|
|
132
|
+
}
|
|
133
|
+
break
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// add the parameter if it can be bound in our config
|
|
137
|
+
if (["query", "header", "path"].includes(param.in)) {
|
|
138
|
+
parameters.push({
|
|
139
|
+
name: param.name,
|
|
140
|
+
default: param.default || "",
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const query = this.constructQuery(
|
|
147
|
+
datasourceId,
|
|
148
|
+
name,
|
|
149
|
+
methodName,
|
|
150
|
+
path,
|
|
151
|
+
url,
|
|
152
|
+
queryString,
|
|
153
|
+
headers,
|
|
154
|
+
parameters,
|
|
155
|
+
requestBody
|
|
156
|
+
)
|
|
157
|
+
queries.push(query)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return queries
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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.name).toBe("example.com")
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe("Returns queries", () => {
|
|
42
|
+
|
|
43
|
+
const getQueries = async (file) => {
|
|
44
|
+
await init(file)
|
|
45
|
+
const queries = await curl.getQueries()
|
|
46
|
+
expect(queries.length).toBe(1)
|
|
47
|
+
return queries
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const testVerb = async (file, verb) => {
|
|
51
|
+
const queries = await getQueries(file)
|
|
52
|
+
expect(queries[0].queryVerb).toBe(verb)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
it("populates verb", async () => {
|
|
56
|
+
await testVerb("get", "read")
|
|
57
|
+
await testVerb("post", "create")
|
|
58
|
+
await testVerb("put", "update")
|
|
59
|
+
await testVerb("delete", "delete")
|
|
60
|
+
await testVerb("patch", "patch")
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const testPath = async (file, urlPath) => {
|
|
64
|
+
const queries = await getQueries(file)
|
|
65
|
+
expect(queries[0].fields.path).toBe(urlPath)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
it("populates path", async () => {
|
|
69
|
+
await testPath("get", "http://example.com/")
|
|
70
|
+
await testPath("path", "http://example.com/paths/abc")
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const testHeaders = async (file, headers) => {
|
|
74
|
+
const queries = await getQueries(file)
|
|
75
|
+
expect(queries[0].fields.headers).toStrictEqual(headers)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
it("populates headers", async () => {
|
|
79
|
+
await testHeaders("get", {})
|
|
80
|
+
await testHeaders("headers", { "x-bb-header-1" : "123", "x-bb-header-2" : "456"} )
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const testQuery = async (file, queryString) => {
|
|
84
|
+
const queries = await getQueries(file)
|
|
85
|
+
expect(queries[0].fields.queryString).toBe(queryString)
|
|
86
|
+
}
|
|
87
|
+
it("populates query", async () => {
|
|
88
|
+
await testQuery("get", "")
|
|
89
|
+
await testQuery("query", "q1=v1&q1=v2")
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const testBody = async (file, body) => {
|
|
93
|
+
const queries = await getQueries(file)
|
|
94
|
+
expect(queries[0].fields.requestBody).toStrictEqual(JSON.stringify(body, null, 2))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
it("populates body", async () => {
|
|
98
|
+
await testBody("get", undefined)
|
|
99
|
+
await testBody("post", { "key" : "val" })
|
|
100
|
+
await testBody("empty-body", {})
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
curl -X DELETE 'http://example.com'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
curl 'http://example.com'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
curl 'http://example.com/paths/abc'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
curl 'http://example.com/paths/abc?q1=v1&q1=v2'
|