@budibase/server 1.3.21 → 1.3.22-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 (310) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/builder/assets/index.96c69636.js +1008 -0
  3. package/builder/assets/index.c167b5c3.css +6 -0
  4. package/builder/index.html +2 -4
  5. package/coverage/clover.xml +308 -338
  6. package/coverage/coverage-final.json +19 -21
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/auth.js.html +41 -8
  9. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/datasource.js.html +73 -34
  13. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/index.html +27 -57
  15. package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
  16. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/external.js.html +2 -2
  25. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  34. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  43. package/coverage/lcov-report/api/index.html +1 -1
  44. package/coverage/lcov-report/api/index.js.html +13 -13
  45. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/index.html +1 -1
  56. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/table.js.html +2 -2
  67. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/utils/index.html +9 -9
  70. package/coverage/lcov-report/api/routes/utils/validators.js.html +75 -12
  71. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  73. package/coverage/lcov-report/automations/actions.js.html +1 -1
  74. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  75. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  76. package/coverage/lcov-report/automations/index.html +1 -1
  77. package/coverage/lcov-report/automations/index.js.html +1 -1
  78. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/index.html +1 -1
  85. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  104. package/coverage/lcov-report/constants/index.html +1 -1
  105. package/coverage/lcov-report/constants/index.js.html +1 -1
  106. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  107. package/coverage/lcov-report/constants/screens.js.html +1 -1
  108. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  109. package/coverage/lcov-report/db/index.html +14 -14
  110. package/coverage/lcov-report/db/index.js.html +1 -1
  111. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  112. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  113. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  115. package/coverage/lcov-report/db/newid.js.html +2 -2
  116. package/coverage/lcov-report/db/utils.js.html +30 -18
  117. package/coverage/lcov-report/events/AutomationEmitter.js.html +3 -3
  118. package/coverage/lcov-report/events/index.html +1 -1
  119. package/coverage/lcov-report/events/index.js.html +1 -1
  120. package/coverage/lcov-report/events/utils.js.html +1 -1
  121. package/coverage/lcov-report/index.html +44 -44
  122. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  123. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  124. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  125. package/coverage/lcov-report/middleware/builder.js.html +12 -12
  126. package/coverage/lcov-report/middleware/currentapp.js.html +46 -40
  127. package/coverage/lcov-report/middleware/index.html +15 -15
  128. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  129. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  130. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  131. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  132. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  133. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  134. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  135. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  136. package/coverage/lcov-report/utilities/global.js.html +16 -16
  137. package/coverage/lcov-report/utilities/index.html +15 -15
  138. package/coverage/lcov-report/utilities/index.js.html +24 -24
  139. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  140. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  141. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  142. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  143. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  144. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  145. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  146. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  147. package/coverage/lcov-report/utilities/security.js.html +2 -2
  148. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  149. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  150. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  151. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  152. package/coverage/lcov-report/utilities/users.js.html +1 -1
  153. package/coverage/lcov-report/utilities/workerRequests.js.html +32 -8
  154. package/coverage/lcov.info +521 -558
  155. package/dist/api/controllers/application.js +5 -5
  156. package/dist/api/controllers/auth.js +9 -0
  157. package/dist/api/controllers/component.js +19 -6
  158. package/dist/api/controllers/datasource.js +21 -8
  159. package/dist/api/controllers/deploy/index.js +1 -8
  160. package/dist/api/controllers/integration.js +4 -4
  161. package/dist/{migrations/functions/usageQuotas/syncDevelopers.js → api/controllers/plugin/file.js} +13 -13
  162. package/dist/api/controllers/plugin/github.js +69 -0
  163. package/dist/api/controllers/plugin/index.js +144 -0
  164. package/dist/api/controllers/plugin/npm.js +58 -0
  165. package/dist/api/controllers/plugin/uploaders.js +11 -0
  166. package/dist/{migrations/functions/usageQuotas/syncPublishedApps.js → api/controllers/plugin/url.js} +13 -15
  167. package/dist/api/controllers/plugin/utils.js +26 -0
  168. package/dist/api/controllers/row/external.js +1 -1
  169. package/dist/api/controllers/screen.js +62 -14
  170. package/dist/api/controllers/static/index.js +1 -0
  171. package/dist/api/controllers/static/templates/BudibaseApp.svelte +10 -0
  172. package/dist/api/controllers/static/templates/preview.hbs +5 -1
  173. package/dist/api/index.js +1 -1
  174. package/dist/api/routes/application.js +3 -2
  175. package/dist/api/routes/index.js +2 -0
  176. package/dist/{migrations/functions/publishedAppsQuota.js → api/routes/plugin.js} +13 -21
  177. package/dist/api/routes/public/rows.js +1 -82
  178. package/dist/api/routes/public/tables.js +1 -1
  179. package/dist/api/routes/table.js +1 -1
  180. package/dist/api/routes/utils/validators.js +20 -2
  181. package/dist/app.js +16 -1
  182. package/dist/db/utils.js +3 -0
  183. package/dist/environment.js +1 -0
  184. package/dist/integrations/airtable.js +126 -129
  185. package/dist/integrations/arangodb.js +86 -89
  186. package/dist/integrations/base/query.js +2 -2
  187. package/dist/integrations/base/sqlTable.js +3 -1
  188. package/dist/integrations/couchdb.js +80 -83
  189. package/dist/integrations/dynamodb.js +161 -164
  190. package/dist/integrations/elasticsearch.js +135 -138
  191. package/dist/integrations/firebase.js +154 -157
  192. package/dist/integrations/googlesheets.js +323 -327
  193. package/dist/integrations/index.js +99 -51
  194. package/dist/integrations/microsoftSqlServer.js +240 -243
  195. package/dist/integrations/mongodb.js +239 -242
  196. package/dist/integrations/mysql.js +215 -219
  197. package/dist/integrations/oracle.js +318 -322
  198. package/dist/integrations/postgres.js +262 -265
  199. package/dist/integrations/redis.js +134 -139
  200. package/dist/integrations/rest.js +289 -292
  201. package/dist/integrations/s3.js +61 -64
  202. package/dist/integrations/snowflake.js +83 -86
  203. package/dist/middleware/currentapp.js +2 -0
  204. package/dist/migrations/functions/backfill/global.js +0 -3
  205. package/dist/migrations/index.js +0 -10
  206. package/dist/package.json +9 -6
  207. package/dist/tests/utilities/TestConfiguration.js +1 -1
  208. package/dist/threads/query.js +2 -2
  209. package/dist/tsconfig.build.tsbuildinfo +1 -1
  210. package/dist/utilities/fileSystem/index.js +105 -1
  211. package/dist/utilities/workerRequests.js +4 -0
  212. package/dist/watch.js +77 -0
  213. package/dist/websocket.js +22 -0
  214. package/package.json +10 -7
  215. package/scripts/dev/manage.js +4 -0
  216. package/scripts/localdomain.js +3 -1
  217. package/specs/openapi.json +115 -112
  218. package/specs/openapi.yaml +96 -94
  219. package/specs/resources/misc.js +116 -0
  220. package/specs/resources/query.js +1 -1
  221. package/src/api/controllers/application.ts +1 -2
  222. package/src/api/controllers/auth.js +11 -0
  223. package/src/api/controllers/component.ts +57 -0
  224. package/src/api/controllers/datasource.js +21 -8
  225. package/src/api/controllers/deploy/index.ts +1 -6
  226. package/src/api/controllers/integration.js +4 -4
  227. package/src/api/controllers/plugin/file.ts +15 -0
  228. package/src/api/controllers/plugin/github.ts +75 -0
  229. package/src/api/controllers/plugin/index.ts +134 -0
  230. package/src/api/controllers/plugin/npm.ts +56 -0
  231. package/src/api/controllers/plugin/uploaders.ts +4 -0
  232. package/src/api/controllers/plugin/url.ts +12 -0
  233. package/src/api/controllers/plugin/utils.ts +19 -0
  234. package/src/api/controllers/public/mapping/types.ts +8 -0
  235. package/src/api/controllers/row/external.js +1 -1
  236. package/src/api/controllers/screen.ts +122 -0
  237. package/src/api/controllers/static/index.ts +1 -1
  238. package/src/api/controllers/static/templates/BudibaseApp.svelte +10 -0
  239. package/src/api/controllers/static/templates/preview.hbs +5 -1
  240. package/src/api/index.js +1 -1
  241. package/src/api/routes/application.ts +13 -2
  242. package/src/api/routes/index.ts +2 -0
  243. package/src/api/routes/plugin.ts +14 -0
  244. package/src/api/routes/public/rows.ts +1 -82
  245. package/src/api/routes/public/tables.ts +1 -1
  246. package/src/api/routes/table.js +1 -1
  247. package/src/api/routes/tests/query.spec.js +8 -25
  248. package/src/api/routes/tests/user.spec.js +0 -2
  249. package/src/api/routes/utils/validators.js +26 -5
  250. package/src/app.ts +25 -2
  251. package/src/db/utils.js +4 -0
  252. package/src/definitions/openapi.ts +56 -55
  253. package/src/environment.js +1 -0
  254. package/src/integrations/airtable.ts +116 -118
  255. package/src/integrations/arangodb.ts +87 -89
  256. package/src/integrations/base/query.ts +2 -2
  257. package/src/integrations/base/sqlTable.ts +3 -1
  258. package/src/integrations/couchdb.ts +83 -89
  259. package/src/integrations/dynamodb.ts +173 -175
  260. package/src/integrations/elasticsearch.ts +120 -122
  261. package/src/integrations/firebase.ts +157 -159
  262. package/src/integrations/googlesheets.ts +328 -338
  263. package/src/integrations/index.ts +64 -21
  264. package/src/integrations/microsoftSqlServer.ts +249 -251
  265. package/src/integrations/mongodb.ts +261 -258
  266. package/src/integrations/mysql.ts +229 -234
  267. package/src/integrations/oracle.ts +373 -380
  268. package/src/integrations/postgres.ts +264 -268
  269. package/src/integrations/redis.ts +128 -132
  270. package/src/integrations/rest.ts +324 -329
  271. package/src/integrations/s3.ts +68 -71
  272. package/src/integrations/snowflake.ts +80 -82
  273. package/src/integrations/tests/{airtable.spec.js → airtable.spec.ts} +21 -18
  274. package/src/integrations/tests/{arangodb.spec.js → arangodb.spec.ts} +12 -9
  275. package/src/integrations/tests/{couchdb.spec.js → couchdb.spec.ts} +33 -27
  276. package/src/integrations/tests/{dynamodb.spec.js → dynamodb.spec.ts} +45 -41
  277. package/src/integrations/tests/{elasticsearch.spec.js → elasticsearch.spec.ts} +22 -21
  278. package/src/integrations/tests/{firebase.spec.js → firebase.spec.ts} +33 -28
  279. package/src/integrations/tests/{microsoftSqlServer.spec.js → microsoftSqlServer.spec.ts} +12 -11
  280. package/src/integrations/tests/{mongo.spec.js → mongo.spec.ts} +46 -35
  281. package/src/integrations/tests/{mysql.spec.js → mysql.spec.ts} +17 -15
  282. package/src/integrations/tests/{oracle.spec.js → oracle.spec.ts} +19 -17
  283. package/src/integrations/tests/{postgres.spec.js → postgres.spec.ts} +19 -17
  284. package/src/integrations/tests/{redis.spec.js → redis.spec.ts} +27 -18
  285. package/src/integrations/tests/{rest.spec.js → rest.spec.ts} +22 -14
  286. package/src/integrations/tests/{s3.spec.js → s3.spec.ts} +10 -8
  287. package/src/integrations/tests/{sql.spec.js → sql.spec.ts} +228 -177
  288. package/src/middleware/currentapp.js +2 -0
  289. package/src/migrations/functions/backfill/global.ts +0 -3
  290. package/src/migrations/index.ts +0 -16
  291. package/src/module.d.ts +2 -0
  292. package/src/tests/utilities/TestConfiguration.js +1 -1
  293. package/src/threads/query.ts +2 -2
  294. package/src/utilities/fileSystem/index.js +123 -0
  295. package/src/utilities/workerRequests.js +8 -0
  296. package/src/watch.ts +38 -0
  297. package/src/websocket.ts +26 -0
  298. package/builder/assets/index.8d12d461.css +0 -6
  299. package/builder/assets/index.d354271c.js +0 -879
  300. package/builder/assets/vendor.5e1fe644.css +0 -1
  301. package/builder/assets/vendor.67dbd8fa.js +0 -248
  302. package/coverage/lcov-report/api/controllers/component.js.html +0 -199
  303. package/coverage/lcov-report/api/controllers/screen.js.html +0 -259
  304. package/dist/migrations/functions/developerQuota.js +0 -49
  305. package/src/api/controllers/component.js +0 -38
  306. package/src/api/controllers/screen.js +0 -58
  307. package/src/migrations/functions/developerQuota.ts +0 -15
  308. package/src/migrations/functions/publishedAppsQuota.ts +0 -13
  309. package/src/migrations/functions/usageQuotas/syncDevelopers.ts +0 -19
  310. package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +0 -21
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.sync = exports.destroy = exports.revertClient = exports.updateClient = exports.update = exports.create = exports.fetchAppPackage = exports.fetchAppDefinition = exports.fetch = exports.getAppUrl = void 0;
15
+ exports.updateAppPackage = exports.sync = exports.destroy = exports.revertClient = exports.updateClient = exports.update = exports.create = exports.fetchAppPackage = exports.fetchAppDefinition = exports.fetch = exports.getAppUrl = void 0;
16
16
  const environment_1 = __importDefault(require("../../environment"));
