@tasenor/common-node 1.9.16

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 (326) hide show
  1. package/.eslintrc.js +4 -0
  2. package/LICENSE +21 -0
  3. package/dist/tasenor-common-node/src/cli.d.ts +81 -0
  4. package/dist/tasenor-common-node/src/cli.js +242 -0
  5. package/dist/tasenor-common-node/src/cli.js.map +1 -0
  6. package/dist/tasenor-common-node/src/commands/account.d.ts +12 -0
  7. package/dist/tasenor-common-node/src/commands/account.js +58 -0
  8. package/dist/tasenor-common-node/src/commands/account.js.map +1 -0
  9. package/dist/tasenor-common-node/src/commands/balance.d.ts +11 -0
  10. package/dist/tasenor-common-node/src/commands/balance.js +117 -0
  11. package/dist/tasenor-common-node/src/commands/balance.js.map +1 -0
  12. package/dist/tasenor-common-node/src/commands/db.d.ts +14 -0
  13. package/dist/tasenor-common-node/src/commands/db.js +69 -0
  14. package/dist/tasenor-common-node/src/commands/db.js.map +1 -0
  15. package/dist/tasenor-common-node/src/commands/entry.d.ts +13 -0
  16. package/dist/tasenor-common-node/src/commands/entry.js +106 -0
  17. package/dist/tasenor-common-node/src/commands/entry.js.map +1 -0
  18. package/dist/tasenor-common-node/src/commands/import.d.ts +17 -0
  19. package/dist/tasenor-common-node/src/commands/import.js +140 -0
  20. package/dist/tasenor-common-node/src/commands/import.js.map +1 -0
  21. package/dist/tasenor-common-node/src/commands/importer.d.ts +13 -0
  22. package/dist/tasenor-common-node/src/commands/importer.js +71 -0
  23. package/dist/tasenor-common-node/src/commands/importer.js.map +1 -0
  24. package/dist/tasenor-common-node/src/commands/index.d.ts +191 -0
  25. package/dist/tasenor-common-node/src/commands/index.js +482 -0
  26. package/dist/tasenor-common-node/src/commands/index.js.map +1 -0
  27. package/dist/tasenor-common-node/src/commands/period.d.ts +12 -0
  28. package/dist/tasenor-common-node/src/commands/period.js +48 -0
  29. package/dist/tasenor-common-node/src/commands/period.js.map +1 -0
  30. package/dist/tasenor-common-node/src/commands/plugin.d.ts +15 -0
  31. package/dist/tasenor-common-node/src/commands/plugin.js +78 -0
  32. package/dist/tasenor-common-node/src/commands/plugin.js.map +1 -0
  33. package/dist/tasenor-common-node/src/commands/report.d.ts +11 -0
  34. package/dist/tasenor-common-node/src/commands/report.js +96 -0
  35. package/dist/tasenor-common-node/src/commands/report.js.map +1 -0
  36. package/dist/tasenor-common-node/src/commands/settings.d.ts +10 -0
  37. package/dist/tasenor-common-node/src/commands/settings.js +64 -0
  38. package/dist/tasenor-common-node/src/commands/settings.js.map +1 -0
  39. package/dist/tasenor-common-node/src/commands/stock.d.ts +8 -0
  40. package/dist/tasenor-common-node/src/commands/stock.js +73 -0
  41. package/dist/tasenor-common-node/src/commands/stock.js.map +1 -0
  42. package/dist/tasenor-common-node/src/commands/tag.d.ts +13 -0
  43. package/dist/tasenor-common-node/src/commands/tag.js +89 -0
  44. package/dist/tasenor-common-node/src/commands/tag.js.map +1 -0
  45. package/dist/tasenor-common-node/src/commands/tx.d.ts +12 -0
  46. package/dist/tasenor-common-node/src/commands/tx.js +81 -0
  47. package/dist/tasenor-common-node/src/commands/tx.js.map +1 -0
  48. package/dist/tasenor-common-node/src/commands/user.d.ts +12 -0
  49. package/dist/tasenor-common-node/src/commands/user.js +52 -0
  50. package/dist/tasenor-common-node/src/commands/user.js.map +1 -0
  51. package/dist/tasenor-common-node/src/database/BookkeeperImporter.d.ts +77 -0
  52. package/dist/tasenor-common-node/src/database/BookkeeperImporter.js +343 -0
  53. package/dist/tasenor-common-node/src/database/BookkeeperImporter.js.map +1 -0
  54. package/dist/tasenor-common-node/src/database/DB.d.ts +51 -0
  55. package/dist/tasenor-common-node/src/database/DB.js +354 -0
  56. package/dist/tasenor-common-node/src/database/DB.js.map +1 -0
  57. package/dist/tasenor-common-node/src/database/index.d.ts +7 -0
  58. package/dist/tasenor-common-node/src/database/index.js +8 -0
  59. package/dist/tasenor-common-node/src/database/index.js.map +1 -0
  60. package/dist/tasenor-common-node/src/doccer.d.ts +29 -0
  61. package/dist/tasenor-common-node/src/doccer.js +30 -0
  62. package/dist/tasenor-common-node/src/doccer.js.map +1 -0
  63. package/dist/tasenor-common-node/src/error.d.ts +30 -0
  64. package/dist/tasenor-common-node/src/error.js +35 -0
  65. package/dist/tasenor-common-node/src/error.js.map +1 -0
  66. package/dist/tasenor-common-node/src/export/Exporter.d.ts +69 -0
  67. package/dist/tasenor-common-node/src/export/Exporter.js +123 -0
  68. package/dist/tasenor-common-node/src/export/Exporter.js.map +1 -0
  69. package/dist/tasenor-common-node/src/export/TasenorExporter.d.ts +55 -0
  70. package/dist/tasenor-common-node/src/export/TasenorExporter.js +135 -0
  71. package/dist/tasenor-common-node/src/export/TasenorExporter.js.map +1 -0
  72. package/dist/tasenor-common-node/src/export/TilitinExporter.d.ts +71 -0
  73. package/dist/tasenor-common-node/src/export/TilitinExporter.js +290 -0
  74. package/dist/tasenor-common-node/src/export/TilitinExporter.js.map +1 -0
  75. package/dist/tasenor-common-node/src/export/index.d.ts +8 -0
  76. package/dist/tasenor-common-node/src/export/index.js +9 -0
  77. package/dist/tasenor-common-node/src/export/index.js.map +1 -0
  78. package/dist/tasenor-common-node/src/import/TextFileProcessHandler.d.ts +104 -0
  79. package/dist/tasenor-common-node/src/import/TextFileProcessHandler.js +354 -0
  80. package/dist/tasenor-common-node/src/import/TextFileProcessHandler.js.map +1 -0
  81. package/dist/tasenor-common-node/src/import/TransactionImportConnector.d.ts +38 -0
  82. package/dist/tasenor-common-node/src/import/TransactionImportConnector.js +27 -0
  83. package/dist/tasenor-common-node/src/import/TransactionImportConnector.js.map +1 -0
  84. package/dist/tasenor-common-node/src/import/TransactionImportHandler.d.ts +173 -0
  85. package/dist/tasenor-common-node/src/import/TransactionImportHandler.js +733 -0
  86. package/dist/tasenor-common-node/src/import/TransactionImportHandler.js.map +1 -0
  87. package/dist/tasenor-common-node/src/import/TransactionRules.d.ts +238 -0
  88. package/dist/tasenor-common-node/src/import/TransactionRules.js +522 -0
  89. package/dist/tasenor-common-node/src/import/TransactionRules.js.map +1 -0
  90. package/dist/tasenor-common-node/src/import/TransactionUI.d.ts +181 -0
  91. package/dist/tasenor-common-node/src/import/TransactionUI.js +482 -0
  92. package/dist/tasenor-common-node/src/import/TransactionUI.js.map +1 -0
  93. package/dist/tasenor-common-node/src/import/TransferAnalyzer.d.ts +324 -0
  94. package/dist/tasenor-common-node/src/import/TransferAnalyzer.js +1379 -0
  95. package/dist/tasenor-common-node/src/import/TransferAnalyzer.js.map +1 -0
  96. package/dist/tasenor-common-node/src/import/index.d.ts +11 -0
  97. package/dist/tasenor-common-node/src/import/index.js +12 -0
  98. package/dist/tasenor-common-node/src/import/index.js.map +1 -0
  99. package/dist/tasenor-common-node/src/index.d.ts +12 -0
  100. package/dist/tasenor-common-node/src/index.js +13 -0
  101. package/dist/tasenor-common-node/src/index.js.map +1 -0
  102. package/dist/tasenor-common-node/src/net/crypto.d.ts +33 -0
  103. package/dist/tasenor-common-node/src/net/crypto.js +63 -0
  104. package/dist/tasenor-common-node/src/net/crypto.js.map +1 -0
  105. package/dist/tasenor-common-node/src/net/git.d.ts +49 -0
  106. package/dist/tasenor-common-node/src/net/git.js +137 -0
  107. package/dist/tasenor-common-node/src/net/git.js.map +1 -0
  108. package/dist/tasenor-common-node/src/net/index.d.ts +10 -0
  109. package/dist/tasenor-common-node/src/net/index.js +11 -0
  110. package/dist/tasenor-common-node/src/net/index.js.map +1 -0
  111. package/dist/tasenor-common-node/src/net/middleware.d.ts +61 -0
  112. package/dist/tasenor-common-node/src/net/middleware.js +220 -0
  113. package/dist/tasenor-common-node/src/net/middleware.js.map +1 -0
  114. package/dist/tasenor-common-node/src/net/tokens.d.ts +50 -0
  115. package/dist/tasenor-common-node/src/net/tokens.js +141 -0
  116. package/dist/tasenor-common-node/src/net/tokens.js.map +1 -0
  117. package/dist/tasenor-common-node/src/net/vault.d.ts +67 -0
  118. package/dist/tasenor-common-node/src/net/vault.js +145 -0
  119. package/dist/tasenor-common-node/src/net/vault.js.map +1 -0
  120. package/dist/tasenor-common-node/src/plugins/BackendPlugin.d.ts +91 -0
  121. package/dist/tasenor-common-node/src/plugins/BackendPlugin.js +165 -0
  122. package/dist/tasenor-common-node/src/plugins/BackendPlugin.js.map +1 -0
  123. package/dist/tasenor-common-node/src/plugins/DataPlugin.d.ts +13 -0
  124. package/dist/tasenor-common-node/src/plugins/DataPlugin.js +26 -0
  125. package/dist/tasenor-common-node/src/plugins/DataPlugin.js.map +1 -0
  126. package/dist/tasenor-common-node/src/plugins/ImportPlugin.d.ts +188 -0
  127. package/dist/tasenor-common-node/src/plugins/ImportPlugin.js +204 -0
  128. package/dist/tasenor-common-node/src/plugins/ImportPlugin.js.map +1 -0
  129. package/dist/tasenor-common-node/src/plugins/ReportPlugin.d.ts +132 -0
  130. package/dist/tasenor-common-node/src/plugins/ReportPlugin.js +393 -0
  131. package/dist/tasenor-common-node/src/plugins/ReportPlugin.js.map +1 -0
  132. package/dist/tasenor-common-node/src/plugins/SchemePlugin.d.ts +34 -0
  133. package/dist/tasenor-common-node/src/plugins/SchemePlugin.js +47 -0
  134. package/dist/tasenor-common-node/src/plugins/SchemePlugin.js.map +1 -0
  135. package/dist/tasenor-common-node/src/plugins/ServicePlugin.d.ts +80 -0
  136. package/dist/tasenor-common-node/src/plugins/ServicePlugin.js +168 -0
  137. package/dist/tasenor-common-node/src/plugins/ServicePlugin.js.map +1 -0
  138. package/dist/tasenor-common-node/src/plugins/ToolPlugin.d.ts +27 -0
  139. package/dist/tasenor-common-node/src/plugins/ToolPlugin.js +37 -0
  140. package/dist/tasenor-common-node/src/plugins/ToolPlugin.js.map +1 -0
  141. package/dist/tasenor-common-node/src/plugins/index.d.ts +13 -0
  142. package/dist/tasenor-common-node/src/plugins/index.js +14 -0
  143. package/dist/tasenor-common-node/src/plugins/index.js.map +1 -0
  144. package/dist/tasenor-common-node/src/plugins/plugins.d.ts +101 -0
  145. package/dist/tasenor-common-node/src/plugins/plugins.js +292 -0
  146. package/dist/tasenor-common-node/src/plugins/plugins.js.map +1 -0
  147. package/dist/tasenor-common-node/src/process/Process.d.ts +108 -0
  148. package/dist/tasenor-common-node/src/process/Process.js +335 -0
  149. package/dist/tasenor-common-node/src/process/Process.js.map +1 -0
  150. package/dist/tasenor-common-node/src/process/ProcessConnector.d.ts +24 -0
  151. package/dist/tasenor-common-node/src/process/ProcessConnector.js +28 -0
  152. package/dist/tasenor-common-node/src/process/ProcessConnector.js.map +1 -0
  153. package/dist/tasenor-common-node/src/process/ProcessFile.d.ts +69 -0
  154. package/dist/tasenor-common-node/src/process/ProcessFile.js +145 -0
  155. package/dist/tasenor-common-node/src/process/ProcessFile.js.map +1 -0
  156. package/dist/tasenor-common-node/src/process/ProcessHandler.d.ts +60 -0
  157. package/dist/tasenor-common-node/src/process/ProcessHandler.js +73 -0
  158. package/dist/tasenor-common-node/src/process/ProcessHandler.js.map +1 -0
  159. package/dist/tasenor-common-node/src/process/ProcessStep.d.ts +52 -0
  160. package/dist/tasenor-common-node/src/process/ProcessStep.js +78 -0
  161. package/dist/tasenor-common-node/src/process/ProcessStep.js.map +1 -0
  162. package/dist/tasenor-common-node/src/process/ProcessingSystem.d.ts +60 -0
  163. package/dist/tasenor-common-node/src/process/ProcessingSystem.js +182 -0
  164. package/dist/tasenor-common-node/src/process/ProcessingSystem.js.map +1 -0
  165. package/dist/tasenor-common-node/src/process/index.d.ts +11 -0
  166. package/dist/tasenor-common-node/src/process/index.js +12 -0
  167. package/dist/tasenor-common-node/src/process/index.js.map +1 -0
  168. package/dist/tasenor-common-node/src/reports/conversions.d.ts +8 -0
  169. package/dist/tasenor-common-node/src/reports/conversions.js +47 -0
  170. package/dist/tasenor-common-node/src/reports/conversions.js.map +1 -0
  171. package/dist/tasenor-common-node/src/reports/index.d.ts +6 -0
  172. package/dist/tasenor-common-node/src/reports/index.js +7 -0
  173. package/dist/tasenor-common-node/src/reports/index.js.map +1 -0
  174. package/dist/tasenor-common-node/src/server/ISPDemoServer.d.ts +43 -0
  175. package/dist/tasenor-common-node/src/server/ISPDemoServer.js +112 -0
  176. package/dist/tasenor-common-node/src/server/ISPDemoServer.js.map +1 -0
  177. package/dist/tasenor-common-node/src/server/api.d.ts +15 -0
  178. package/dist/tasenor-common-node/src/server/api.js +27 -0
  179. package/dist/tasenor-common-node/src/server/api.js.map +1 -0
  180. package/dist/tasenor-common-node/src/server/index.d.ts +7 -0
  181. package/dist/tasenor-common-node/src/server/index.js +8 -0
  182. package/dist/tasenor-common-node/src/server/index.js.map +1 -0
  183. package/dist/tasenor-common-node/src/server/router.d.ts +5 -0
  184. package/dist/tasenor-common-node/src/server/router.js +37 -0
  185. package/dist/tasenor-common-node/src/server/router.js.map +1 -0
  186. package/dist/tasenor-common-node/src/system.d.ts +27 -0
  187. package/dist/tasenor-common-node/src/system.js +95 -0
  188. package/dist/tasenor-common-node/src/system.js.map +1 -0
  189. package/dist/tasenor-common-node/src/testing/ProcessingSystemMock.d.ts +21 -0
  190. package/dist/tasenor-common-node/src/testing/ProcessingSystemMock.js +33 -0
  191. package/dist/tasenor-common-node/src/testing/ProcessingSystemMock.js.map +1 -0
  192. package/dist/tasenor-common-node/src/testing/UnitTestImportConnector.d.ts +24 -0
  193. package/dist/tasenor-common-node/src/testing/UnitTestImportConnector.js +68 -0
  194. package/dist/tasenor-common-node/src/testing/UnitTestImportConnector.js.map +1 -0
  195. package/dist/tasenor-common-node/src/testing/UnitTester.d.ts +64 -0
  196. package/dist/tasenor-common-node/src/testing/UnitTester.js +199 -0
  197. package/dist/tasenor-common-node/src/testing/UnitTester.js.map +1 -0
  198. package/dist/tasenor-common-node/src/testing/index.d.ts +4 -0
  199. package/dist/tasenor-common-node/src/testing/index.js +5 -0
  200. package/dist/tasenor-common-node/src/testing/index.js.map +1 -0
  201. package/dist/tasenor-common-node/src/testing/test-handlers.d.ts +13 -0
  202. package/dist/tasenor-common-node/src/testing/test-handlers.js +52 -0
  203. package/dist/tasenor-common-node/src/testing/test-handlers.js.map +1 -0
  204. package/dist/tasenor-common-node/tests/TransactionRules.spec.d.ts +1 -0
  205. package/dist/tasenor-common-node/tests/TransactionRules.spec.js +64 -0
  206. package/dist/tasenor-common-node/tests/TransactionRules.spec.js.map +1 -0
  207. package/dist/tasenor-common-node/tests/TransferAnalyzer-account-address.spec.d.ts +1 -0
  208. package/dist/tasenor-common-node/tests/TransferAnalyzer-account-address.spec.js +80 -0
  209. package/dist/tasenor-common-node/tests/TransferAnalyzer-account-address.spec.js.map +1 -0
  210. package/dist/tasenor-common-node/tests/TransferAnalyzer-buying-and-selling.spec.d.ts +1 -0
  211. package/dist/tasenor-common-node/tests/TransferAnalyzer-buying-and-selling.spec.js +342 -0
  212. package/dist/tasenor-common-node/tests/TransferAnalyzer-buying-and-selling.spec.js.map +1 -0
  213. package/dist/tasenor-common-node/tests/TransferAnalyzer-loans.spec.d.ts +1 -0
  214. package/dist/tasenor-common-node/tests/TransferAnalyzer-loans.spec.js +174 -0
  215. package/dist/tasenor-common-node/tests/TransferAnalyzer-loans.spec.js.map +1 -0
  216. package/dist/tasenor-common-node/tests/TransferAnalyzer-multiple-null-amounts.spec.d.ts +1 -0
  217. package/dist/tasenor-common-node/tests/TransferAnalyzer-multiple-null-amounts.spec.js +175 -0
  218. package/dist/tasenor-common-node/tests/TransferAnalyzer-multiple-null-amounts.spec.js.map +1 -0
  219. package/dist/tasenor-common-node/tests/password.spec.d.ts +1 -0
  220. package/dist/tasenor-common-node/tests/password.spec.js +8 -0
  221. package/dist/tasenor-common-node/tests/password.spec.js.map +1 -0
  222. package/dist/tasenor-common-node/tests/tokens.spec.d.ts +1 -0
  223. package/dist/tasenor-common-node/tests/tokens.spec.js +49 -0
  224. package/dist/tasenor-common-node/tests/tokens.spec.js.map +1 -0
  225. package/dist/tasenor-common-node/tests/vault.spec.d.ts +1 -0
  226. package/dist/tasenor-common-node/tests/vault.spec.js +19 -0
  227. package/dist/tasenor-common-node/tests/vault.spec.js.map +1 -0
  228. package/dist/tasenor-common-plugins/src/CoinbaseImport/backend/CoinbaseHandler.d.ts +11 -0
  229. package/dist/tasenor-common-plugins/src/CoinbaseImport/backend/CoinbaseHandler.js +30 -0
  230. package/dist/tasenor-common-plugins/src/CoinbaseImport/backend/CoinbaseHandler.js.map +1 -0
  231. package/dist/tasenor-common-plugins/src/IncomeAndExpenses/backend/index.d.ts +5 -0
  232. package/dist/tasenor-common-plugins/src/IncomeAndExpenses/backend/index.js +350 -0
  233. package/dist/tasenor-common-plugins/src/IncomeAndExpenses/backend/index.js.map +1 -0
  234. package/dist/tasenor-common-plugins/src/KrakenImport/backend/KrakenHandler.d.ts +23 -0
  235. package/dist/tasenor-common-plugins/src/KrakenImport/backend/KrakenHandler.js +83 -0
  236. package/dist/tasenor-common-plugins/src/KrakenImport/backend/KrakenHandler.js.map +1 -0
  237. package/dist/tasenor-common-plugins/src/LynxImport/backend/LynxHandler.d.ts +28 -0
  238. package/dist/tasenor-common-plugins/src/LynxImport/backend/LynxHandler.js +340 -0
  239. package/dist/tasenor-common-plugins/src/LynxImport/backend/LynxHandler.js.map +1 -0
  240. package/dist/tasenor-common-plugins/src/NordeaImport/backend/NordeaHandler.d.ts +11 -0
  241. package/dist/tasenor-common-plugins/src/NordeaImport/backend/NordeaHandler.js +39 -0
  242. package/dist/tasenor-common-plugins/src/NordeaImport/backend/NordeaHandler.js.map +1 -0
  243. package/dist/tasenor-common-plugins/src/NordnetImport/backend/NordnetHandler.d.ts +17 -0
  244. package/dist/tasenor-common-plugins/src/NordnetImport/backend/NordnetHandler.js +66 -0
  245. package/dist/tasenor-common-plugins/src/NordnetImport/backend/NordnetHandler.js.map +1 -0
  246. package/dist/tasenor-common-plugins/src/TITOImport/backend/TITOHandler.d.ts +13 -0
  247. package/dist/tasenor-common-plugins/src/TITOImport/backend/TITOHandler.js +241 -0
  248. package/dist/tasenor-common-plugins/src/TITOImport/backend/TITOHandler.js.map +1 -0
  249. package/jest.config.js +1 -0
  250. package/package.json +62 -0
  251. package/src/cli.ts +267 -0
  252. package/src/commands/account.ts +69 -0
  253. package/src/commands/balance.ts +131 -0
  254. package/src/commands/db.ts +84 -0
  255. package/src/commands/entry.ts +117 -0
  256. package/src/commands/import.ts +160 -0
  257. package/src/commands/importer.ts +84 -0
  258. package/src/commands/index.ts +534 -0
  259. package/src/commands/period.ts +59 -0
  260. package/src/commands/plugin.ts +95 -0
  261. package/src/commands/report.ts +113 -0
  262. package/src/commands/settings.ts +75 -0
  263. package/src/commands/stock.ts +80 -0
  264. package/src/commands/tag.ts +102 -0
  265. package/src/commands/tx.ts +93 -0
  266. package/src/commands/user.ts +65 -0
  267. package/src/database/BookkeeperImporter.ts +358 -0
  268. package/src/database/DB.ts +396 -0
  269. package/src/database/index.ts +7 -0
  270. package/src/doccer.ts +29 -0
  271. package/src/error.ts +32 -0
  272. package/src/export/Exporter.ts +136 -0
  273. package/src/export/TasenorExporter.ts +144 -0
  274. package/src/export/TilitinExporter.ts +302 -0
  275. package/src/export/index.ts +8 -0
  276. package/src/import/TextFileProcessHandler.ts +384 -0
  277. package/src/import/TransactionImportConnector.ts +65 -0
  278. package/src/import/TransactionImportHandler.ts +819 -0
  279. package/src/import/TransactionRules.ts +570 -0
  280. package/src/import/TransactionUI.ts +520 -0
  281. package/src/import/TransferAnalyzer.ts +1450 -0
  282. package/src/import/index.ts +11 -0
  283. package/src/index.ts +12 -0
  284. package/src/net/crypto.ts +69 -0
  285. package/src/net/git.ts +151 -0
  286. package/src/net/index.ts +10 -0
  287. package/src/net/middleware.ts +261 -0
  288. package/src/net/tokens.ts +140 -0
  289. package/src/net/vault.ts +161 -0
  290. package/src/plugins/BackendPlugin.ts +188 -0
  291. package/src/plugins/DataPlugin.ts +29 -0
  292. package/src/plugins/ImportPlugin.ts +211 -0
  293. package/src/plugins/ReportPlugin.ts +443 -0
  294. package/src/plugins/SchemePlugin.ts +56 -0
  295. package/src/plugins/ServicePlugin.ts +188 -0
  296. package/src/plugins/ToolPlugin.ts +44 -0
  297. package/src/plugins/index.ts +13 -0
  298. package/src/plugins/plugins.ts +345 -0
  299. package/src/process/Process.ts +368 -0
  300. package/src/process/ProcessConnector.ts +45 -0
  301. package/src/process/ProcessFile.ts +169 -0
  302. package/src/process/ProcessHandler.ts +94 -0
  303. package/src/process/ProcessStep.ts +100 -0
  304. package/src/process/ProcessingSystem.ts +202 -0
  305. package/src/process/index.ts +11 -0
  306. package/src/reports/conversions.ts +52 -0
  307. package/src/reports/index.ts +6 -0
  308. package/src/server/ISPDemoServer.ts +122 -0
  309. package/src/server/api.ts +37 -0
  310. package/src/server/index.ts +7 -0
  311. package/src/server/router.ts +60 -0
  312. package/src/system.ts +96 -0
  313. package/src/testing/ProcessingSystemMock.ts +45 -0
  314. package/src/testing/UnitTestImportConnector.ts +86 -0
  315. package/src/testing/UnitTester.ts +231 -0
  316. package/src/testing/index.ts +4 -0
  317. package/src/testing/test-handlers.ts +55 -0
  318. package/tests/TransactionRules.spec.ts +73 -0
  319. package/tests/TransferAnalyzer-account-address.spec.ts +87 -0
  320. package/tests/TransferAnalyzer-buying-and-selling.spec.ts +354 -0
  321. package/tests/TransferAnalyzer-loans.spec.ts +197 -0
  322. package/tests/TransferAnalyzer-multiple-null-amounts.spec.ts +181 -0
  323. package/tests/password.spec.ts +8 -0
  324. package/tests/tokens.spec.ts +52 -0
  325. package/tests/vault.spec.ts +20 -0
  326. package/tsconfig.json +13 -0
