@silexlabs/silex 3.0.1-alpha.0 → 3.0.2

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 (323) hide show
  1. package/.env.default +20 -0
  2. package/.silex.js +67 -8
  3. package/LICENSE +661 -203
  4. package/README.md +37 -35
  5. package/dist/client/client/api.d.ts +90 -0
  6. package/dist/client/client/assetUrl.d.ts +54 -0
  7. package/dist/client/client/config.d.ts +102 -0
  8. package/dist/client/client/events.d.ts +23 -0
  9. package/dist/client/client/expose.d.ts +8 -0
  10. package/dist/client/client/grapesjs/LoginDialog.d.ts +15 -0
  11. package/dist/client/client/grapesjs/PublicationManager.d.ts +73 -0
  12. package/dist/client/client/grapesjs/PublicationUi.d.ts +59 -0
  13. package/dist/client/client/grapesjs/blocks.d.ts +1 -0
  14. package/dist/client/client/grapesjs/breadcrumbs.d.ts +1 -0
  15. package/dist/client/client/grapesjs/css-props.d.ts +6 -0
  16. package/dist/client/client/grapesjs/footer.d.ts +2 -0
  17. package/dist/client/client/grapesjs/img.d.ts +6 -0
  18. package/dist/client/client/grapesjs/index.d.ts +9 -0
  19. package/dist/client/client/grapesjs/internal-links.d.ts +1 -0
  20. package/dist/client/client/grapesjs/keymaps.d.ts +123 -0
  21. package/dist/client/client/grapesjs/new-page-dialog.d.ts +2 -0
  22. package/dist/client/client/grapesjs/openImport.d.ts +9 -0
  23. package/dist/client/client/grapesjs/page-panel.d.ts +9 -0
  24. package/dist/client/client/grapesjs/project-bar.d.ts +21 -0
  25. package/dist/client/client/grapesjs/resize-panel.d.ts +1 -0
  26. package/dist/client/client/grapesjs/rich-text.d.ts +4 -0
  27. package/dist/client/client/grapesjs/semantic.d.ts +1 -0
  28. package/dist/client/client/grapesjs/settings-sections.d.ts +16 -0
  29. package/dist/client/client/grapesjs/settings.d.ts +4 -0
  30. package/dist/client/client/grapesjs/storage.d.ts +2 -0
  31. package/dist/client/client/grapesjs/symbolDialogs.d.ts +3 -0
  32. package/dist/client/client/grapesjs/view-buttons.d.ts +1 -0
  33. package/dist/client/client/index.d.ts +10 -0
  34. package/dist/client/client/publication-transformers.d.ts +42 -0
  35. package/dist/client/client/publish-custom-code-block.d.ts +4 -0
  36. package/dist/client/client/publish-fonts.d.ts +4 -0
  37. package/dist/client/client/utils.d.ts +22 -0
  38. package/dist/client/constants.d.ts +32 -0
  39. package/dist/client/css/admin.css +1114 -328
  40. package/dist/client/css/admin.css.map +1 -0
  41. package/dist/client/grapesjs-filter-styles/dist/index.d.ts +4 -0
  42. package/dist/client/grapesjs-fonts/dist/index.d.ts +4 -0
  43. package/dist/client/grapesjs-fonts/src/commands.d.ts +3 -0
  44. package/dist/client/grapesjs-fonts/src/fonts.d.ts +4 -0
  45. package/dist/client/grapesjs-storage-rate-limit/dist/index.d.ts +4 -0
  46. package/dist/client/grapesjs-ui-suggest-classes/dist/index.d.ts +4 -0
  47. package/dist/client/index.html +3 -2
  48. package/dist/client/js/main.js +356 -131
  49. package/dist/client/js/main.js.LICENSE.txt +15 -1
  50. package/dist/client/page.d.ts +2 -0
  51. package/dist/client/silex-lib/src/ts/client/api.d.ts +90 -0
  52. package/dist/client/silex-lib/src/ts/client/assetUrl.d.ts +54 -0
  53. package/dist/client/silex-lib/src/ts/client/config.d.ts +102 -0
  54. package/dist/client/silex-lib/src/ts/client/events.d.ts +23 -0
  55. package/dist/client/silex-lib/src/ts/client/expose.d.ts +8 -0
  56. package/dist/client/silex-lib/src/ts/client/grapesjs/LoginDialog.d.ts +15 -0
  57. package/dist/client/silex-lib/src/ts/client/grapesjs/PublicationManager.d.ts +73 -0
  58. package/dist/client/silex-lib/src/ts/client/grapesjs/PublicationUi.d.ts +59 -0
  59. package/dist/client/silex-lib/src/ts/client/grapesjs/blocks.d.ts +1 -0
  60. package/dist/client/silex-lib/src/ts/client/grapesjs/breadcrumbs.d.ts +1 -0
  61. package/dist/client/silex-lib/src/ts/client/grapesjs/css-props.d.ts +6 -0
  62. package/dist/client/silex-lib/src/ts/client/grapesjs/footer.d.ts +2 -0
  63. package/dist/client/silex-lib/src/ts/client/grapesjs/img.d.ts +6 -0
  64. package/dist/client/silex-lib/src/ts/client/grapesjs/index.d.ts +9 -0
  65. package/dist/client/silex-lib/src/ts/client/grapesjs/internal-links.d.ts +1 -0
  66. package/dist/client/silex-lib/src/ts/client/grapesjs/keymaps.d.ts +123 -0
  67. package/dist/client/silex-lib/src/ts/client/grapesjs/new-page-dialog.d.ts +2 -0
  68. package/dist/client/silex-lib/src/ts/client/grapesjs/openImport.d.ts +9 -0
  69. package/dist/client/silex-lib/src/ts/client/grapesjs/page-panel.d.ts +9 -0
  70. package/dist/client/silex-lib/src/ts/client/grapesjs/project-bar.d.ts +21 -0
  71. package/dist/client/silex-lib/src/ts/client/grapesjs/resize-panel.d.ts +1 -0
  72. package/dist/client/silex-lib/src/ts/client/grapesjs/rich-text.d.ts +4 -0
  73. package/dist/client/silex-lib/src/ts/client/grapesjs/semantic.d.ts +1 -0
  74. package/dist/client/silex-lib/src/ts/client/grapesjs/settings-sections.d.ts +16 -0
  75. package/dist/client/silex-lib/src/ts/client/grapesjs/settings.d.ts +4 -0
  76. package/dist/client/silex-lib/src/ts/client/grapesjs/storage.d.ts +2 -0
  77. package/dist/client/silex-lib/src/ts/client/grapesjs/symbolDialogs.d.ts +3 -0
  78. package/dist/client/silex-lib/src/ts/client/grapesjs/view-buttons.d.ts +1 -0
  79. package/dist/client/silex-lib/src/ts/client/index.d.ts +10 -0
  80. package/dist/client/silex-lib/src/ts/client/publication-transformers.d.ts +42 -0
  81. package/dist/client/silex-lib/src/ts/client/publish-custom-code-block.d.ts +4 -0
  82. package/dist/client/silex-lib/src/ts/client/publish-fonts.d.ts +4 -0
  83. package/dist/client/silex-lib/src/ts/client/utils.d.ts +22 -0
  84. package/dist/client/silex-lib/src/ts/constants.d.ts +32 -0
  85. package/dist/client/silex-lib/src/ts/page.d.ts +2 -0
  86. package/dist/client/silex-lib/src/ts/types.d.ts +339 -0
  87. package/dist/client/types.d.ts +339 -0
  88. package/dist/plugins/client/client/events.d.ts +23 -0
  89. package/dist/plugins/client/client/events.js +43 -0
  90. package/dist/plugins/client/client/events.js.map +1 -0
  91. package/dist/plugins/client/plugins/client/template.d.ts +2 -0
  92. package/dist/plugins/client/plugins/client/template.js +234 -0
  93. package/dist/plugins/client/plugins/client/template.js.map +1 -0
  94. package/dist/plugins/client/plugins/client/website-info.d.ts +1 -0
  95. package/dist/plugins/client/plugins/client/website-info.js +72 -0
  96. package/dist/plugins/client/plugins/client/website-info.js.map +1 -0
  97. package/dist/plugins/client/types.d.ts +339 -0
  98. package/dist/plugins/client/types.js +80 -0
  99. package/dist/plugins/client/types.js.map +1 -0
  100. package/dist/plugins/server/constants.d.ts +32 -0
  101. package/dist/plugins/server/constants.js +76 -0
  102. package/dist/plugins/server/constants.js.map +1 -0
  103. package/dist/plugins/server/plugins/server/Cache.d.ts +2 -0
  104. package/dist/plugins/server/plugins/server/Cache.js +36 -0
  105. package/dist/plugins/server/plugins/server/Cache.js.map +1 -0
  106. package/dist/plugins/server/plugins/server/DownloadConnector.d.ts +29 -0
  107. package/dist/plugins/server/plugins/server/DownloadConnector.js +127 -0
  108. package/dist/plugins/server/plugins/server/DownloadConnector.js.map +1 -0
  109. package/dist/plugins/server/plugins/server/FtpConnector.d.ts +86 -0
  110. package/dist/plugins/server/plugins/server/FtpConnector.js +536 -0
  111. package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -0
  112. package/dist/plugins/server/plugins/server/GitlabConnector.d.ts +135 -0
  113. package/dist/plugins/server/plugins/server/GitlabConnector.js +649 -0
  114. package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -0
  115. package/dist/plugins/server/plugins/server/GitlabHostingConnector.d.ts +16 -0
  116. package/dist/plugins/server/plugins/server/GitlabHostingConnector.js +209 -0
  117. package/dist/plugins/server/plugins/server/GitlabHostingConnector.js.map +1 -0
  118. package/dist/plugins/server/plugins/server/PublicationOptimizer.d.ts +0 -0
  119. package/dist/plugins/server/plugins/server/PublicationOptimizer.js +14 -0
  120. package/dist/plugins/server/plugins/server/PublicationOptimizer.js.map +1 -0
  121. package/dist/plugins/server/plugins/server/SslPlugin.d.ts +1 -0
  122. package/dist/plugins/server/plugins/server/SslPlugin.js +86 -0
  123. package/dist/plugins/server/plugins/server/SslPlugin.js.map +1 -0
  124. package/dist/plugins/server/plugins/server/StaticPlugin.d.ts +8 -0
  125. package/dist/plugins/server/plugins/server/StaticPlugin.js +45 -0
  126. package/dist/plugins/server/plugins/server/StaticPlugin.js.map +1 -0
  127. package/dist/plugins/server/server/config.d.ts +59 -0
  128. package/dist/plugins/server/server/config.js +181 -0
  129. package/dist/plugins/server/server/config.js.map +1 -0
  130. package/dist/plugins/server/server/connectors/FsHosting.d.ts +14 -0
  131. package/dist/plugins/server/server/connectors/FsHosting.js +66 -0
  132. package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -0
  133. package/dist/plugins/server/server/connectors/FsStorage.d.ts +44 -0
  134. package/dist/plugins/server/server/connectors/FsStorage.js +261 -0
  135. package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -0
  136. package/dist/plugins/server/server/connectors/connectors.d.ts +86 -0
  137. package/dist/plugins/server/server/connectors/connectors.js +126 -0
  138. package/dist/plugins/server/server/connectors/connectors.js.map +1 -0
  139. package/dist/plugins/server/server/events.d.ts +26 -0
  140. package/dist/plugins/server/server/events.js +31 -0
  141. package/dist/plugins/server/server/events.js.map +1 -0
  142. package/dist/plugins/server/server/jobs.d.ts +12 -0
  143. package/dist/plugins/server/server/jobs.js +79 -0
  144. package/dist/plugins/server/server/jobs.js.map +1 -0
  145. package/dist/plugins/server/server/utils/validation.d.ts +7 -0
  146. package/dist/plugins/server/server/utils/validation.js +37 -0
  147. package/dist/plugins/server/server/utils/validation.js.map +1 -0
  148. package/dist/plugins/server/types.d.ts +339 -0
  149. package/dist/plugins/server/types.js +84 -0
  150. package/dist/plugins/server/types.js.map +1 -0
  151. package/dist/server/constants.js +55 -0
  152. package/dist/server/plugins/server/Cache.js +19 -0
  153. package/dist/server/server/api/api.js +20 -0
  154. package/dist/server/server/api/connectorApi.js +334 -0
  155. package/dist/server/server/api/publicationApi.js +106 -0
  156. package/dist/server/server/api/websiteApi.js +315 -0
  157. package/dist/server/server/cli.js +71 -0
  158. package/dist/server/server/config.js +120 -0
  159. package/dist/server/server/connectors/FsHosting.js +47 -0
  160. package/dist/server/server/connectors/FsStorage.js +228 -0
  161. package/dist/server/server/connectors/connectors.js +88 -0
  162. package/dist/server/server/events.js +14 -0
  163. package/dist/server/server/expose.js +27 -0
  164. package/dist/server/server/express.js +46 -0
  165. package/dist/server/server/index.js +92 -0
  166. package/dist/server/server/jobs.js +50 -0
  167. package/dist/server/server/utils/validation.js +14 -0
  168. package/dist/server/types.js +40 -0
  169. package/package.json +99 -49
  170. package/public/assets/download.png +0 -0
  171. package/public/assets/favicon.ico +0 -0
  172. package/public/assets/favicon.png +0 -0
  173. package/public/assets/ftp.png +0 -0
  174. package/public/assets/gitlab.png +0 -0
  175. package/public/assets/gitlab2.png +0 -0
  176. package/public/assets/laptop.png +0 -0
  177. package/public/assets/logo-silex-small.png +0 -0
  178. package/public/silex.js +22 -23
  179. package/src/css/_variables.scss +24 -20
  180. package/src/css/dialog.scss +35 -2
  181. package/src/css/fonts.scss +31 -0
  182. package/src/css/footer.scss +12 -0
  183. package/src/css/grapesjs-light.scss +180 -0
  184. package/src/css/grapesjs-plugins.scss +227 -0
  185. package/src/css/grapesjs.scss +159 -1
  186. package/src/css/index.scss +12 -1
  187. package/src/css/light.scss +7 -0
  188. package/src/css/loader.scss +2 -0
  189. package/src/css/project-bar.scss +32 -16
  190. package/src/css/silex.scss +79 -5
  191. package/src/css/website-info.scss +14 -0
  192. package/src/html/index.pug +3 -3
  193. package/src/html/templates/includes.pug +0 -1
  194. package/src/ts/client/api.ts +156 -0
  195. package/src/ts/client/assetUrl.test.ts +164 -0
  196. package/src/ts/client/assetUrl.ts +254 -0
  197. package/src/ts/client/config.ts +175 -13
  198. package/src/ts/client/events.ts +43 -0
  199. package/src/ts/client/expose.ts +27 -1
  200. package/src/ts/client/grapesjs/LoginDialog.ts +204 -0
  201. package/src/ts/client/grapesjs/PublicationManager.ts +433 -0
  202. package/src/ts/client/grapesjs/PublicationUi.ts +366 -0
  203. package/src/ts/client/grapesjs/blocks.ts +17 -0
  204. package/src/ts/client/grapesjs/breadcrumbs.ts +79 -0
  205. package/src/ts/client/grapesjs/css-props.ts +910 -0
  206. package/src/ts/client/grapesjs/eleventy.ts +30 -7
  207. package/src/ts/client/grapesjs/footer.ts +42 -0
  208. package/src/ts/client/grapesjs/img.ts +147 -0
  209. package/src/ts/client/grapesjs/index.ts +311 -122
  210. package/src/ts/client/grapesjs/internal-links.test.ts +19 -1
  211. package/src/ts/client/grapesjs/internal-links.ts +31 -7
  212. package/src/ts/client/grapesjs/keymaps.ts +207 -0
  213. package/src/ts/client/grapesjs/new-page-dialog.ts +19 -3
  214. package/src/ts/client/grapesjs/openImport.ts +22 -0
  215. package/src/ts/client/grapesjs/page-panel.ts +109 -7
  216. package/src/ts/client/grapesjs/project-bar.ts +133 -72
  217. package/src/ts/client/grapesjs/resize-panel.ts +20 -0
  218. package/src/ts/client/grapesjs/rich-text.ts +38 -13
  219. package/src/ts/client/grapesjs/semantic.ts +20 -3
  220. package/src/ts/client/grapesjs/settings-sections.ts +117 -0
  221. package/src/ts/client/grapesjs/settings.ts +191 -96
  222. package/src/ts/client/grapesjs/storage.ts +187 -0
  223. package/src/ts/client/grapesjs/symbolDialogs.ts +21 -5
  224. package/src/ts/client/grapesjs/view-buttons.ts +42 -0
  225. package/src/ts/client/index.ts +80 -21
  226. package/src/ts/client/publication-transformers.test.ts +207 -0
  227. package/src/ts/client/publication-transformers.ts +280 -0
  228. package/src/ts/client/publish-custom-code-block.ts +31 -0
  229. package/src/ts/client/publish-fonts.ts +36 -0
  230. package/src/ts/client/utils.ts +70 -1
  231. package/src/ts/constants.ts +78 -0
  232. package/src/ts/externs.ts +17 -0
  233. package/src/ts/page.ts +20 -3
  234. package/src/ts/plugins/client/template.ts +246 -0
  235. package/src/ts/plugins/client/website-info.ts +84 -0
  236. package/src/ts/plugins/server/Cache.ts +32 -0
  237. package/src/ts/plugins/server/DownloadConnector.ts +146 -0
  238. package/src/ts/plugins/server/FtpConnector.test.ts +82 -0
  239. package/src/ts/plugins/server/FtpConnector.ts +621 -0
  240. package/src/ts/plugins/server/GitlabConnector.ts +749 -0
  241. package/src/ts/plugins/server/GitlabHostingConnector.ts +215 -0
  242. package/src/ts/plugins/server/PublicationOptimizer.ts +14 -0
  243. package/src/ts/plugins/server/SslPlugin.ts +84 -0
  244. package/src/ts/plugins/server/StaticPlugin.ts +45 -0
  245. package/src/ts/server/api/api.ts +19 -0
  246. package/src/ts/server/api/connectorApi.ts +464 -0
  247. package/src/ts/server/api/publicationApi.ts +159 -0
  248. package/src/ts/server/api/websiteApi.ts +462 -0
  249. package/src/ts/server/cli.ts +48 -14
  250. package/src/ts/server/config.ts +158 -60
  251. package/src/ts/server/connectors/FsHosting.ts +66 -0
  252. package/src/ts/server/connectors/FsStorage.test.ts +51 -0
  253. package/src/ts/server/connectors/FsStorage.ts +290 -0
  254. package/src/ts/server/connectors/connectors.ts +203 -0
  255. package/src/ts/server/events.ts +37 -0
  256. package/src/ts/server/expose.ts +19 -0
  257. package/src/ts/server/express.ts +57 -5
  258. package/src/ts/server/index.ts +80 -19
  259. package/src/ts/server/jobs.test.ts +75 -0
  260. package/src/ts/server/jobs.ts +89 -0
  261. package/src/ts/server/utils/BackwardCompat.ts +546 -528
  262. package/src/ts/server/utils/validation.ts +34 -0
  263. package/src/ts/types.ts +295 -85
  264. package/.dockerignore +0 -5
  265. package/.editorconfig +0 -14
  266. package/.eslintrc.json +0 -43
  267. package/.github/FUNDING.yml +0 -13
  268. package/.github/workflows/docker-hub-publish.yml +0 -36
  269. package/.github/workflows/npm-publish.yml +0 -19
  270. package/.github/workflows/test.yml +0 -26
  271. package/.nvmrc +0 -1
  272. package/.silex/default/.silex.data.json +0 -1
  273. package/CODE_OF_CONDUCT.md +0 -128
  274. package/CONTRIBUTING.md +0 -131
  275. package/Dockerfile +0 -15
  276. package/directus.silex.js +0 -7
  277. package/dist/constants.js +0 -4
  278. package/dist/events.js +0 -5
  279. package/dist/page.js +0 -15
  280. package/dist/server/cli.js +0 -43
  281. package/dist/server/config.js +0 -70
  282. package/dist/server/express.js +0 -18
  283. package/dist/server/index.js +0 -58
  284. package/dist/types.js +0 -34
  285. package/jest.config.js +0 -10
  286. package/logos/logo_by_ceubri/silex-icon-2018@200px.png +0 -0
  287. package/logos/logo_by_ceubri/silex-icon-2018@4x.png +0 -0
  288. package/logos/logo_by_ceubri/silex-logo-2018-white-transp.pdf +0 -0
  289. package/logos/logo_by_ceubri/silex-logo-2018-white.jpg +0 -0
  290. package/logos/logo_by_ceubri/silex-logo-2018-white.pdf +0 -0
  291. package/logos/logo_by_ceubri/silex-logo-2018-white.png +0 -0
  292. package/logos/logo_by_ceubri/silex-logo-2018-white@0.5x.png +0 -0
  293. package/logos/logo_by_ceubri/silex-logo-2018-white@0.75x.png +0 -0
  294. package/logos/logo_by_ceubri/silex-logo-2018-white@4x.jpg +0 -0
  295. package/logos/logo_by_ceubri/silex-logo-2018-white@4x.png +0 -0
  296. package/logos/logo_by_ceubri/silex-logo-2018.ai +5 -2521
  297. package/logos/logo_by_ceubri/silex-logo-2018.jpg +0 -0
  298. package/logos/logo_by_ceubri/silex-logo-2018.pdf +0 -0
  299. package/logos/logo_by_ceubri/silex-logo-2018.png +0 -0
  300. package/logos/logo_by_ceubri/silex-logo-2018@0.5x.png +0 -0
  301. package/logos/logo_by_ceubri/silex-logo-2018@0.75x.png +0 -0
  302. package/logos/logo_by_ceubri/silex-logo-2018@4x.jpg +0 -0
  303. package/logos/logo_by_ceubri/silex-logo-2018@4x.png +0 -0
  304. package/logos/silexlabs.png +0 -0
  305. package/src/example-client-config.js +0 -47
  306. package/src/plugins/AuthPlugin.js +0 -21
  307. package/src/plugins/Cache.js +0 -11
  308. package/src/plugins/DefaultBackend.js +0 -149
  309. package/src/plugins/ExpressPlugin.js +0 -39
  310. package/src/plugins/HooksPlugin.js +0 -58
  311. package/src/plugins/PublishPlugin.js +0 -69
  312. package/src/plugins/SslPlugin.js +0 -66
  313. package/src/plugins/StaticPlugin.js +0 -48
  314. package/src/plugins/WebsitePlugin.js +0 -207
  315. package/src/ts/client/grapesjs/publish.ts +0 -386
  316. package/src/ts/client/grapesjs/template.ts +0 -166
  317. package/src/ts/events.ts +0 -2
  318. package/tsconfig-server-debug.json +0 -19
  319. package/tsconfig-server-release.json +0 -19
  320. package/tsconfig.jest.json +0 -9
  321. package/tsconfig.json +0 -26
  322. package/webpack.config.js +0 -28
  323. package/webpack.debug.config.js +0 -8