17
17
  const package_json_1 = __importDefault(require("../../../package.json"));
18
18
  const staticViews_1 = require("../../db/views/staticViews");
@@ -353,7 +353,7 @@ const update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
353
353
  checkAppUrl(ctx, apps, url, ctx.params.appId);
354
354
  ctx.request.body.url = url;
355
355
  }
356
- const app = yield updateAppPackage(ctx.request.body, ctx.params.appId);
356
+ const app = yield (0, exports.updateAppPackage)(ctx.request.body, ctx.params.appId);
357
357
  yield backend_core_2.events.app.updated(app);
358
358
  ctx.status = 200;
359
359
  ctx.body = app;
@@ -375,7 +375,7 @@ const updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
375
375
  version: updatedToVersion,
376
376
  revertableVersion: currentVersion,
377
377
  };
378
- const app = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
378
+ const app = yield (0, exports.updateAppPackage)(appPackageUpdates, ctx.params.appId);
379
379
  yield backend_core_2.events.app.versionUpdated(app, currentVersion, updatedToVersion);
380
380
  ctx.status = 200;
381
381
  ctx.body = app;
@@ -399,7 +399,7 @@ const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
399
399
  version: revertedToVersion,
400
400
  revertableVersion: null,
401
401
  };
402
- const app = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
402
+ const app = yield (0, exports.updateAppPackage)(appPackageUpdates, ctx.params.appId);
403
403
  yield backend_core_2.events.app.versionReverted(app, currentVersion, revertedToVersion);