@@ -0,0 +1,168 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import axios from 'axios';
3
+ import { log, note, error, waitPromise } from '@dataplug/tasenor-common';
4
+ import { BackendPlugin } from './BackendPlugin';
5
+ /**
6
+ * An API end point provider.
7
+ */
8
+ export class ServicePlugin extends BackendPlugin {
9
+ services;
10
+ constructor(...services) {
11
+ super();
12
+ this.services = services;
13
+ }
14
+ getServices() {
15
+ return this.services;
16
+ }
17
+ /**
18
+ * A query executor called by the back end for API request.
19
+ * @param best The currently best solution found.
20
+ * @param db Knex database.
21
+ * @param service Name of the service to called.
22
+ * @param query Query parameters.
23
+ * This calls the actual query function, handles errors and finally modifies `best` if found a solution.
24
+ */
25
+ async executeQuery(best, db, service, query) {
26
+ const settings = {};
27
+ for (const setting of await db('settings').select('*').where('name', 'like', `${this.code}.%`)) {
28
+ const [, name] = setting.name.split('.');
29
+ settings[name] = setting.value;
30
+ }
31
+ // First check if the current answer is adequate.
32
+ if (this.isAdequate(best)) {
33
+ return;
34
+ }
35
+ // Then run the query and catch errors.
36
+ let result;
37
+ try {
38
+ result = await this.query(db, settings, service, query);
39
+ }
40
+ catch (err) {
41
+ error(`Exception when handling service ${service} query ${JSON.stringify(query)}: ${err}`);
42
+ result = {
43
+ status: 500,
44
+ message: `Execution of service ${service} query failed on plugin ${this.constructor.name}.`
45
+ };
46
+ }
47
+ // Combine result.
48
+ this.addResult(best, result);
49
+ }
50
+ /**
51
+ * Perform the actual query.
52
+ *
53
+ * @param db Knex database.
54
+ * @param service Name of the service to called.
55
+ * @param query Query parameters.
56
+ */
57
+ async query(db, settings, service, query) {
58
+ throw new Error(`A service plugin ${this.constructor.name} does not implement query().`);
59
+ }
60
+ /**
61
+ * Combine result of the service query.
62
+ *
63
+ * @param old Currently found solution.
64
+ * @param latest The solution given by this plugin.
65
+ *
66
+ * By default, any 2xx status result will override the current result.
67
+ * Any error result will override initial 404 result.
68
+ * Otherwise the latest is ignored.
69
+ */
70
+ addResult(old, latest) {
71
+ if ((latest.status >= 200 && latest.status < 300) ||
72
+ (old.status === 404 && old.message === 'No handlers found.')) {
73
+ delete old.message;
74
+ Object.assign(old, latest);
75
+ }
76
+ }
77
+ /**
78
+ * Check if the current solution is sufficient.
79
+ * By default, any status 2xx is sufficient.
80
+ */
81
+ isAdequate(solution) {
82
+ return solution.status >= 200 && solution.status < 300;
83
+ }
84
+ /**
85
+ * Execute query to the third party service,
86
+ * @param service
87
+ * @param method
88
+ * @param url
89
+ * @param params
90
+ * @returns Result body.
91
+ */
92
+ async request(service, method, url, params, headers = {}) {
93
+ if (method !== 'GET') {
94
+ throw new Error('Only GET method currently supported in plugin requests.');
95
+ }
96
+ note(`Service ${service} request ${method} ${url}`);
97
+ return new Promise((resolve, reject) => {
98
+ axios.request({ method, url, params, headers })
99
+ .then(response => {
100
+ log(`Request ${method} ${url}: HTTP ${response.status}`);
101
+ resolve({
102
+ status: response.status,
103
+ data: response.data
104
+ });
105
+ })
106
+ .catch(err => {
107
+ const status = err.response ? err.response.status : 500;
108
+ const message = err.response && err.response.data && err.response.data.message ? err.response.data.message : `${err}`;
109
+ error(`Request ${method} ${url} failed: HTTP ${status} ${message}`);
110
+ resolve({
111
+ status,
112
+ message
113
+ });
114
+ });
115
+ });
116
+ }
117
+ /**
118
+ * Pick meaningful keys unique from the headers for using as a key, whe storing result to teh cache.
119
+ * @param service
120
+ * @param header
121
+ * By default, no header is used as cache key.
122
+ */
123
+ cacheHeadersKey(service, header) {
124
+ return {};
125
+ }
126
+ /**
127
+ * Pick meaningful keys unique from the query parameters for using as a key, whe storing result to teh cache.
128
+ * @param service
129
+ * @param params
130
+ * By default, all parameters are used as cache key.
131
+ */
132
+ cacheParamsKey(service, params) {
133
+ return params;
134
+ }
135
+ /**
136
+ * Execute query to the third party service,
137
+ * @param db
138
+ * @param service
139
+ * @param method
140
+ * @param url
141
+ * @param params
142
+ * @returns Result body.
143
+ */
144
+ async cachedRequest(db, service, method, url, params, headers = {}, options = {}) {
145
+ // Get cache keys.
146
+ const keyParams = this.cacheParamsKey(service, params);
147
+ const keyHeaders = this.cacheHeadersKey(service, headers);
148
+ // Check if cached.
149
+ const cached = db ? await db('cached_requests').select('status', 'result').where({ method, url, query: keyParams, headers: keyHeaders }).first() : null;
150
+ if (cached) {
151
+ if (cached.status >= 200 && cached.status < 300) {
152
+ log(`Using cached service ${service} result for ${method} ${url}`);
153
+ return cached.result;
154
+ }
155
+ }
156
+ // Add delay if needed.
157
+ if (options.rateLimitDelay) {
158
+ await waitPromise(options.rateLimitDelay);
159
+ }
160
+ // Do the request and cache the result.
161
+ const result = await this.request(service, method, url, params, headers);
162
+ if (db) {
163
+ await db('cached_requests').insert({ method, url, query: keyParams, headers: keyHeaders, status: result.status || null, result });
164
+ }
165
+ return result;
166
+ }
167
+ }
168
+ //# sourceMappingURL=ServicePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServicePlugin.js","sourceRoot":"","sources":["../../../../src/plugins/ServicePlugin.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAwC,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAC9G,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAO/C;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,aAAa;IAEtC,QAAQ,CAAiB;IAEjC,YAAY,GAAG,QAAQ;QACrB,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY,CAAC,IAAa,EAAE,EAAgB,EAAE,OAAsB,EAAE,KAA8B;QACxG,MAAM,QAAQ,GAA4B,EAAE,CAAA;QAC5C,KAAK,MAAM,OAAO,IAAI,MAAM,EAAE,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE;YAC9F,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACxC,QAAQ,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAA;SAC/B;QAED,iDAAiD;QACjD,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACzB,OAAM;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AE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;QACxE,IAAI,EAAE,EAAE;YACN,MAAM,EAAE,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;SAClI;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
@@ -0,0 +1,27 @@
1
+ import { KnexDatabase } from '../database';
2
+ import { BackendPlugin } from './BackendPlugin';
3
+ /**
4
+ * A generic tool.
5
+ */
6
+ export declare class ToolPlugin extends BackendPlugin {
7
+ /**
8
+ * Handler for GET request.
9
+ */
10
+ GET(db: KnexDatabase, query: any): Promise<unknown>;
11
+ /**
12
+ * Handler for DELETE request.
13
+ */
14
+ DELETE(db: KnexDatabase, query: any): Promise<unknown>;
15
+ /**
16
+ * Handler for POST request.
17
+ */
18
+ POST(db: KnexDatabase, data: any): Promise<unknown>;
19
+ /**
20
+ * Handler for PUT request.
21
+ */
22
+ PUT(db: KnexDatabase, data: any): Promise<unknown>;
23
+ /**
24
+ * Handler for PATCH request.
25
+ */
26
+ PATCH(db: KnexDatabase, data: any): Promise<unknown>;
27
+ }
@@ -0,0 +1,37 @@
1
+ import { BackendPlugin } from './BackendPlugin';
2
+ /**
3
+ * A generic tool.
4
+ */
5
+ export class ToolPlugin extends BackendPlugin {
6
+ /**
7
+ * Handler for GET request.
8
+ */
9
+ async GET(db, query) {
10
+ return undefined;
11
+ }
12
+ /**
13
+ * Handler for DELETE request.
14
+ */
15
+ async DELETE(db, query) {
16
+ return undefined;
17
+ }
18
+ /**
19
+ * Handler for POST request.
20
+ */
21
+ async POST(db, data) {
22
+ return undefined;
23
+ }
24
+ /**
25
+ * Handler for PUT request.
26
+ */
27
+ async PUT(db, data) {
28
+ return undefined;
29
+ }
30
+ /**
31
+ * Handler for PATCH request.
32
+ */
33
+ async PATCH(db, data) {
34
+ return undefined;
35
+ }
36
+ }
37
+ //# sourceMappingURL=ToolPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/ToolPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,aAAa;IAE3C;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,EAAgB,EAAE,KAAK;QAC/B,OAAO,SAAS,CAAA;IAClB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,EAAgB,EAAE,KAAK;QAClC,OAAO,SAAS,CAAA;IAClB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,EAAgB,EAAE,IAAI;QAC/B,OAAO,SAAS,CAAA;IAClB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,EAAgB,EAAE,IAAI;QAC9B,OAAO,SAAS,CAAA;IAClB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,EAAgB,EAAE,IAAI;QAChC,OAAO,SAAS,CAAA;IAClB,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Plugin base classes for backend and utility functions.
3
+ *
4
+ * @module tasenor-common-node/src/plugins
5
+ */
6
+ export * from './BackendPlugin';
7
+ export * from './DataPlugin';
8
+ export * from './ImportPlugin';
9
+ export * from './ReportPlugin';
10
+ export * from './SchemePlugin';
11
+ export * from './ServicePlugin';
12
+ export * from './ToolPlugin';
13
+ export * from './plugins';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Plugin base classes for backend and utility functions.
3
+ *
4
+ * @module tasenor-common-node/src/plugins
5
+ */
6
+ export * from './BackendPlugin';
7
+ export * from './DataPlugin';
8
+ export * from './ImportPlugin';
9
+ export * from './ReportPlugin';
10
+ export * from './SchemePlugin';
11
+ export * from './ServicePlugin';
12
+ export * from './ToolPlugin';
13
+ export * from './plugins';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA"}
@@ -0,0 +1,101 @@
1
+ import { TasenorPlugin, PluginCatalog, FilePath } from '@dataplug/tasenor-common';
2
+ interface PluginConfig {
3
+ PLUGIN_PATH?: string;
4
+ }
5
+ type ConfigVariable = keyof PluginConfig;
6
+ interface PluginState {
7
+ installed: boolean;
8
+ }
9
+ /**
10
+ * Get the configuration variable or throw an error.
11
+ * @param variable Name of the variable.
12
+ */
13
+ declare function getConfig(variable: ConfigVariable): string;
14
+ /**
15
+ * Set the configuration variable. When setting the root for plugins other directories are set automatically.
16
+ * @param variable Name of the variable.
17
+ * @param value Value of the variable.
18
+ */
19
+ declare function setConfig(variable: ConfigVariable, value: string): void;
20
+ /**
21
+ * Sort list of plugins according to the code.
22
+ * @param plugins A list of plugins.
23
+ * @returns New sorted list.
24
+ */
25
+ declare function sortPlugins(plugins: TasenorPlugin[]): TasenorPlugin[];
26
+ /**
27
+ * Compare two plugin lists if they are essentially the same.
28
+ * @param listA
29
+ * @param listB
30
+ * @returns True if code, versions and path match.
31
+ */
32
+ declare function samePlugins(listA: TasenorPlugin[], listB: TasenorPlugin[]): boolean;
33
+ /**
34
+ * Read in the current `index.json` file.
35
+ */
36
+ declare function loadPluginIndex(): PluginCatalog;
37
+ /**
38
+ * Store plugin index.
39
+ * @param plugins
40
+ */
41
+ declare function savePluginIndex(plugins: any): void;
42
+ /**
43
+ * Update one plugin in the index.
44
+ */
45
+ declare function updatePluginIndex(plugin: TasenorPlugin, plugins?: TasenorPlugin[] | undefined): TasenorPlugin[] | undefined;
46
+ /**
47
+ * Find the named plugin from the current `index.json` file or from the list if given..
48
+ * @param {String} code
49
+ * @returns Data or null if not found.
50
+ */
51
+ declare function findPluginFromIndex(code: string, plugins?: TasenorPlugin[] | undefined): TasenorPlugin | null;
52
+ /**
53
+ * Get the current plugin list maintained by some master API.
54
+ * @returns The latest list.
55
+ */
56
+ declare function fetchOfficialPluginList(): Promise<TasenorPlugin[]>;
57
+ /**
58
+ * Scan all plugins from the plugin directory based on index files found.
59
+ */
60
+ declare function scanPlugins(): TasenorPlugin[];
61
+ /**
62
+ * Read the local plugin state.
63
+ */
64
+ declare function loadPluginState(plugin: TasenorPlugin): PluginState;
65
+ /**
66
+ * Save local plugin state.
67
+ */
68
+ declare function savePluginState(plugin: TasenorPlugin, state: PluginState): void;
69
+ /**
70
+ * Check if plugin is marked as installed.
71
+ */
72
+ declare function isInstalled(plugin: TasenorPlugin): boolean;
73
+ /**
74
+ * Combine official and installed plugins to the same list and save if changed.
75
+ */
76
+ declare function updatePluginList(): Promise<TasenorPlugin[]>;
77
+ /**
78
+ * Convert full path from UI or backend index file to relative path inside the plugin.
79
+ */
80
+ declare function pluginLocalPath(indexFilePath: FilePath): string | undefined;
81
+ /**
82
+ * Collection of file system and API related plugin handling functions for fetching, building and scanning.
83
+ */
84
+ export declare const plugins: {
85
+ findPluginFromIndex: typeof findPluginFromIndex;
86
+ fetchOfficialPluginList: typeof fetchOfficialPluginList;
87
+ getConfig: typeof getConfig;
88
+ isInstalled: typeof isInstalled;
89
+ loadPluginIndex: typeof loadPluginIndex;
90
+ loadPluginState: typeof loadPluginState;
91
+ pluginLocalPath: typeof pluginLocalPath;
92
+ samePlugins: typeof samePlugins;
93
+ savePluginIndex: typeof savePluginIndex;
94
+ savePluginState: typeof savePluginState;
95
+ scanPlugins: typeof scanPlugins;
96
+ setConfig: typeof setConfig;
97
+ sortPlugins: typeof sortPlugins;
98
+ updatePluginIndex: typeof updatePluginIndex;
99
+ updatePluginList: typeof updatePluginList;
100
+ };
101
+ export {};
@@ -0,0 +1,292 @@
1
+ import fs from 'fs';
2
+ import glob from 'fast-glob';
3
+ import path from 'path';
4
+ import { net, note, log } from '@dataplug/tasenor-common';
5
+ import { create } from 'ts-opaque';
6
+ import { vault } from '../net';
7
+ const PLUGIN_FIELDS = ['code', 'title', 'version', 'icon', 'releaseDate', 'use', 'type', 'description'];
8
+ // Internal configuration for the module.
9
+ const config = {
10
+ PLUGIN_PATH: undefined
11
+ };
12
+ /**
13
+ * Get the configuration variable or throw an error.
14
+ * @param variable Name of the variable.
15
+ */
16
+ function getConfig(variable) {
17
+ const value = config[variable];
18
+ if (value === undefined) {
19
+ throw new Error(`Configuration variable ${variable} is required but it is not set.`);
20
+ }
21
+ return value;
22
+ }
23
+ /**
24
+ * Set the configuration variable. When setting the root for plugins other directories are set automatically.
25
+ * @param variable Name of the variable.
26
+ * @param value Value of the variable.
27
+ */
28
+ function setConfig(variable, value) {
29
+ if (variable in config) {
30
+ config[variable] = value;
31
+ }
32
+ else {
33
+ throw new Error(`No such configuration variable as ${variable}.`);
34
+ }
35
+ }
36
+ /**
37
+ * Sort list of plugins according to the code.
38
+ * @param plugins A list of plugins.
39
+ * @returns New sorted list.
40
+ */
41
+ function sortPlugins(plugins) {
42
+ return plugins.sort((a, b) => a.code < b.code ? -1 : (a.code > b.code ? 1 : 0));
43
+ }
44
+ /**
45
+ * Compare two plugin lists if they are essentially the same.
46
+ * @param listA
47
+ * @param listB
48
+ * @returns True if code, versions and path match.
49
+ */
50
+ function samePlugins(listA, listB) {
51
+ if (listA.length !== listB.length) {
52
+ return false;
53
+ }
54
+ listA = sortPlugins(listA);
55
+ listB = sortPlugins(listB);
56
+ for (let i = 0; i < listA.length; i++) {
57
+ if (listA[i].id !== listB[i].id ||
58
+ listA[i].code !== listB[i].code ||
59
+ listA[i].installedVersion !== listB[i].installedVersion ||
60
+ listA[i].path !== listB[i].path) {
61
+ return false;
62
+ }
63
+ }
64
+ return true;
65
+ }
66
+ /**
67
+ * Read in the current `index.json` file.
68
+ */
69
+ function loadPluginIndex() {
70
+ const indexPath = path.join(getConfig('PLUGIN_PATH'), 'index.json');
71
+ note(`Loading plugin index from '${indexPath}'.`);
72
+ if (fs.existsSync(indexPath)) {
73
+ return JSON.parse(fs.readFileSync(indexPath).toString('utf-8'));
74
+ }
75
+ return [];
76
+ }
77
+ /**
78
+ * Store plugin index.
79
+ * @param plugins
80
+ */
81
+ function savePluginIndex(plugins) {
82
+ plugins = sortPlugins(plugins);
83
+ const indexPath = path.join(getConfig('PLUGIN_PATH'), 'index.json');
84
+ note(`Saving plugin index to '${indexPath}'.`);
85
+ fs.writeFileSync(indexPath, JSON.stringify(plugins, null, 2) + '\n');
86
+ }
87
+ /**
88
+ * Update one plugin in the index.
89
+ */
90
+ function updatePluginIndex(plugin, plugins = undefined) {
91
+ const old = findPluginFromIndex(plugin.code, plugins);
92
+ if (!old) {
93
+ throw new Error(`Cannot update non-existing plugin ${plugin.code}.`);
94
+ }
95
+ Object.assign(old, plugin);
96
+ savePluginIndex(plugins);
97
+ return plugins;
98
+ }
99
+ /**
100
+ * Find the named plugin from the current `index.json` file or from the list if given..
101
+ * @param {String} code
102
+ * @returns Data or null if not found.
103
+ */
104
+ function findPluginFromIndex(code, plugins = undefined) {
105
+ const index = plugins || loadPluginIndex();
106
+ const plugin = index.find(plugin => plugin.code === code);
107
+ return plugin || null;
108
+ }
109
+ /**
110
+ * Get the current plugin list maintained by some master API.
111
+ * @returns The latest list.
112
+ */
113
+ async function fetchOfficialPluginList() {
114
+ const url = vault.get('TASENOR_API_URL', '');
115
+ if (url) {
116
+ const plugins = await net.GET(`${url}/plugins`);
117
+ if (plugins.success) {
118
+ return plugins.data;
119
+ }
120
+ }
121
+ return [];
122
+ }
123
+ /**
124
+ * Scan all plugins from the plugin directory based on index files found.
125
+ */
126
+ function scanPlugins() {
127
+ const rootPath = path.resolve(getConfig('PLUGIN_PATH'));
128
+ log(`Scanning plugins from ${rootPath}.`);
129
+ let uiFiles = [];
130
+ let backendFiles = [];
131
+ // Scan each dir resolving symlinks first.
132
+ const dirs = glob.sync(path.join(rootPath, '**', 'package.json'));
133
+ dirs.map(dir => path.dirname(fs.realpathSync(dir))).forEach(dir => {
134
+ uiFiles = uiFiles.concat(glob.sync(path.join(dir, '**', 'ui', 'index.tsx')).map(p => p.substring(0, p.length - 'ui/index.tsx'.length)));
135
+ backendFiles = backendFiles.concat(glob.sync(path.join(dir, '**', 'backend', 'index.ts')).map(p => p.substring(0, p.length - 'backend/index.ts'.length)));
136
+ });
137
+ const pluginSet = new Set(uiFiles.concat(backendFiles));
138
+ return [...pluginSet].map(scanPlugin);
139
+ }
140
+ /**
141
+ * Read data from the plugin's index file(s) found from the given path.
142
+ */
143
+ function scanPlugin(pluginPath) {
144
+ const uiPath = path.join(pluginPath, 'ui', 'index.tsx');
145
+ const ui = fs.existsSync(uiPath) ? readUIPlugin(uiPath) : null;
146
+ const backendPath = path.join(pluginPath, 'backend', 'index.ts');
147
+ const backend = fs.existsSync(backendPath) ? readBackendPlugin(backendPath) : null;
148
+ if (ui && backend) {
149
+ for (const field of PLUGIN_FIELDS) {
150
+ if (ui[field] !== backend[field]) {
151
+ throw new Error(`A field '${field}' have contradicting values ${JSON.stringify(ui[field])} and ${JSON.stringify(backend[field])} for index files '${uiPath}' and '${backendPath}'.`);
152
+ }
153
+ }
154
+ }
155
+ if (ui === null && backend === null) {
156
+ throw new Error(`Cannot find any plugins in '${pluginPath}'.`);
157
+ }
158
+ return ui || backend;
159
+ }
160
+ /**
161
+ * Read UI plugin data from the given index file.
162
+ */
163
+ function readUIPlugin(indexPath) {
164
+ const regex = new RegExp(`^\\s*static\\s+(${PLUGIN_FIELDS.join('|')})\\s*=\\s*(?:'([^']*)'|"([^"]*)")`);
165
+ const data = {
166
+ code: create('Unknown'),
167
+ title: 'Unknown Development Plugin',
168
+ icon: 'HelpOutline',
169
+ path: path.dirname(path.dirname(indexPath)),
170
+ version: create('0'),
171
+ releaseDate: null,
172
+ use: 'unknown',
173
+ type: 'unknown',
174
+ description: 'No description'
175
+ };
176
+ const code = fs.readFileSync(indexPath).toString('utf-8').split('\n');
177
+ for (const line of code) {
178
+ const match = regex.exec(line);
179
+ if (match) {
180
+ data[match[1]] = match[2];
181
+ }
182
+ }
183
+ return data;
184
+ }
185
+ function readBackendPlugin(indexPath) {
186
+ const regex = new RegExp(`^\\s*this\\.(${PLUGIN_FIELDS.join('|')})\\s*=\\s*(?:'([^']*)'|"([^"]*)")`);
187
+ const data = {
188
+ code: create('Unknown'),
189
+ title: 'Unknown Development Plugin',
190
+ icon: 'HelpOutline',
191
+ path: path.dirname(path.dirname(indexPath)),
192
+ version: create('0'),
193
+ releaseDate: null,
194
+ use: 'unknown',
195
+ type: 'unknown',
196
+ description: 'No description'
197
+ };
198
+ const code = fs.readFileSync(indexPath).toString('utf-8').split('\n');
199
+ for (const line of code) {
200
+ const match = regex.exec(line);
201
+ if (match) {
202
+ data[match[1]] = match[2];
203
+ }
204
+ }
205
+ return data;
206
+ }
207
+ /**
208
+ * Read the local plugin state.
209
+ */
210
+ function loadPluginState(plugin) {
211
+ const stateFile = plugin.path && path.join(plugin.path, '.state');
212
+ if (stateFile && fs.existsSync(stateFile)) {
213
+ return JSON.parse(fs.readFileSync(stateFile).toString('utf-8'));
214
+ }
215
+ return {
216
+ installed: false
217
+ };
218
+ }
219
+ /**
220
+ * Save local plugin state.
221
+ */
222
+ function savePluginState(plugin, state) {
223
+ const stateFile = path.join(plugin.path, '.state');
224
+ fs.writeFileSync(stateFile, JSON.stringify(state, null, 2) + '\n');
225
+ }
226
+ /**
227
+ * Check if plugin is marked as installed.
228
+ */
229
+ function isInstalled(plugin) {
230
+ return loadPluginState(plugin).installed;
231
+ }
232
+ /**
233
+ * Combine official and installed plugins to the same list and save if changed.
234
+ */
235
+ async function updatePluginList() {
236
+ let current = [];
237
+ // Get the official list if any.
238
+ for (const plugin of await fetchOfficialPluginList()) {
239
+ current[plugin.code] = plugin;
240
+ }
241
+ // Collect and add local plugins.
242
+ let localId = -1;
243
+ for (const plugin of await scanPlugins()) {
244
+ if (!current[plugin.code]) {
245
+ current[plugin.code] = plugin;
246
+ current[plugin.code].id = localId--;
247
+ }
248
+ current[plugin.code].path = plugin.path;
249
+ current[plugin.code].version = plugin.version;
250
+ current[plugin.code].availableVersion = plugin.version;
251
+ if (isInstalled(plugin)) {
252
+ current[plugin.code].installedVersion = plugin.version;
253
+ }
254
+ }
255
+ // Avoid dev server unnecessary restart.
256
+ const old = loadPluginIndex();
257
+ current = Object.values(current);
258
+ if (!samePlugins(old, current)) {
259
+ savePluginIndex(current);
260
+ }
261
+ return current;
262
+ }
263
+ /**
264
+ * Convert full path from UI or backend index file to relative path inside the plugin.
265
+ */
266
+ function pluginLocalPath(indexFilePath) {
267
+ const match = /\/[^/]+\/(ui|backend)\/index.tsx?$/.exec(indexFilePath);
268
+ if (match) {
269
+ return match[0].substring(1);
270
+ }
271
+ }
272
+ /**
273
+ * Collection of file system and API related plugin handling functions for fetching, building and scanning.
274
+ */
275
+ export const plugins = {
276
+ findPluginFromIndex,
277
+ fetchOfficialPluginList,
278
+ getConfig,
279
+ isInstalled,
280
+ loadPluginIndex,
281
+ loadPluginState,
282
+ pluginLocalPath,
283
+ samePlugins,
284
+ savePluginIndex,
285
+ savePluginState,
286
+ scanPlugins,
287
+ setConfig,
288
+ sortPlugins,
289
+ updatePluginIndex,
290
+ updatePluginList
291
+ };
292
+ //# sourceMappingURL=plugins.js.map