@@ -0,0 +1,649 @@
1
+ "use strict";
2
+ /*
3
+ * Silex website builder, free/libre no-code tool for makers.
4
+ * Copyright (c) 2023 lexoyo and Silex Labs foundation
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ var desc = Object.getOwnPropertyDescriptor(m, k);
21
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
22
+ desc = { enumerable: true, get: function() { return m[k]; } };
23
+ }
24
+ Object.defineProperty(o, k2, desc);
25
+ }) : (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ o[k2] = m[k];
28
+ }));
29
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
30
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
31
+ }) : function(o, v) {
32
+ o["default"] = v;
33
+ });
34
+ var __importStar = (this && this.__importStar) || function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ const constants_1 = require("../../constants");
46
+ const connectors_1 = require("../../server/connectors/connectors");
47
+ const types_1 = require("../../types");
48
+ const node_fetch_1 = __importDefault(require("node-fetch"));
49
+ const crypto_1 = __importStar(require("crypto"));
50
+ const path_1 = require("path");
51
+ const svg = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
52
+ <svg
53
+ xmlns:svg="http://www.w3.org/2000/svg"
54
+ xmlns="http://www.w3.org/2000/svg"
55
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
56
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
57
+ width="1000"
58
+ height="963.197"
59
+ viewBox="0 0 1000 963.197"
60
+ version="1.1"
61
+ id="svg85">
62
+ <sodipodi:namedview
63
+ id="namedview87"
64
+ pagecolor="#ffffff"
65
+ bordercolor="#666666"
66
+ borderopacity="1.0"
67
+ inkscape:pageshadow="2"
68
+ inkscape:pageopacity="0.0"
69
+ inkscape:pagecheckerboard="0"
70
+ showgrid="false"
71
+ inkscape:zoom="1"
72
+ inkscape:cx="991.5"
73
+ inkscape:cy="964.5"
74
+ inkscape:window-width="1126"
75
+ inkscape:window-height="895"
76
+ inkscape:window-x="774"
77
+ inkscape:window-y="12"
78
+ inkscape:window-maximized="0"
79
+ inkscape:current-layer="svg85" />
80
+ <defs
81
+ id="defs74">
82
+ <style
83
+ id="style72">.cls-1{fill:#e24329;}.cls-2{fill:#fc6d26;}.cls-3{fill:#fca326;}</style>
84
+ </defs>
85
+ <g
86
+ id="LOGO"
87
+ transform="matrix(5.2068817,0,0,5.2068817,-489.30756,-507.76085)">
88
+ <path
89
+ class="cls-1"
90
+ d="m 282.83,170.73 -0.27,-0.69 -26.14,-68.22 a 6.81,6.81 0 0 0 -2.69,-3.24 7,7 0 0 0 -8,0.43 7,7 0 0 0 -2.32,3.52 l -17.65,54 h -71.47 l -17.65,-54 a 6.86,6.86 0 0 0 -2.32,-3.53 7,7 0 0 0 -8,-0.43 6.87,6.87 0 0 0 -2.69,3.24 L 97.44,170 l -0.26,0.69 a 48.54,48.54 0 0 0 16.1,56.1 l 0.09,0.07 0.24,0.17 39.82,29.82 19.7,14.91 12,9.06 a 8.07,8.07 0 0 0 9.76,0 l 12,-9.06 19.7,-14.91 40.06,-30 0.1,-0.08 a 48.56,48.56 0 0 0 16.08,-56.04 z"
91
+ id="path76" />
92
+ <path
93
+ class="cls-2"
94
+ d="m 282.83,170.73 -0.27,-0.69 a 88.3,88.3 0 0 0 -35.15,15.8 L 190,229.25 c 19.55,14.79 36.57,27.64 36.57,27.64 l 40.06,-30 0.1,-0.08 a 48.56,48.56 0 0 0 16.1,-56.08 z"
95
+ id="path78" />
96
+ <path
97
+ class="cls-3"
98
+ d="m 153.43,256.89 19.7,14.91 12,9.06 a 8.07,8.07 0 0 0 9.76,0 l 12,-9.06 19.7,-14.91 c 0,0 -17.04,-12.89 -36.59,-27.64 -19.55,14.75 -36.57,27.64 -36.57,27.64 z"
99
+ id="path80" />
100
+ <path
101
+ class="cls-2"
102
+ d="M 132.58,185.84 A 88.19,88.19 0 0 0 97.44,170 l -0.26,0.69 a 48.54,48.54 0 0 0 16.1,56.1 l 0.09,0.07 0.24,0.17 39.82,29.82 c 0,0 17,-12.85 36.57,-27.64 z"
103
+ id="path82" />
104
+ </g>
105
+ </svg>`;
106
+ const encodedSvg = encodeURIComponent(svg);
107
+ const ICON = '/assets/gitlab.png';
108
+ class GitlabConnector {
109
+ config;
110
+ connectorId = 'gitlab';
111
+ connectorType = types_1.ConnectorType.STORAGE;
112
+ displayName = 'GitLab';
113
+ icon = ICON;
114
+ disableLogout = false;
115
+ color = '#2B1B63';
116
+ background = 'rgba(252, 109, 38, 0.2)';
117
+ options;
118
+ constructor(config, opts) {
119
+ this.config = config;
120
+ this.options = {
121
+ branch: 'main',
122
+ assetsFolder: 'assets',
123
+ //metaRepo: 'silex-meta',
124
+ //metaRepoFile: 'websites.json',
125
+ repoPrefix: 'silex_',
126
+ scope: 'api', // 'api+read_api+read_user+read_repository+write_repository+email+sudo+profile+openid'
127
+ ...opts,
128
+ };
129
+ if (!this.options.clientId)
130
+ throw new Error('Missing Gitlab client ID');
131
+ if (!this.options.clientSecret)
132
+ throw new Error('Missing Gitlab client secret');
133
+ if (!this.options.domain)
134
+ throw new Error('Missing Gitlab domain');
135
+ if (!this.options.timeOut)
136
+ this.options.timeOut = 15000; /* default value */
137
+ }
138
+ // **
139
+ // Convenience methods for the Gitlab API
140
+ getAssetPath(path) {
141
+ return encodeURIComponent((0, path_1.join)(this.options.assetsFolder, path));
142
+ }
143
+ isUsingOfficialInstance() {
144
+ const gitlabDomainRegexp = /(^|\b)(gitlab\.com)($|\b)/;
145
+ return gitlabDomainRegexp.test(this.options.domain);
146
+ }
147
+ async createFile(session, websiteId, path, content, isBase64 = false) {
148
+ // Remove leading slash
149
+ const safePath = path.replace(/^\//, '');
150
+ const encodePath = decodeURIComponent(path);
151
+ return this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${safePath}`, 'POST', {
152
+ id: websiteId,
153
+ branch: this.options.branch,
154
+ content,
155
+ commit_message: `Create file ${encodePath} from Silex`,
156
+ encoding: isBase64 ? 'base64' : undefined,
157
+ });
158
+ }
159
+ async updateFile(session, websiteId, path, content, isBase64 = false) {
160
+ // Remove leading slash
161
+ const safePath = path.replace(/^\//, '');
162
+ const encodePath = decodeURIComponent(path);
163
+ return this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${safePath}`, 'PUT', {
164
+ id: websiteId,
165
+ branch: this.options.branch,
166
+ content: await (0, connectors_1.contentToString)(content),
167
+ commit_message: `Update website asset ${encodePath} from Silex`,
168
+ encoding: isBase64 ? 'base64' : undefined,
169
+ });
170
+ }
171
+ async readFile(session, websiteId, fileName) {
172
+ const safePath = fileName.replace(/^\//, '');
173
+ // Call the API
174
+ const url = `${this.options.domain}/api/v4/projects/${websiteId}/repository/files/${safePath}?ref=${this.options.branch}&access_token=${this.getSessionToken(session).token?.access_token}`;
175
+ const response = await (0, node_fetch_1.default)(url, {
176
+ method: 'GET',
177
+ headers: {
178
+ 'Content-Type': 'application/json',
179
+ },
180
+ });
181
+ const json = await response.json();
182
+ if (!response.ok)
183
+ throw new types_1.ApiError(`Error reading file "${fileName}" from Gitlab: ${json?.message ?? json?.error ?? response.statusText}`, response.status);
184
+ // From base64 string to buffer
185
+ const buf = Buffer.from(json.content, 'base64');
186
+ // Return the image bytes
187
+ return buf;
188
+ }
189
+ /*
190
+ * Get the meta repo path for the current user
191
+ * The meta repo contains a JSON file which contains the list of websites
192
+ */
193
+ //private getMetaRepoPath(session: GitlabSession): string {
194
+ // if(!this.getSessionToken(session).username) throw new ApiError('Missing Gitlab user ID. User not logged in?', 401)
195
+ // return encodeURIComponent(`${this.getSessionToken(session).username}/${this.options.metaRepo}`)
196
+ //}
197
+ ///**
198
+ // * Initialize the storage with a meta repo
199
+ // */
200
+ //private async initStorage(session: GitlabSession): Promise<void> {
201
+ // // Create the meta repo
202
+ // try {
203
+ // const project = await this.callApi(session, 'api/v4/projects/', 'POST', {
204
+ // name: this.options.metaRepo,
205
+ // }) as any
206
+ // return this.createFile(session, this.getMetaRepoPath(session), this.options.metaRepoFile, JSON.stringify({
207
+ // websites: {}
208
+ // } as MetaRepoFileContent))
209
+ // } catch (e) {
210
+ // console.error('Could not init storage', e.statusCode, e.httpStatusCode, e)
211
+ // throw e
212
+ // }
213
+ //}
214
+ /**
215
+ * Call the Gitlab API with the user's token and handle errors
216
+ */
217
+ async callApi(session, path, method = 'GET', body = null, params = {}) {
218
+ const token = this.getSessionToken(session).token;
219
+ const tokenParam = token ? `access_token=${token.access_token}&` : '';
220
+ const paramsStr = Object.entries(params).map(([k, v]) => `${k}=${encodeURIComponent(v.toString())}`).join('&');
221
+ const url = `${this.options.domain}/${path}?${tokenParam}${paramsStr}`;
222
+ const headers = {
223
+ 'Content-Type': 'application/json',
224
+ };
225
+ if (method === 'GET' && body) {
226
+ console.error('Gitlab API error (4) - GET request with body', { url, method, body, params });
227
+ }
228
+ // With or without body
229
+ let response;
230
+ try {
231
+ response = await (0, node_fetch_1.default)(url, body && method !== 'GET' ? {
232
+ method,
233
+ headers,
234
+ body: body ? JSON.stringify(body) : undefined
235
+ } : {
236
+ method,
237
+ headers,
238
+ });
239
+ }
240
+ catch (e) {
241
+ console.error('Gitlab API error (0)', e);
242
+ throw new types_1.ApiError(`Gitlab API error (0): ${e.message} ${e.code} ${e.name} ${e.type}`, 500);
243
+ }
244
+ let json;
245
+ // Handle the case when the server returns a non-JSON response (e.g. 400 Bad Request)
246
+ const text = await response.text();
247
+ if (!response.ok) {
248
+ if (text.includes('A file with this name doesn\'t exist')) {
249
+ throw new types_1.ApiError('Gitlab API error (5): Not Found', 404);
250
+ }
251
+ else if (response.status === 401 && this.getSessionToken(session).token?.refresh_token) {
252
+ // Refresh the token
253
+ const token = this.getSessionToken(session).token;
254
+ const body = {
255
+ grant_type: 'refresh_token',
256
+ refresh_token: token?.refresh_token,
257
+ client_id: this.options.clientId,
258
+ client_secret: this.options.clientSecret,
259
+ };
260
+ const response = await (0, node_fetch_1.default)(this.options.domain + '/oauth/token', {
261
+ method: 'POST',
262
+ headers: {
263
+ 'Content-Type': 'application/json',
264
+ },
265
+ body: JSON.stringify(body)
266
+ });
267
+ const refreshJson = await response.json();
268
+ if (response.ok) {
269
+ this.setSessionToken(session, {
270
+ token: {
271
+ ...token,
272
+ ...refreshJson,
273
+ },
274
+ });
275
+ return await this.callApi(session, path, method, body, params);
276
+ }
277
+ else {
278
+ const message = typeof refreshJson?.message === 'object' ? Object.entries(refreshJson.message).map(entry => entry.join(' ')).join(' ') : refreshJson?.message ?? refreshJson?.error ?? response.statusText;
279
+ console.error('Gitlab API error (2) - could not refresh token', response.status, response.statusText, { message }, 'refresh_token:', token?.refresh_token);
280
+ // Workaround for when the token is invalid
281
+ // It happens often which is not normal (refresh token should last 6 months)
282
+ this.logout(session);
283
+ // Notify the user
284
+ throw new types_1.ApiError(`Gitlab API error (2): ${message}`, response.status);
285
+ }
286
+ }
287
+ else {
288
+ const message = typeof json?.message === 'object' ? Object.entries(json.message).map(entry => entry.join(' ')).join(' ') : json?.message ?? json?.error ?? response.statusText;
289
+ console.error('Gitlab API error (1)', response.status, response.statusText, { url, method, body, params, text, message });
290
+ throw new types_1.ApiError(`Gitlab API error (1): ${message}`, response.status);
291
+ }
292
+ }
293
+ try {
294
+ json = JSON.parse(text);
295
+ }
296
+ catch (e) {
297
+ if (!response.ok) {
298
+ // A real error
299
+ throw e;
300
+ }
301
+ else {
302
+ // Useless error linked to the fact that the response is not JSON
303
+ console.error('Gitlab API error (3) - could not parse response', response.status, response.statusText, { url, method, body, params, text });
304
+ return text;
305
+ }
306
+ }
307
+ return json;
308
+ }
309
+ generateCodeVerifier() {
310
+ return crypto_1.default.randomBytes(64).toString('base64')
311
+ .replace(/\+/g, '-')
312
+ .replace(/\//g, '_')
313
+ .replace(/=/g, '')
314
+ .substr(0, 128);
315
+ }
316
+ async generateCodeChallenge(verifier) {
317
+ const hashed = (0, crypto_1.createHash)('sha256').update(verifier).digest();
318
+ let base64Url = hashed.toString('base64');
319
+ // Replace '+' with '-', '/' with '_', and remove '='
320
+ base64Url = base64Url.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
321
+ return base64Url;
322
+ }
323
+ getRedirect() {
324
+ const params = `connectorId=${this.connectorId}&type=${this.connectorType}`;
325
+ return `${this.config.url}${constants_1.API_PATH}${constants_1.API_CONNECTOR_PATH}${constants_1.API_CONNECTOR_LOGIN_CALLBACK}?${params}`;
326
+ }
327
+ /**
328
+ * Get the OAuth URL to redirect the user to
329
+ * The URL should look like
330
+ * https://gitlab.example.com/oauth/authorize?client_id=APP_ID&redirect_uri=REDIRECT_URI&response_type=code&state=STATE&scope=REQUESTED_SCOPES&code_challenge=CODE_CHALLENGE&code_challenge_method=S256
331
+ * OAuth2 Step #1 from https://docs.gitlab.com/ee/api/oauth2.html#authorization-code-with-proof-key-for-code-exchange-pkce
332
+ */
333
+ async getOAuthUrl(session) {
334
+ const redirect_uri = encodeURIComponent(this.getRedirect());
335
+ const state = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
336
+ const codeVerifier = this.generateCodeVerifier();
337
+ // Create the code challenge
338
+ const codeChallenge = await this.generateCodeChallenge(codeVerifier);
339
+ // Store the code verifier and code challenge in the session
340
+ this.setSessionToken(session, {
341
+ ...this.getSessionToken(session),
342
+ state,
343
+ codeVerifier,
344
+ codeChallenge,
345
+ });
346
+ return `${this.options.domain}/oauth/authorize?client_id=${this.options.clientId}&redirect_uri=${redirect_uri}&response_type=code&state=${this.getSessionToken(session).state}&scope=${this.options.scope}&code_challenge=${codeChallenge}&code_challenge_method=S256`;
347
+ }
348
+ getSessionToken(session) {
349
+ return (session ?? {})[this.connectorId] ?? {};
350
+ }
351
+ setSessionToken(session, token) {
352
+ session[this.connectorId] = token;
353
+ }
354
+ resetSessionToken(session) {
355
+ delete session[this.connectorId];
356
+ }
357
+ getOptions(formData) {
358
+ return {}; // FIXME: store branch
359
+ }
360
+ async getLoginForm(session, redirectTo) {
361
+ return null;
362
+ }
363
+ async getSettingsForm(session, redirectTo) {
364
+ return null;
365
+ }
366
+ async isLoggedIn(session) {
367
+ return !!this.getSessionToken(session).token;
368
+ }
369
+ /**
370
+ * Get the token from return code
371
+ * Set the token in the session
372
+ * OAuth2 Step #2 from https://docs.gitlab.com/ee/api/oauth2.html#authorization-code-with-proof-key-for-code-exchange-pkce
373
+ */
374
+ async setToken(session, loginResult) {
375
+ const sessionToken = this.getSessionToken(session);
376
+ if (!loginResult.state || loginResult.state !== sessionToken?.state) {
377
+ this.logout(session);
378
+ throw new types_1.ApiError('Invalid state', 401);
379
+ }
380
+ if (!sessionToken?.codeVerifier) {
381
+ this.logout(session);
382
+ throw new types_1.ApiError('Missing code verifier', 401);
383
+ }
384
+ if (!sessionToken?.codeChallenge) {
385
+ this.logout(session);
386
+ throw new types_1.ApiError('Missing code challenge', 401);
387
+ }
388
+ const response = await (0, node_fetch_1.default)(this.options.domain + '/oauth/token', {
389
+ method: 'POST',
390
+ headers: {
391
+ 'Content-Type': 'application/json',
392
+ },
393
+ body: JSON.stringify({
394
+ client_id: this.options.clientId,
395
+ client_secret: this.options.clientSecret,
396
+ code: loginResult.code,
397
+ grant_type: 'authorization_code',
398
+ redirect_uri: this.getRedirect(),
399
+ code_verifier: sessionToken.codeVerifier,
400
+ }),
401
+ });
402
+ const token = await response.json();
403
+ // Store the token in the session
404
+ this.setSessionToken(session, {
405
+ token,
406
+ ...this.getSessionToken(session),
407
+ });
408
+ // We need to get the user ID for listWebsites
409
+ const user = await this.callApi(session, 'api/v4/user');
410
+ // Store the user details in the session
411
+ this.setSessionToken(session, {
412
+ ...this.getSessionToken(session),
413
+ userId: user.id,
414
+ username: user.username,
415
+ });
416
+ }
417
+ async logout(session) {
418
+ this.resetSessionToken(session);
419
+ }
420
+ async getUser(session) {
421
+ const user = await this.callApi(session, 'api/v4/user');
422
+ return {
423
+ name: user.name,
424
+ email: user.email,
425
+ picture: user.avatar_url,
426
+ storage: await (0, connectors_1.toConnectorData)(session, this),
427
+ };
428
+ }
429
+ async listWebsites(session) {
430
+ //try {
431
+ // const result = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
432
+ // ref: this.options.branch,
433
+ // })
434
+ // const { content } = result
435
+ // const contentDecoded = Buffer.from(content, 'base64').toString('utf8')
436
+ // const websites = (JSON.parse(contentDecoded) as MetaRepoFileContent).websites
437
+ // return Object.entries(websites).map(([websiteId, {meta, createdAt, updatedAt}]) => ({
438
+ // websiteId,
439
+ // createdAt: new Date(createdAt),
440
+ // updatedAt: new Date(updatedAt),
441
+ // ...meta,
442
+ // }))
443
+ //} catch (e) {
444
+ // console.error('Could not list websites', e.statusCode, e.httpStatusCode, e.code)
445
+ // if (e.statusCode === 404 || e.httpStatusCode === 404) {
446
+ // await this.initStorage(session)
447
+ // return []
448
+ // } else {
449
+ // throw e
450
+ // }
451
+ //}
452
+ const userId = this.getSessionToken(session).userId;
453
+ if (!userId) {
454
+ this.logout(session);
455
+ throw new types_1.ApiError('Missing Gitlab user ID. User not logged in?', 401);
456
+ }
457
+ const projects = await this.callApi(session, `api/v4/users/${userId}/projects`);
458
+ return projects
459
+ .filter(p => p.name.startsWith(this.options.repoPrefix))
460
+ .map(p => ({
461
+ websiteId: p.id,
462
+ name: p.name.replace(this.options.repoPrefix, ''),
463
+ createdAt: p.created_at,
464
+ updatedAt: p.last_activity_at,
465
+ connectorUserSettings: {},
466
+ }));
467
+ }
468
+ async readWebsite(session, websiteId) {
469
+ const result = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${constants_1.WEBSITE_DATA_FILE}`, 'GET', null, {
470
+ ref: this.options.branch,
471
+ });
472
+ const { content } = result;
473
+ const contentDecoded = Buffer.from(content, 'base64').toString('utf8');
474
+ const websiteData = JSON.parse(contentDecoded);
475
+ return websiteData;
476
+ }
477
+ async createWebsite(session, websiteMeta) {
478
+ const project = await this.callApi(session, 'api/v4/projects/', 'POST', {
479
+ name: this.options.repoPrefix + websiteMeta.name,
480
+ });
481
+ await this.createFile(session, project.id, constants_1.WEBSITE_DATA_FILE, JSON.stringify({}));
482
+ //await this.createFile(session, project.id, WEBSITE_META_DATA_FILE, JSON.stringify(websiteMeta))
483
+ //await this.updateWebsite(session, project.id, {} as WebsiteData)
484
+ //await this.setWebsiteMeta(session, project.id, websiteMeta)
485
+ return project.id;
486
+ }
487
+ async updateWebsite(session, websiteId, websiteData) {
488
+ const project = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${constants_1.WEBSITE_DATA_FILE}`, 'PUT', {
489
+ branch: this.options.branch,
490
+ commit_message: 'Update website data from Silex',
491
+ content: JSON.stringify(websiteData),
492
+ id: websiteId,
493
+ });
494
+ }
495
+ async deleteWebsite(session, websiteId) {
496
+ // Delete repo
497
+ await this.callApi(session, `api/v4/projects/${websiteId}`, 'DELETE');
498
+ //// Load the meta repo data
499
+ //const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
500
+ // ref: this.options.branch,
501
+ //})
502
+ //const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
503
+ //const data = metaRepo.websites[websiteId]
504
+ //if(!data) throw new ApiError(`Website ${websiteId} not found`, 404)
505
+ //// Update or create the website meta data
506
+ //delete metaRepo.websites[websiteId]
507
+ //// Save the meta repo data
508
+ //const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
509
+ // branch: this.options.branch,
510
+ // commit_message: `Delete meta data of ${data.meta.name} (${websiteId}) from Silex`,
511
+ // content: JSON.stringify(metaRepo),
512
+ // file_path: this.options.metaRepoFile,
513
+ //})
514
+ }
515
+ async duplicateWebsite(session, websiteId) {
516
+ // Get the repo meta data
517
+ const meta = await this.getWebsiteMeta(session, websiteId);
518
+ // List all the repository files
519
+ const blobs = await this.callApi(session, `api/v4/projects/${websiteId}/repository/tree`, 'GET', null, {
520
+ recursive: true,
521
+ });
522
+ const files = blobs
523
+ .filter(item => item.type === 'blob')
524
+ .map(item => item.path);
525
+ // Create a new repo
526
+ const newId = await this.createWebsite(session, {
527
+ ...meta,
528
+ name: meta.name + ' Copy ' + new Date().toISOString().replace(/T.*/, '') + ' ' + Math.random().toString(36).substring(2, 4),
529
+ });
530
+ // Upload all files
531
+ for (const file of files) {
532
+ const path = encodeURIComponent(file);
533
+ const content = await this.readFile(session, websiteId, path);
534
+ // From buffer to string
535
+ const contentStr = content.toString('base64');
536
+ switch (file) {
537
+ case constants_1.WEBSITE_DATA_FILE:
538
+ await this.updateFile(session, newId, path, contentStr, true);
539
+ break;
540
+ default:
541
+ await this.createFile(session, newId, path, contentStr, true);
542
+ }
543
+ }
544
+ }
545
+ async getWebsiteMeta(session, websiteId) {
546
+ //const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
547
+ // ref: this.options.branch,
548
+ //})
549
+ //const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
550
+ //if(!metaRepo.websites[websiteId]) throw new ApiError(`Website ${websiteId} not found`, 404)
551
+ //return {
552
+ // websiteId,
553
+ // createdAt: new Date(metaRepo.websites[websiteId].createdAt),
554
+ // updatedAt: new Date(metaRepo.websites[websiteId].updatedAt),
555
+ // ...metaRepo.websites[websiteId].meta,
556
+ //}
557
+ // const response = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`, 'GET', null, {
558
+ // ref: this.options.branch,
559
+ // }) as any
560
+ // Base64 to string to JSON
561
+ // const contentDecoded = Buffer.from(response.content, 'base64').toString('utf8')
562
+ // const websiteMeta = JSON.parse(contentDecoded) as WebsiteMetaFileContent
563
+ const project = await this.callApi(session, `api/v4/projects/${websiteId}`);
564
+ return {
565
+ websiteId,
566
+ name: project.name.replace(this.options.repoPrefix, ''),
567
+ imageUrl: project.avatar_url,
568
+ createdAt: project.created_at,
569
+ updatedAt: project.last_activity_at,
570
+ connectorUserSettings: {},
571
+ };
572
+ }
573
+ async setWebsiteMeta(session, websiteId, websiteMeta) {
574
+ //// Load the meta repo data
575
+ //const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
576
+ // ref: this.options.branch,
577
+ //})
578
+ //const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
579
+ //// Update or create the website meta data
580
+ //metaRepo.websites[websiteId] = {
581
+ // updatedAt: new Date().toISOString(),
582
+ // createdAt: metaRepo.websites[websiteId]?.createdAt ?? new Date().toISOString(),
583
+ // meta: websiteMeta,
584
+ //}
585
+ //// Save the meta repo data
586
+ //const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
587
+ // branch: this.options.branch,
588
+ // commit_message: `Update website meta data of ${websiteMeta.name} (${websiteId}) from Silex`,
589
+ // content: JSON.stringify(metaRepo),
590
+ // file_path: this.options.metaRepoFile,
591
+ //})
592
+ // Rename the repo if needed
593
+ const oldMeta = await this.getWebsiteMeta(session, websiteId);
594
+ if (websiteMeta.name !== oldMeta.name) {
595
+ await this.callApi(session, `api/v4/projects/${websiteId}`, 'PUT', {
596
+ name: this.options.repoPrefix + websiteMeta.name,
597
+ });
598
+ }
599
+ //// Update the metadata file
600
+ //await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`, 'PUT', {
601
+ // branch: this.options.branch,
602
+ // commit_message: 'Update website meta data from Silex',
603
+ // content: JSON.stringify(websiteMeta),
604
+ // file_path: WEBSITE_META_DATA_FILE,
605
+ // id: websiteId,
606
+ //})
607
+ }
608
+ async writeAssets(session, websiteId, files, status) {
609
+ status && await status({ message: 'in progress...', status: types_1.JobStatus.IN_PROGRESS });
610
+ // For each file
611
+ for (const file of files) {
612
+ // Convert to base64
613
+ const content = (await (0, connectors_1.contentToBuffer)(file.content)).toString('base64');
614
+ const path = this.getAssetPath(file.path);
615
+ try {
616
+ await this.updateFile(session, websiteId, path, content, true);
617
+ }
618
+ catch (e) {
619
+ // If the file does not exist, create it
620
+ if (e.statusCode === 404 || e.httpStatusCode === 404 || e.message.endsWith('A file with this name doesn\'t exist')) {
621
+ await this.createFile(session, websiteId, path, content, true);
622
+ }
623
+ else {
624
+ status && await status({ message: 'Error', status: types_1.JobStatus.ERROR });
625
+ throw e;
626
+ }
627
+ }
628
+ }
629
+ status && await status({ message: 'Successfull', status: types_1.JobStatus.SUCCESS });
630
+ }
631
+ async readAsset(session, websiteId, fileName) {
632
+ // Remove leading slash
633
+ const finalPath = this.getAssetPath(fileName);
634
+ return this.readFile(session, websiteId, finalPath);
635
+ }
636
+ async deleteAssets(session, websiteId, fileNames) {
637
+ return this.callApi(session, `api/v4/projects/${websiteId}/repository/commits`, 'POST', {
638
+ id: websiteId,
639
+ branch: this.options.branch,
640
+ commit_message: `Delete assets from Silex: ${fileNames.join(', ')}`,
641
+ actions: fileNames.map(f => ({
642
+ action: 'delete',
643
+ file_path: this.getAssetPath(f),
644
+ })),
645
+ });
646
+ }
647
+ }
648
+ exports.default = GitlabConnector;
649
+ //# sourceMappingURL=GitlabConnector.js.map