404
404
  ctx.status = 200;
405
405
  ctx.body = app;
@@ -415,7 +415,6 @@ const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
415
415
  const app = yield db.get(utils_1.DocumentType.APP_METADATA);
416
416
  const result = yield db.destroy();
417
417
  if (isUnpublish) {
418
- yield pro_1.quotas.removePublishedApp();
419
418
  yield backend_core_2.events.app.unpublished(app);
420
419
  }
421
420
  else {
@@ -527,6 +526,7 @@ const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0
527
526
  return newAppPackage;
528
527
  }));
529
528
  });
529
+ exports.updateAppPackage = updateAppPackage;
530
530
  const migrateAppNavigation = () => __awaiter(void 0, void 0, void 0, function* () {
531
531
  const db = backend_core_1.context.getAppDB();
532
532
  const existing = yield db.get(utils_1.DocumentType.APP_METADATA);
@@ -13,6 +13,14 @@ const { InternalTables } = require("../../db/utils");
13
13
  const { getFullUser } = require("../../utilities/users");
14
14
  const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
15
15
  const { getAppDB, getAppId } = require("@budibase/backend-core/context");
16
+ /**
17
+ * Add the attributes that are session based to the current user.
18
+ */
19
+ const addSessionAttributesToUser = ctx => {
20
+ if (ctx.user) {
21
+ ctx.body.license = ctx.user.license;
22
+ }
23
+ };
16
24
  exports.fetchSelf = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
17
25
  let userId = ctx.user.userId || ctx.user._id;
18
26
  /* istanbul ignore next */
@@ -59,4 +67,5 @@ exports.fetchSelf = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
59
67
  else {
60
68
  ctx.body = user;
61
69
  }
70
+ addSessionAttributesToUser(ctx);
62
71
  });
@@ -8,16 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { DocumentType } = require("../../db/utils");
12
- const { getComponentLibraryManifest } = require("../../utilities/fileSystem");
13
- const { getAppDB } = require("@budibase/backend-core/context");
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const utils_1 = require("../../db/utils");
13
+ const backend_core_1 = require("@budibase/backend-core");
14
+ const fileSystem_1 = require("../../utilities/fileSystem");
14
15
  exports.fetchAppComponentDefinitions = function (ctx) {
15
16
  return __awaiter(this, void 0, void 0, function* () {
16
17
  try {
17
- const db = getAppDB();
18
- const app = yield db.get(DocumentType.APP_METADATA);
18
+ const db = backend_core_1.context.getAppDB();
19
+ const app = yield db.get(utils_1.DocumentType.APP_METADATA);
19
20
  let componentManifests = yield Promise.all(app.componentLibraries.map((library) => __awaiter(this, void 0, void 0, function* () {
20
- let manifest = yield getComponentLibraryManifest(library);
21
+ let manifest = yield (0, fileSystem_1.getComponentLibraryManifest)(library);
21
22
  return {
22
23
  manifest,
23
24
  library,
@@ -35,6 +36,18 @@ exports.fetchAppComponentDefinitions = function (ctx) {
35
36
  }
36
37
  }
37
38
  }
39
+ // Add custom components
40
+ const globalDB = backend_core_1.tenancy.getGlobalDB();
41
+ const response = yield globalDB.allDocs(backend_core_1.db.getPluginParams(null, {
42
+ include_docs: true,
43
+ }));
44
+ response.rows
45
+ .map((row) => row.doc)
46
+ .filter((plugin) => plugin.schema.type === "component")
47
+ .forEach((plugin) => {
48
+ const fullComponentName = `plugin/${plugin.name}`;
49
+ definitions[fullComponentName] = Object.assign({ component: fullComponentName }, plugin.schema.schema);
50
+ });
38
51
  ctx.body = definitions;
39
52
  }
40
53
  catch (err) {
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const { generateDatasourceID, getDatasourceParams, getQueryParams, DocumentType, BudibaseInternalDB, getTableParams, } = require("../../db/utils");
12
12
  const { BuildSchemaErrors, InvalidColumns } = require("../../constants");
13
- const { integrations } = require("../../integrations");
13
+ const { getIntegration } = require("../../integrations");
14
14
  const { getDatasourceAndQuery } = require("./row/utils");
15
15
  const { invalidateDynamicVariables } = require("../../threads/utils");
16
16
  const { getAppDB } = require("@budibase/backend-core/context");
@@ -41,8 +41,21 @@ exports.buildSchemaFromDb = function (ctx) {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
42
  const db = getAppDB();
43
43
  const datasource = yield db.get(ctx.params.datasourceId);
44
- const { tables, error } = yield buildSchemaHelper(datasource);
45
- datasource.entities = tables;
44
+ const tablesFilter = ctx.request.body.tablesFilter;
45
+ let { tables, error } = yield buildSchemaHelper(datasource);
46
+ if (tablesFilter) {
47
+ if (!datasource.entities) {
48
+ datasource.entities = {};
49
+ }
50
+ for (let key in tables) {
51
+ if (tablesFilter.some(filter => filter.toLowerCase() === key.toLowerCase())) {
52
+ datasource.entities[key] = tables[key];
53
+ }
54
+ }
55
+ }
56
+ else {
57
+ datasource.entities = tables;
58
+ }
46
59
  const dbResp = yield db.put(datasource);
47
60
  datasource._rev = dbResp.rev;
48
61
  const response = { datasource };
@@ -96,7 +109,7 @@ exports.update = function (ctx) {
96
109
  datasource._rev = response.rev;
97
110
  // Drain connection pools when configuration is changed
98
111
  if (datasource.source) {
99
- const source = integrations[datasource.source];
112
+ const source = yield getIntegration(datasource.source);
100
113
  if (source && source.pool) {
101
114
  yield source.pool.end();
102
115
  }
@@ -123,7 +136,7 @@ exports.save = function (ctx) {
123
136
  datasource._rev = dbResp.rev;
124
137
  // Drain connection pools when configuration is changed
125
138
  if (datasource.source) {
126
- const source = integrations[datasource.source];
139
+ const source = yield getIntegration(datasource.source);
127
140
  if (source && source.pool) {
128
141
  yield source.pool.end();
129
142
  }
@@ -188,13 +201,13 @@ function updateError(error, newError, tables) {
188
201
  return error;
189
202
  }
190
203
  const buildSchemaHelper = (datasource) => __awaiter(void 0, void 0, void 0, function* () {
191
- const Connector = integrations[datasource.source];
204
+ var _a;
205
+ const Connector = yield getIntegration(datasource.source);
192
206
  // Connect to the DB and build the schema
193
207
  const connector = new Connector(datasource.config);
194
208
  yield connector.buildSchema(datasource._id, datasource.entities);
195
- datasource.entities = connector.tables;
196
209
  // make sure they all have a display name selected
197
- for (let entity of Object.values(datasource.entities)) {
210
+ for (let entity of Object.values((_a = datasource.entities) !== null && _a !== void 0 ? _a : {})) {
198
211
  if (entity.primaryDisplay) {
199
212
  continue;
200
213
  }
@@ -19,7 +19,6 @@ const utils_1 = require("../../../db/utils");
19
19
  const utils_2 = require("../../../automations/utils");
20
20
  const cache_1 = require("@budibase/backend-core/cache");
21
21
  const context_1 = require("@budibase/backend-core/context");
22
- const pro_1 = require("@budibase/pro");
23
22
  const backend_core_1 = require("@budibase/backend-core");
24
23
  // the max time we can wait for an invalidation to complete before considering it failed
25
24
  const MAX_PENDING_TIME_MS = 30 * 60000;
@@ -196,13 +195,7 @@ const _deployApp = function (ctx) {
196
195
  deployment = yield storeDeploymentHistory(deployment);
197
196
  console.log("Stored deployment history");
198
197
  console.log("Deploying app...");
199
- let app;
200
- if (yield isFirstDeploy()) {
201
- app = yield pro_1.quotas.addPublishedApp(() => deployApp(deployment));
202
- }
203
- else {
204
- app = yield deployApp(deployment);
205
- }
198
+ let app = yield deployApp(deployment);
206
199
  yield backend_core_1.events.app.published(app);
207
200
  ctx.body = deployment;
208
201
  });
@@ -8,15 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { cloneDeep } = require("lodash");
12
- const { definitions } = require("../../integrations");
11
+ const { getDefinitions } = require("../../integrations");
13
12
  const { SourceName } = require("@budibase/types");
14
13
  const googlesheets = require("../../integrations/googlesheets");
15
14
  const { featureFlags } = require("@budibase/backend-core");
16
15
  exports.fetch = function (ctx) {
17
16
  return __awaiter(this, void 0, void 0, function* () {
18
17
  ctx.status = 200;
19
- const defs = cloneDeep(definitions);
18
+ const defs = yield getDefinitions();
20
19
  // for google sheets integration google verification
21
20
  if (featureFlags.isEnabled(featureFlags.FeatureFlag.GOOGLE_SHEETS)) {
22
21
  defs[SourceName.GOOGLE_SHEETS] = googlesheets.schema;
@@ -26,7 +25,8 @@ exports.fetch = function (ctx) {
26
25
  };
27
26
  exports.find = function (ctx) {
28
27
  return __awaiter(this, void 0, void 0, function* () {
28
+ const defs = yield getDefinitions();
29
29
  ctx.status = 200;
30
- ctx.body = definitions[ctx.params.type];
30
+ ctx.body = defs[ctx.params.type];
31
31
  });
32
32
  };
@@ -9,16 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.run = void 0;
13
- const tenancy_1 = require("@budibase/backend-core/tenancy");
14
- const backend_core_1 = require("@budibase/backend-core");
15
- const pro_1 = require("@budibase/pro");
16
- const run = () => __awaiter(void 0, void 0, void 0, function* () {
17
- // get developer count
18
- const developerCount = yield backend_core_1.utils.getBuildersCount();
19
- // sync developer count
20
- const tenantId = (0, tenancy_1.getTenantId)();
21
- console.log(`[Tenant: ${tenantId}] Syncing developer count: ${developerCount}`);
22
- yield pro_1.quotas.setUsage(developerCount, pro_1.StaticQuotaName.DEVELOPERS, pro_1.QuotaUsageType.STATIC);
23
- });
24
- exports.run = run;
12
+ exports.fileUpload = void 0;
13
+ const fileSystem_1 = require("../../../utilities/fileSystem");
14
+ function fileUpload(file) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ if (!file.name.endsWith(".tar.gz")) {
17
+ throw new Error("Plugin must be compressed into a gzipped tarball.");
18
+ }
19
+ const path = (0, fileSystem_1.createTempFolder)(file.name.split(".tar.gz")[0]);
20
+ yield (0, fileSystem_1.extractTarball)(file.path, path);
21
+ return yield (0, fileSystem_1.getPluginMetadata)(path);
22
+ });
23
+ }
24
+ exports.fileUpload = fileUpload;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.githubUpload = exports.request = void 0;
16
+ const fileSystem_1 = require("../../../utilities/fileSystem");
17
+ const node_fetch_1 = __importDefault(require("node-fetch"));
18
+ const utils_1 = require("./utils");
19
+ function request(url, headers, err) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const response = yield (0, node_fetch_1.default)(url, { headers });
22
+ if (response.status >= 300) {
23
+ const respErr = yield response.text();
24
+ throw new Error(`Error: ${err} - ${respErr}`);
25
+ }
26
+ return response.json();
27
+ });
28
+ }
29
+ exports.request = request;
30
+ function githubUpload(url, name = "", token = "") {
31
+ var _a;
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ let githubUrl = url;
34
+ if (!githubUrl.includes("https://github.com/")) {
35
+ throw new Error("The plugin origin must be from Github");
36
+ }
37
+ if (url.includes(".git")) {
38
+ githubUrl = url.replace(".git", "");
39
+ }
40
+ const githubApiUrl = githubUrl.replace("https://github.com/", "https://api.github.com/repos/");
41
+ const headers = token ? { Authorization: `Bearer ${token}` } : {};
42
+ const pluginDetails = yield request(githubApiUrl, headers, "Repository not found");
43
+ const pluginName = pluginDetails.name || name;
44
+ const pluginLatestReleaseUrl = (pluginDetails === null || pluginDetails === void 0 ? void 0 : pluginDetails["releases_url"])
45
+ ? pluginDetails === null || pluginDetails === void 0 ? void 0 : pluginDetails["releases_url"].replace("{/id}", "/latest")
46
+ : undefined;
47
+ if (!pluginLatestReleaseUrl) {
48
+ throw new Error("Github release not found");
49
+ }
50
+ const pluginReleaseDetails = yield request(pluginLatestReleaseUrl, headers, "Github latest release not found");
51
+ const pluginReleaseTarballAsset = (_a = pluginReleaseDetails === null || pluginReleaseDetails === void 0 ? void 0 : pluginReleaseDetails.assets) === null || _a === void 0 ? void 0 : _a.find((x) => (x === null || x === void 0 ? void 0 : x["content_type"]) === "application/gzip");
52
+ const pluginLastReleaseTarballUrl = pluginReleaseTarballAsset === null || pluginReleaseTarballAsset === void 0 ? void 0 : pluginReleaseTarballAsset["browser_download_url"];
53
+ if (!pluginLastReleaseTarballUrl) {
54
+ throw new Error("Github latest release url not found");
55
+ }
56
+ try {
57
+ const path = yield (0, utils_1.downloadUnzipTarball)(pluginLastReleaseTarballUrl, pluginName, headers);
58
+ return yield (0, fileSystem_1.getPluginMetadata)(path);
59
+ }
60
+ catch (err) {
61
+ let errMsg = (err === null || err === void 0 ? void 0 : err.message) || err;
62
+ if (errMsg === "unexpected response Not Found") {
63
+ errMsg = "Github release tarball not found";
64
+ }
65
+ throw new Error(errMsg);
66
+ }
67
+ });
68
+ }
69
+ exports.githubUpload = githubUpload;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.processUploadedPlugin = exports.destroy = exports.fetch = exports.create = exports.upload = exports.getPlugins = void 0;
16
+ const uploaders_1 = require("./uploaders");
17
+ const tenancy_1 = require("@budibase/backend-core/tenancy");
18
+ const plugins_1 = require("@budibase/backend-core/plugins");
19
+ const types_1 = require("@budibase/types");
20
+ const environment_1 = __importDefault(require("../../../environment"));
21
+ const websocket_1 = require("../../../websocket");
22
+ const backend_core_1 = require("@budibase/backend-core");
23
+ const pro_1 = require("@budibase/pro");
24
+ function getPlugins(type) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const db = (0, tenancy_1.getGlobalDB)();
27
+ const response = yield db.allDocs(backend_core_1.db.getPluginParams(null, {
28
+ include_docs: true,
29
+ }));
30
+ const plugins = response.rows.map((row) => row.doc);
31
+ if (type) {
32
+ return plugins.filter((plugin) => { var _a; return ((_a = plugin.schema) === null || _a === void 0 ? void 0 : _a.type) === type; });
33
+ }
34
+ else {
35
+ return plugins;
36
+ }
37
+ });
38
+ }
39
+ exports.getPlugins = getPlugins;
40
+ function upload(ctx) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const plugins = ctx.request.files.file.length > 1
43
+ ? Array.from(ctx.request.files.file)
44
+ : [ctx.request.files.file];
45
+ try {
46
+ let docs = [];
47
+ // can do single or multiple plugins
48
+ for (let plugin of plugins) {
49
+ const doc = yield processUploadedPlugin(plugin, types_1.PluginSource.FILE);
50
+ docs.push(doc);
51
+ }
52
+ ctx.body = {
53
+ message: "Plugin(s) uploaded successfully",
54
+ plugins: docs,
55
+ };
56
+ }
57
+ catch (err) {
58
+ const errMsg = (err === null || err === void 0 ? void 0 : err.message) ? err === null || err === void 0 ? void 0 : err.message : err;
59
+ ctx.throw(400, `Failed to import plugin: ${errMsg}`);
60
+ }
61
+ });
62
+ }
63
+ exports.upload = upload;
64
+ function create(ctx) {
65
+ var _a;
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const { source, url, headers, githubToken } = ctx.request.body;
68
+ try {
69
+ let metadata;
70
+ let directory;
71
+ // Generating random name as a backup and needed for url
72
+ let name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000);
73
+ switch (source) {
74
+ case types_1.PluginSource.NPM:
75
+ const { metadata: metadataNpm, directory: directoryNpm } = yield (0, uploaders_1.npmUpload)(url, name);
76
+ metadata = metadataNpm;
77
+ directory = directoryNpm;
78
+ break;
79
+ case types_1.PluginSource.GITHUB:
80
+ const { metadata: metadataGithub, directory: directoryGithub } = yield (0, uploaders_1.githubUpload)(url, name, githubToken);
81
+ metadata = metadataGithub;
82
+ directory = directoryGithub;
83
+ break;
84
+ case types_1.PluginSource.URL:
85
+ const headersObj = headers || {};
86
+ const { metadata: metadataUrl, directory: directoryUrl } = yield (0, uploaders_1.urlUpload)(url, name, headersObj);
87
+ metadata = metadataUrl;
88
+ directory = directoryUrl;
89
+ break;
90
+ }
91
+ (0, plugins_1.validate)(metadata === null || metadata === void 0 ? void 0 : metadata.schema);
92
+ // Only allow components in cloud
93
+ if (!environment_1.default.SELF_HOSTED && ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.schema) === null || _a === void 0 ? void 0 : _a.type) !== types_1.PluginType.COMPONENT) {
94
+ throw new Error("Only component plugins are supported outside of self-host");
95
+ }
96
+ const doc = yield pro_1.plugins.storePlugin(metadata, directory, source);
97
+ websocket_1.ClientAppSocket.emit("plugins-update", { name, hash: doc.hash });
98
+ ctx.body = {
99
+ message: "Plugin uploaded successfully",
100
+ plugins: [doc],
101
+ };
102
+ ctx.body = { plugin: doc };
103
+ }
104
+ catch (err) {
105
+ const errMsg = (err === null || err === void 0 ? void 0 : err.message) ? err === null || err === void 0 ? void 0 : err.message : err;
106
+ ctx.throw(400, `Failed to import plugin: ${errMsg}`);
107
+ }
108
+ });
109
+ }
110
+ exports.create = create;
111
+ function fetch(ctx) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ ctx.body = yield getPlugins();
114
+ });
115
+ }
116
+ exports.fetch = fetch;
117
+ function destroy(ctx) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const { pluginId } = ctx.params;
120
+ try {
121
+ yield pro_1.plugins.deletePlugin(pluginId);
122
+ ctx.body = { message: `Plugin ${ctx.params.pluginId} deleted.` };
123
+ }
124
+ catch (err) {
125
+ ctx.throw(400, err.message);
126
+ }
127
+ });
128
+ }
129
+ exports.destroy = destroy;
130
+ function processUploadedPlugin(plugin, source) {
131
+ var _a;
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ const { metadata, directory } = yield (0, uploaders_1.fileUpload)(plugin);
134
+ (0, plugins_1.validate)(metadata === null || metadata === void 0 ? void 0 : metadata.schema);
135
+ // Only allow components in cloud
136
+ if (!environment_1.default.SELF_HOSTED && ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.schema) === null || _a === void 0 ? void 0 : _a.type) !== types_1.PluginType.COMPONENT) {
137
+ throw new Error("Only component plugins are supported outside of self-host");
138
+ }
139
+ const doc = yield pro_1.plugins.storePlugin(metadata, directory, source);
140
+ websocket_1.ClientAppSocket.emit("plugins-update", { name: doc.name, hash: doc.hash });
141
+ return doc;
142
+ });
143
+ }
144
+ exports.processUploadedPlugin = processUploadedPlugin;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.npmUpload = void 0;
16
+ const fileSystem_1 = require("../../../utilities/fileSystem");
17
+ const node_fetch_1 = __importDefault(require("node-fetch"));
18
+ const path_1 = require("path");
19
+ const utils_1 = require("./utils");
20
+ function npmUpload(url, name, headers = {}) {
21
+ var _a, _b, _c;
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ let npmTarballUrl = url;
24
+ let pluginName = name;
25
+ if (!npmTarballUrl.includes("https://www.npmjs.com") &&
26
+ !npmTarballUrl.includes("https://registry.npmjs.org")) {
27
+ throw new Error("The plugin origin must be from NPM");
28
+ }
29
+ if (!npmTarballUrl.includes(".tgz")) {
30
+ const npmPackageURl = url.replace("https://www.npmjs.com/package/", "https://registry.npmjs.org/");
31
+ const response = yield (0, node_fetch_1.default)(npmPackageURl);
32
+ if (response.status !== 200) {
33
+ throw new Error("NPM Package not found");
34
+ }
35
+ let npmDetails = yield response.json();
36
+ pluginName = npmDetails.name;
37
+ const npmVersion = npmDetails["dist-tags"].latest;
38
+ npmTarballUrl = (_c = (_b = (_a = npmDetails === null || npmDetails === void 0 ? void 0 : npmDetails.versions) === null || _a === void 0 ? void 0 : _a[npmVersion]) === null || _b === void 0 ? void 0 : _b.dist) === null || _c === void 0 ? void 0 : _c.tarball;
39
+ if (!npmTarballUrl) {
40
+ throw new Error("NPM tarball url not found");
41
+ }
42
+ }
43
+ const path = yield (0, utils_1.downloadUnzipTarball)(npmTarballUrl, pluginName, headers);
44
+ const tarballPluginFile = (0, fileSystem_1.findFileRec)(path, ".tar.gz");
45
+ if (!tarballPluginFile) {
46
+ throw new Error("Tarball plugin file not found");
47
+ }
48
+ try {
49
+ yield (0, fileSystem_1.extractTarball)(tarballPluginFile, path);
50
+ (0, fileSystem_1.deleteFolderFileSystem)((0, path_1.join)(path, "package"));
51
+ }
52
+ catch (err) {
53
+ throw new Error(err);
54
+ }
55
+ return yield (0, fileSystem_1.getPluginMetadata)(path);
56
+ });
57
+ }
58
+ exports.npmUpload = npmUpload;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.urlUpload = exports.npmUpload = exports.githubUpload = exports.fileUpload = void 0;
4
+ var file_1 = require("./file");
5
+ Object.defineProperty(exports, "fileUpload", { enumerable: true, get: function () { return file_1.fileUpload; } });
6
+ var github_1 = require("./github");
7
+ Object.defineProperty(exports, "githubUpload", { enumerable: true, get: function () { return github_1.githubUpload; } });
8
+ var npm_1 = require("./npm");
9
+ Object.defineProperty(exports, "npmUpload", { enumerable: true, get: function () { return npm_1.npmUpload; } });
10
+ var url_1 = require("./url");
11
+ Object.defineProperty(exports, "urlUpload", { enumerable: true, get: function () { return url_1.urlUpload; } });
@@ -9,18 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.run = void 0;
13
- const tenancy_1 = require("@budibase/backend-core/tenancy");
14
- const db_1 = require("@budibase/backend-core/db");
15
- const pro_1 = require("@budibase/pro");
16
- const run = () => __awaiter(void 0, void 0, void 0, function* () {
17
- // get app count
18
- const opts = { dev: false };
19
- const prodApps = yield (0, db_1.getAllApps)(opts);
20
- const prodAppCount = prodApps ? prodApps.length : 0;
21
- // sync app count
22
- const tenantId = (0, tenancy_1.getTenantId)();
23
- console.log(`[Tenant: ${tenantId}] Syncing published app count: ${prodAppCount}`);
24
- yield pro_1.quotas.setUsage(prodAppCount, pro_1.StaticQuotaName.PUBLISHED_APPS, pro_1.QuotaUsageType.STATIC);
25
- });
26
- exports.run = run;
12
+ exports.urlUpload = void 0;
13
+ const utils_1 = require("./utils");
14
+ const fileSystem_1 = require("../../../utilities/fileSystem");
15
+ function urlUpload(url, name = "", headers = {}) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ if (!url.includes(".tar.gz")) {
18
+ throw new Error("Plugin must be compressed into a gzipped tarball.");
19
+ }
20
+ const path = yield (0, utils_1.downloadUnzipTarball)(url, name, headers);
21
+ return yield (0, fileSystem_1.getPluginMetadata)(path);
22
+ });
23
+ }
24
+ exports.urlUpload = urlUpload;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.downloadUnzipTarball = void 0;
13
+ const fileSystem_1 = require("../../../utilities/fileSystem");
14
+ function downloadUnzipTarball(url, name, headers = {}) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ const path = (0, fileSystem_1.createTempFolder)(name);
18
+ yield (0, fileSystem_1.downloadTarballDirect)(url, path, headers);
19
+ return path;
20
+ }
21
+ catch (e) {
22
+ throw new Error(e.message);
23
+ }
24
+ });
25
+ }
26
+ exports.downloadUnzipTarball = downloadUnzipTarball;
@@ -63,7 +63,7 @@ exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
63
63
  });
64
64
  });
65
65
  exports.fetchView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
66
- // there are no views in external data sources, shouldn't ever be called
66
+ // there are no views in external datasources, shouldn't ever be called
67
67
  // for now just fetch
68
68
  const split = ctx.params.viewName.split("all_");
69
69
  ctx.params.tableId = split[1] ? split[1] : split[0];