@tasenor/common-plugins 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 (114) hide show
  1. package/.eslintrc.js +4 -0
  2. package/.turbo/turbo-fix.log +4 -0
  3. package/.turbo/turbo-lint.log +4 -0
  4. package/.turbo/turbo-version.log +5 -0
  5. package/LICENSE +21 -0
  6. package/README.md +15 -0
  7. package/data/FinnishBalanceSheetReport.mjs +9 -0
  8. package/data/FinnishBalanceSheetReportInvestment.mjs +11 -0
  9. package/data/FinnishBalanceSheetReportLite.mjs +9 -0
  10. package/data/FinnishIncomeStatementReport.mjs +9 -0
  11. package/data/FinnishIncomeStatementReportInvestment.mjs +11 -0
  12. package/data/FinnishIncomeStatementReportLite.mjs +9 -0
  13. package/data/FinnishInvestmentCompany.mjs +5 -0
  14. package/data/FinnishLimitedCompanyComplete.mjs +5 -0
  15. package/data/FinnishLimitedCompanyLite.mjs +9 -0
  16. package/data/IncomeAndExpenses.mjs +64 -0
  17. package/data/README.md +8 -0
  18. package/data/VATFinland.mjs +22 -0
  19. package/data/bin/build_all +11 -0
  20. package/data/lib/utils.mjs +314 -0
  21. package/data/src/Assets Tree - Definitions.tsv +101 -0
  22. package/data/src/Expense Tree - Definitions.tsv +99 -0
  23. package/data/src/Finland VAT - Definitions.tsv +22 -0
  24. package/data/src/FinnishBalanceSheetReport - balance-sheet-detailed-fi.tsv +215 -0
  25. package/data/src/FinnishBalanceSheetReport - balance-sheet-fi.tsv +93 -0
  26. package/data/src/FinnishBalanceSheetReportInvestment - balance-sheet-detailed-fi.tsv +100 -0
  27. package/data/src/FinnishBalanceSheetReportInvestment - balance-sheet-fi.tsv +52 -0
  28. package/data/src/FinnishBalanceSheetReportLite - balance-sheet-en.tsv +21 -0
  29. package/data/src/FinnishBalanceSheetReportLite - balance-sheet-fi.tsv +21 -0
  30. package/data/src/FinnishBalanceSheetReportLite - balance-sheet-lite-en.tsv +21 -0
  31. package/data/src/FinnishBalanceSheetReportLite - balance-sheet-lite-fi.tsv +21 -0
  32. package/data/src/FinnishIncomeStatementReport - income-statement-detailed-fi.tsv +118 -0
  33. package/data/src/FinnishIncomeStatementReport - income-statement-fi.tsv +45 -0
  34. package/data/src/FinnishIncomeStatementReportInvestment - income-statement-detailed-fi.tsv +96 -0
  35. package/data/src/FinnishIncomeStatementReportInvestment - income-statement-fi.tsv +39 -0
  36. package/data/src/FinnishIncomeStatementReportLite - income-statement-lite-en.tsv +23 -0
  37. package/data/src/FinnishIncomeStatementReportLite - income-statement-lite-fi.tsv +23 -0
  38. package/data/src/FinnishInvestmentCompany - fi-EUR.tsv +722 -0
  39. package/data/src/FinnishLimitedCompanyComplete - fi-EUR.tsv +1086 -0
  40. package/data/src/FinnishLimitedCompanyLite - en-EUR.tsv +97 -0
  41. package/data/src/FinnishLimitedCompanyLite - fi-EUR.tsv +99 -0
  42. package/data/src/Income Tree - Definitions.tsv +60 -0
  43. package/data/src/Tax Types - Definitions.tsv +11 -0
  44. package/package.json +51 -0
  45. package/src/CoinAPI/backend/index.ts +102 -0
  46. package/src/CoinbaseImport/backend/CoinbaseHandler.ts +35 -0
  47. package/src/CoinbaseImport/backend/index.ts +24 -0
  48. package/src/CoinbaseImport/backend/rules.json +64 -0
  49. package/src/DocumentCleaner/ui/index.tsx +165 -0
  50. package/src/Euro/ui/index.tsx +27 -0
  51. package/src/Finnish/ui/finnish.json +341 -0
  52. package/src/Finnish/ui/index.tsx +54 -0
  53. package/src/FinnishBalanceSheetReport/backend/balance-sheet-detailed-fi.tsv +215 -0
  54. package/src/FinnishBalanceSheetReport/backend/balance-sheet-fi.tsv +93 -0
  55. package/src/FinnishBalanceSheetReport/backend/index.ts +107 -0
  56. package/src/FinnishBalanceSheetReportInvestment/backend/balance-sheet-investment-detailed-fi.tsv +100 -0
  57. package/src/FinnishBalanceSheetReportInvestment/backend/balance-sheet-investment-fi.tsv +52 -0
  58. package/src/FinnishBalanceSheetReportInvestment/backend/index.ts +107 -0
  59. package/src/FinnishBalanceSheetReportLite/backend/balance-sheet-lite-en.tsv +21 -0
  60. package/src/FinnishBalanceSheetReportLite/backend/balance-sheet-lite-fi.tsv +21 -0
  61. package/src/FinnishBalanceSheetReportLite/backend/index.ts +121 -0
  62. package/src/FinnishIncomeStatementReport/backend/income-statement-detailed-fi.tsv +118 -0
  63. package/src/FinnishIncomeStatementReport/backend/income-statement-fi.tsv +45 -0
  64. package/src/FinnishIncomeStatementReport/backend/index.ts +212 -0
  65. package/src/FinnishIncomeStatementReportInvestment/backend/income-statement-detailed-fi.tsv +118 -0
  66. package/src/FinnishIncomeStatementReportInvestment/backend/income-statement-fi.tsv +45 -0
  67. package/src/FinnishIncomeStatementReportInvestment/backend/income-statement-investment-detailed-fi.tsv +96 -0
  68. package/src/FinnishIncomeStatementReportInvestment/backend/income-statement-investment-fi.tsv +39 -0
  69. package/src/FinnishIncomeStatementReportInvestment/backend/index.ts +212 -0
  70. package/src/FinnishIncomeStatementReportLite/backend/income-statement-lite-en.tsv +23 -0
  71. package/src/FinnishIncomeStatementReportLite/backend/income-statement-lite-fi.tsv +23 -0
  72. package/src/FinnishIncomeStatementReportLite/backend/index.ts +210 -0
  73. package/src/FinnishInvestmentCompany/backend/fi-EUR.tsv +722 -0
  74. package/src/FinnishInvestmentCompany/backend/index.ts +46 -0
  75. package/src/FinnishInvestmentCompany/ui/index.tsx +26 -0
  76. package/src/FinnishLimitedCompanyComplete/backend/fi-EUR.tsv +1086 -0
  77. package/src/FinnishLimitedCompanyComplete/backend/index.ts +46 -0
  78. package/src/FinnishLimitedCompanyComplete/ui/index.tsx +26 -0
  79. package/src/FinnishLimitedCompanyLite/backend/en-EUR.tsv +97 -0
  80. package/src/FinnishLimitedCompanyLite/backend/fi-EUR.tsv +99 -0
  81. package/src/FinnishLimitedCompanyLite/backend/index.ts +53 -0
  82. package/src/FinnishLimitedCompanyLite/ui/index.tsx +28 -0
  83. package/src/GitBackup/backend/index.ts +109 -0
  84. package/src/GitBackup/ui/index.tsx +127 -0
  85. package/src/IncomeAndExpenses/backend/assetCodes.json +126 -0
  86. package/src/IncomeAndExpenses/backend/expense.json +190 -0
  87. package/src/IncomeAndExpenses/backend/income.json +120 -0
  88. package/src/IncomeAndExpenses/backend/index.ts +354 -0
  89. package/src/IncomeAndExpenses/backend/taxTypes.json +12 -0
  90. package/src/JournalReport/backend/index.ts +157 -0
  91. package/src/KrakenImport/backend/KrakenHandler.ts +88 -0
  92. package/src/KrakenImport/backend/index.ts +24 -0
  93. package/src/KrakenImport/backend/rules.json +52 -0
  94. package/src/LedgerReport/backend/index.ts +161 -0
  95. package/src/LynxImport/backend/LynxHandler.ts +389 -0
  96. package/src/LynxImport/backend/index.ts +24 -0
  97. package/src/LynxImport/backend/rules.json +412 -0
  98. package/src/NordeaImport/backend/NordeaHandler.ts +44 -0
  99. package/src/NordeaImport/backend/index.ts +24 -0
  100. package/src/NordeaImport/backend/rules.json +4 -0
  101. package/src/NordnetImport/backend/NordnetHandler.ts +78 -0
  102. package/src/NordnetImport/backend/index.ts +24 -0
  103. package/src/NordnetImport/backend/rules.json +271 -0
  104. package/src/Rand/ui/index.tsx +27 -0
  105. package/src/RapidAPI/backend/index.ts +133 -0
  106. package/src/TITOImport/backend/TITOHandler.ts +268 -0
  107. package/src/TITOImport/backend/index.ts +24 -0
  108. package/src/TITOImport/backend/rules.json +4 -0
  109. package/src/TagEditor/ui/index.tsx +510 -0
  110. package/src/USDollar/ui/index.tsx +27 -0
  111. package/src/VAT/ui/index.tsx +572 -0
  112. package/src/VATFinland/backend/index.ts +22 -0
  113. package/src/VATFinland/backend/vat.json +23 -0
  114. package/tsconfig.json +13 -0
@@ -0,0 +1,271 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "name": "Stock Buy",
5
+ "filter": "Tapahtumatyyppi == 'OSTO'",
6
+ "result": [
7
+ {
8
+ "data": {
9
+ "text": "Tapahtumateksti"
10
+ },
11
+ "type": "'currency'",
12
+ "asset": "Valuutta",
13
+ "amount": "Summa",
14
+ "reason": "'trade'"
15
+ },
16
+ {
17
+ "data": {
18
+ "text": "Tapahtumateksti"
19
+ },
20
+ "type": "'stock'",
21
+ "asset": "Arvopaperi",
22
+ "amount": "Määrä",
23
+ "reason": "'trade'"
24
+ },
25
+ {
26
+ "if": "Kokonaiskulut",
27
+ "data": {
28
+ "text": "Tapahtumateksti"
29
+ },
30
+ "type": "'currency'",
31
+ "asset": "$('Kokonaiskulut Valuutta')",
32
+ "amount": "Kokonaiskulut",
33
+ "reason": "'fee'"
34
+ }
35
+ ]
36
+ },
37
+ {
38
+ "name": "Stock Sell",
39
+ "filter": "Tapahtumatyyppi == 'MYYNTI'",
40
+ "result": [
41
+ {
42
+ "data": {
43
+ "text": "Tapahtumateksti"
44
+ },
45
+ "type": "'currency'",
46
+ "asset": "Valuutta",
47
+ "amount": "Summa",
48
+ "reason": "'trade'"
49
+ },
50
+ {
51
+ "data": {
52
+ "text": "Tapahtumateksti"
53
+ },
54
+ "type": "'stock'",
55
+ "asset": "Arvopaperi",
56
+ "amount": "-Määrä",
57
+ "reason": "'trade'"
58
+ },
59
+ {
60
+ "if": "Kokonaiskulut",
61
+ "data": {
62
+ "text": "Tapahtumateksti"
63
+ },
64
+ "type": "'currency'",
65
+ "asset": "$('Kokonaiskulut Valuutta')",
66
+ "amount": "Kokonaiskulut",
67
+ "reason": "'fee'"
68
+ }
69
+ ]
70
+ },
71
+ {
72
+ "name": "Monthly Saving Fee",
73
+ "filter": "Tapahtumatyyppi == 'ETF_KK SÄÄSTÖN PALVELUMAKSU'",
74
+ "result": [
75
+ {
76
+ "data": {
77
+ "text": "Tapahtumateksti"
78
+ },
79
+ "type": "'currency'",
80
+ "asset": "Valuutta",
81
+ "amount": "Summa",
82
+ "reason": "'expense'"
83
+ },
84
+ {
85
+ "data": {
86
+ "text": "Tapahtumateksti"
87
+ },
88
+ "type": "'statement'",
89
+ "asset": "'STOCK_BROKER_SERVICE_FEE'",
90
+ "amount": "-Summa",
91
+ "reason": "'expense'"
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ "name": "Forex Sell",
97
+ "filter": "Tapahtumatyyppi == 'VALUUTAN MYYNTI'",
98
+ "result": [
99
+ {
100
+ "data": {
101
+ "text": "Tapahtumateksti",
102
+ "rates": "rates(Valuutta, Vaihtokurssi)"
103
+ },
104
+ "type": "'currency'",
105
+ "asset": "Valuutta",
106
+ "amount": "Summa",
107
+ "reason": "'forex'"
108
+ }
109
+ ]
110
+ },
111
+ {
112
+ "name": "Deposit",
113
+ "filter": "Tapahtumatyyppi == 'TALLETUS'",
114
+ "result": [
115
+ {
116
+ "data": {
117
+ "text": "Tapahtumateksti"
118
+ },
119
+ "type": "'currency'",
120
+ "asset": "Valuutta",
121
+ "amount": "Summa",
122
+ "reason": "'deposit'"
123
+ },
124
+ {
125
+ "data": {
126
+ "text": "Tapahtumateksti"
127
+ },
128
+ "type": "'external'",
129
+ "asset": "Valuutta",
130
+ "amount": "-Summa",
131
+ "reason": "'deposit'"
132
+ }
133
+ ]
134
+ },
135
+ {
136
+ "name": "Withdrawal",
137
+ "filter": "Tapahtumatyyppi == 'NOSTO'",
138
+ "result": [
139
+ {
140
+ "data": {
141
+ "text": "Tapahtumateksti"
142
+ },
143
+ "type": "'currency'",
144
+ "asset": "Valuutta",
145
+ "amount": "Summa",
146
+ "reason": "'withdrawal'"
147
+ },
148
+ {
149
+ "data": {
150
+ "text": "Tapahtumateksti"
151
+ },
152
+ "type": "'external'",
153
+ "asset": "Valuutta",
154
+ "amount": "-Summa",
155
+ "reason": "'withdrawal'"
156
+ }
157
+ ]
158
+ },
159
+ {
160
+ "name": "Dividend",
161
+ "filter": "Tapahtumatyyppi == 'OSINKO'",
162
+ "result": [
163
+ {
164
+ "data": {
165
+ "text": "Tapahtumateksti",
166
+ "asset": "Arvopaperi",
167
+ "notes": [
168
+ "times(Määrä, Kurssi)"
169
+ ],
170
+ "currency": "Valuutta"
171
+ },
172
+ "type": "'currency'",
173
+ "asset": "Valuutta",
174
+ "amount": "Summa",
175
+ "reason": "'dividend'"
176
+ },
177
+ {
178
+ "data": {
179
+ "text": "Tapahtumateksti",
180
+ "notes": [
181
+ "times(Määrä, Kurssi)"
182
+ ]
183
+ },
184
+ "type": "'statement'",
185
+ "asset": "'LISTED_DIVIDEND'",
186
+ "amount": "null",
187
+ "reason": "'income'"
188
+ }
189
+ ]
190
+ },
191
+ {
192
+ "name": "Withholding Tax",
193
+ "filter": "Tapahtumatyyppi == 'ENNAKKOPIDÄTYS'",
194
+ "result": [
195
+ {
196
+ "data": {
197
+ "text": "Tapahtumateksti",
198
+ "currency": "Valuutta",
199
+ "currencyValue": "-Summa * 100"
200
+ },
201
+ "type": "'statement'",
202
+ "asset": "'WITHHOLDING_TAX'",
203
+ "reason": "'tax'"
204
+ }
205
+ ]
206
+ },
207
+ {
208
+ "name": "Forex Buy",
209
+ "filter": "Tapahtumatyyppi == 'VALUUTAN OSTO'",
210
+ "result": [
211
+ {
212
+ "data": {
213
+ "text": "Tapahtumateksti"
214
+ },
215
+ "type": "'currency'",
216
+ "asset": "Valuutta",
217
+ "amount": "Summa",
218
+ "reason": "'forex'"
219
+ }
220
+ ]
221
+ },
222
+ {
223
+ "name": "Interest Expenses",
224
+ "filter": "Tapahtumatyyppi == 'LAINAKORKO'",
225
+ "result": [
226
+ {
227
+ "data": {
228
+ "text": "Tapahtumateksti"
229
+ },
230
+ "type": "'currency'",
231
+ "asset": "Valuutta",
232
+ "amount": "Summa",
233
+ "reason": "'expense'"
234
+ },
235
+ {
236
+ "data": {
237
+ "text": "Tapahtumateksti"
238
+ },
239
+ "type": "'statement'",
240
+ "asset": "'INTEREST_EXPENSE'",
241
+ "amount": "-Summa",
242
+ "reason": "'expense'"
243
+ }
244
+ ]
245
+ },
246
+ {
247
+ "name": "Tapahtumatyyppi contains 'PÄÄOMIT YLIT.KORKO'",
248
+ "filter": "Tapahtumatyyppi == 'PÄÄOMIT YLIT.KORKO'",
249
+ "result": [
250
+ {
251
+ "data": {
252
+ "text": "Tapahtumateksti"
253
+ },
254
+ "type": "'currency'",
255
+ "asset": "Valuutta",
256
+ "amount": "Summa",
257
+ "reason": "'expense'"
258
+ },
259
+ {
260
+ "data": {
261
+ "text": "Tapahtumateksti"
262
+ },
263
+ "type": "'statement'",
264
+ "asset": "'INTEREST_EXPENSE'",
265
+ "amount": "-Summa",
266
+ "reason": "'expense'"
267
+ }
268
+ ]
269
+ }
270
+ ]
271
+ }
@@ -0,0 +1,27 @@
1
+ import { CurrencyPlugin } from '@dataplug/tasenor-common-ui'
2
+
3
+ class Rand extends CurrencyPlugin {
4
+
5
+ static code = 'Rand'
6
+ static title = 'Currency Rand'
7
+ static version = '1.0.10'
8
+ static icon = '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M15 16h3c.55 0 1-.45 1-1V9c0-.55-.45-1-1-1h-3c-.55 0-1 .45-1 1v6c0 .55.45 1 1 1zm1-6h1v4h-1v-4zm-7 6h3c.55 0 1-.45 1-1V9c0-.55-.45-1-1-1H9c-.55 0-1 .45-1 1v6c0 .55.45 1 1 1zm1-6h1v4h-1v-4zM5 8h2v8H5zM2 4v16h20V4H2zm18 14H4V6h16v12z"/></svg>'
9
+ static releaseDate = '2022-03-11'
10
+ static use = 'ui'
11
+ static type = 'currency'
12
+ static description = 'Support for rand currency.'
13
+
14
+ getCurrencySymbol() {
15
+ return 'R'
16
+ }
17
+
18
+ getCurrencyCode() {
19
+ return 'ZAR'
20
+ }
21
+
22
+ money2str(cents) {
23
+ return this.makeMoney(cents, 100, 2, 'R ', ',', '.', '')
24
+ }
25
+ }
26
+
27
+ export default Rand
@@ -0,0 +1,133 @@
1
+ import { ServicePlugin } from '@dataplug/tasenor-common-node'
2
+ import { PluginCode, Version, TasenorElement } from '@dataplug/tasenor-common'
3
+
4
+ /**
5
+ * Service: historical-currency-rate
6
+ *
7
+ * Query:
8
+ * - *from* A currency code to convert from.
9
+ * - *to* A currency code to convert to.
10
+ * - *date* A date for the closing value wanted.
11
+ *
12
+ * Response:
13
+ * {
14
+ * status: 200,
15
+ * rate: 0.88123123
16
+ * }
17
+ */
18
+ class RapidAPI extends ServicePlugin {
19
+
20
+ constructor() {
21
+ super('historical-currency-rate')
22
+
23
+ this.code = 'RapidAPI' as PluginCode
24
+ this.title = 'Rapid API Service'
25
+ this.version = '1.0.14' as Version
26
+ this.icon = '<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><path d="M12.89,11.1c-1.78-0.59-2.64-0.96-2.64-1.9c0-1.02,1.11-1.39,1.81-1.39c1.31,0,1.79,0.99,1.9,1.34l1.58-0.67 C15.39,8.03,14.72,6.56,13,6.24V5h-2v1.26C8.52,6.82,8.51,9.12,8.51,9.22c0,2.27,2.25,2.91,3.35,3.31 c1.58,0.56,2.28,1.07,2.28,2.03c0,1.13-1.05,1.61-1.98,1.61c-1.82,0-2.34-1.87-2.4-2.09L8.1,14.75c0.63,2.19,2.28,2.78,2.9,2.96V19 h2v-1.24c0.4-0.09,2.9-0.59,2.9-3.22C15.9,13.15,15.29,11.93,12.89,11.1z M3,21H1v-6h6v2l-2.48,0c1.61,2.41,4.36,4,7.48,4 c4.97,0,9-4.03,9-9h2c0,6.08-4.92,11-11,11c-3.72,0-7.01-1.85-9-4.67L3,21z M1,12C1,5.92,5.92,1,12,1c3.72,0,7.01,1.85,9,4.67L21,3 h2v6h-6V7l2.48,0C17.87,4.59,15.12,3,12,3c-4.97,0-9,4.03-9,9H1z"/></g></svg>'
27
+ this.releaseDate = '2022-05-13'
28
+ this.use = 'backend'
29
+ this.type = 'service'
30
+ this.description = 'This service provides services from https://rapidapi.com/. Currently it has a service `historical-currency-rate`, which can be used to fetch historical currency rates.'
31
+
32
+ this.languages = {
33
+ en: {
34
+ 'label-apiKey': 'Your Rapid API key to use',
35
+ 'label-apiHost': 'Your Rapid API host to use'
36
+ },
37
+ fi: {
38
+ 'label-apiKey': 'Rapid API key eli avain',
39
+ 'label-apiHost': 'Rapid API host eli palvelin',
40
+ 'Rapid API Service': 'Rapid API palvelu',
41
+ General: 'Yleiset'
42
+ }
43
+ }
44
+ }
45
+
46
+ async query(db, settings, service, query) {
47
+ const host = settings.apiHost
48
+ if (!host) {
49
+ return {
50
+ status: 400,
51
+ message: 'Setting apiHost is not set.'
52
+ }
53
+ }
54
+ const apiKey = settings.apiKey
55
+ if (!apiKey) {
56
+ return {
57
+ status: 400,
58
+ message: 'Setting apiKey is not set.'
59
+ }
60
+ }
61
+ if (!query.date) {
62
+ return {
63
+ status: 400,
64
+ message: 'Query parameter `date` is not set.'
65
+ }
66
+ }
67
+ if (!query.from) {
68
+ return {
69
+ status: 400,
70
+ message: 'Query parameter `from` is not set.'
71
+ }
72
+ }
73
+ if (!query.to) {
74
+ return {
75
+ status: 400,
76
+ message: 'Query parameter `to` is not set.'
77
+ }
78
+ }
79
+
80
+ const date = `${query.date}`.substr(0, 10)
81
+ const res = await this.cachedRequest(
82
+ db,
83
+ service,
84
+ 'GET', `https://${host}/currency/historical/${date}`,
85
+ {
86
+ from: query.from,
87
+ amount: '1',
88
+ format: 'json',
89
+ to: query.to
90
+ }, {
91
+ 'X-RapidAPI-Key': apiKey,
92
+ 'X-RapidAPI-Host': host
93
+ }, {
94
+ rateLimitDelay: settings.freePlan ? 1500 : 0
95
+ }
96
+ )
97
+
98
+ return res.status === 200 ? { status: 200, rate: res.data.rates[query.to.toUpperCase()].rate } : res
99
+ }
100
+
101
+ getSettings(): TasenorElement {
102
+ return {
103
+ type: 'flat',
104
+ elements: [
105
+ {
106
+ type: 'boolean',
107
+ name: 'freePlan',
108
+ label: 'Are we using free plan, i.e. need to limit access rate accordingly?',
109
+ actions: {}
110
+ },
111
+ {
112
+ type: 'text',
113
+ name: 'apiKey',
114
+ actions: {}
115
+ },
116
+ {
117
+ type: 'text',
118
+ name: 'apiHost',
119
+ actions: {}
120
+ },
121
+ {
122
+ type: 'button',
123
+ label: 'Save',
124
+ actions: {
125
+ onClick: { type: 'saveSettings', backend: true, plugin: 'RapidAPI' as PluginCode }
126
+ }
127
+ }
128
+ ]
129
+ }
130
+ }
131
+ }
132
+
133
+ export default RapidAPI
@@ -0,0 +1,268 @@
1
+ import { NO_SEGMENT, SegmentId, TextFileLine } from '@dataplug/tasenor-common'
2
+ import { InvalidFile, NotImplemented, ProcessFile, TransactionImportHandler } from '@dataplug/tasenor-common-node'
3
+
4
+ // Store the latest transactoin ID
5
+ let ref: string | undefined
6
+
7
+ /**
8
+ * Import implementation for TITO format.
9
+ *
10
+ * Based on https://www.nordea.fi/Images/146-84478/xml_tiliote.pdf
11
+ */
12
+ export class TITOHandler extends TransactionImportHandler {
13
+
14
+ constructor() {
15
+ super('TITOImport')
16
+
17
+ this.importOptions = {
18
+ parser: 'custom',
19
+ numericFields: ['Tapahtuman rahamäärä', 'Tietuetunnus', 'Panot Summa', 'Otot Summa', 'Panot Kappalemäärä', 'Otot Kappalemäärä', 'Tiliotteen tietueiden lukumäärä', 'Tilin limiitti'],
20
+ requiredFields: ['Tietuetunnus', 'Viite', 'Seliteteksti'],
21
+ insignificantFields: ['Tietuetunnus', 'Tapahtuman numero', 'Tapahtumatunnus', 'Koodi', 'Kuittikoodi', 'Välitystapa', 'Nimen lähde', 'Tili muuttunut -tieto', 'Lomakkeen numero', 'Tasotunnus'],
22
+ sharedFields: ['Toimeksiantajan tieto-1', 'Toimeksiantajan tieto-2'],
23
+ textField: 'Seliteteksti',
24
+ totalAmountField: 'Tapahtuman rahamäärä',
25
+ custom: {
26
+ splitToLines: (s: string): string[] => {
27
+
28
+ const ret: string[] = []
29
+
30
+ for (let i = 0; i < s.length;) {
31
+ if (s[i] !== 'T') {
32
+ throw new InvalidFile('Parsing a file failed. Missing "T" in the beginning of the record.')
33
+ }
34
+
35
+ const len = parseInt(s.substring(i + 3, i + 6))
36
+ const text = s.substring(i, i + len)
37
+ .replace(/\]/g, 'Å')
38
+ .replace(/\[/g, 'Ä')
39
+ .replace(/\\/g, 'Ö')
40
+ .replace(/\}/g, 'å')
41
+ .replace(/\{/g, 'ä')
42
+ .replace(/\|/g, 'ö')
43
+ ret.push(text)
44
+
45
+ i += len
46
+ while (s.charCodeAt(i) === 10 || s.charCodeAt(i) === 13) {
47
+ i++
48
+ }
49
+ }
50
+
51
+ return ret
52
+ },
53
+
54
+ splitToColumns: (s: string): Record<string, string> => {
55
+ if (s[0] !== 'T') {
56
+ throw new InvalidFile('Parsing a line failed. Missing "T" in the beginning of the line.')
57
+ }
58
+
59
+ const code = s.substring(1, 3)
60
+ let columns
61
+ let extras
62
+
63
+ switch (code) {
64
+
65
+ // Header line.
66
+ case '00':
67
+ ref = undefined
68
+ return {
69
+ Tietuetunnus: code,
70
+ ...this.parseFixedLength(s.substring(6), {
71
+ Versionumero: 3,
72
+ Tilinumero: 14,
73
+ 'Tiliotteen numero': 3,
74
+ Tiliotekausi: 12,
75
+ Muodostumisaika: 10,
76
+ Asiakastunnus: 17,
77
+ 'Alkusaldon pvm': 6,
78
+ 'Tiliotteen alkusaldo': 19,
79
+ 'Tiliotteen tietueiden lukumäärä': 6,
80
+ 'Tilin valuutan tunnus': 3,
81
+ 'Tilin nimi': 30,
82
+ 'Tilin limiitti': 18,
83
+ 'Tilin omistajan nimi': 35,
84
+ 'Yhteydenottotieto-1': 40,
85
+ 'Yhteydenottotieto-2': 40,
86
+ 'Pankkikohtaista tietoa-1': 30,
87
+ 'Pankkikohtaista tietoa-2': 30,
88
+ }, {
89
+ Tiliotekausi: (s) => `20${s.substring(0, 2)}-${s.substring(2, 4)}-${s.substring(4, 6)} 20${s.substring(6, 8)}-${s.substring(8, 10)}-${s.substring(10, 12)}`,
90
+ Muodostumisaika: (s) => `20${s.substring(0, 2)}-${s.substring(2, 4)}-${s.substring(4, 6)} ${s.substring(6, 8)}:${s.substring(8, 10)}:00`,
91
+ 'Alkusaldon pvm': (s) => `20${s.substring(0, 2)}-${s.substring(2, 4)}-${s.substring(4, 6)}`,
92
+ 'Tiliotteen alkusaldo': (s) => `${parseInt(s) / 100}`,
93
+ 'Tiliotteen tietueiden lukumäärä': (s) => `${parseInt(s)}`,
94
+ 'Tilin limiitti': (s) => `${parseInt(s) / 100}`,
95
+ })
96
+ }
97
+
98
+ // Basic transaction
99
+ case '10':
100
+ columns = {
101
+ Tietuetunnus: code,
102
+ ...this.parseFixedLength(s.substring(6), {
103
+ 'Tapahtuman numero': 6,
104
+ Arkistointitunnus: 18,
105
+ Kirjauspäivä: 6,
106
+ Arvopäivä: 6,
107
+ Maksupäivä: 6,
108
+ Tapahtumatunnus: 1,
109
+ Koodi: 3,
110
+ Seliteteksti: 35,
111
+ 'Tapahtuman rahamäärä': 19,
112
+ Kuittikoodi: 1,
113
+ Välitystapa: 1,
114
+ 'Saaja/Maksaja': 35,
115
+ 'Nimen lähde': 1,
116
+ 'Saajan tili': 14,
117
+ 'Tili muuttunut -tieto': 1,
118
+ Viite: 20,
119
+ 'Lomakkeen numero': 8,
120
+ Tasotunnus: 1,
121
+ }, {
122
+ Kirjauspäivä: (s) => `20${s.substring(0, 2)}-${s.substring(2, 4)}-${s.substring(4, 6)}`,
123
+ Arvopäivä: (s) => `20${s.substring(0, 2)}-${s.substring(2, 4)}-${s.substring(4, 6)}`,
124
+ Maksupäivä: (s) => `20${s.substring(0, 2)}-${s.substring(2, 4)}-${s.substring(4, 6)}`,
125
+ Viite: (s) => s.replace(/^0+/, ''),
126
+ 'Tapahtuman rahamäärä': (s) => `${parseInt(s) / 100}`,
127
+ })
128
+ }
129
+ ref = columns.Arkistointitunnus
130
+ return columns
131
+
132
+ // Additional information.
133
+ case '11':
134
+ columns = {
135
+ Tietuetunnus: code,
136
+ ...this.parseFixedLength(s.substring(6), {
137
+ 'Lisätiedon tyyppi': 2,
138
+ Lisätieto: 999999
139
+ }, {
140
+ })
141
+ }
142
+ if (ref) {
143
+ columns['Edellinen Arkistointitunnus'] = ref
144
+ }
145
+ extras = columns['Lisätieto']
146
+ switch (columns['Lisätiedon tyyppi']) {
147
+ case '00':
148
+ Object.assign(columns, {
149
+ ...this.parseFixedLength(extras, {
150
+ 'Viesti-1': 35,
151
+ 'Viesti-2': 35,
152
+ 'Viesti-3': 35,
153
+ 'Viesti-4': 35,
154
+ 'Viesti-5': 35,
155
+ 'Viesti-6': 35,
156
+ 'Viesti-7': 35,
157
+ 'Viesti-8': 35,
158
+ 'Viesti-9': 35,
159
+ 'Viesti-10': 35,
160
+ 'Viesti-11': 35,
161
+ 'Viesti-12': 35,
162
+ }, {})
163
+ })
164
+ break
165
+
166
+ case '03':
167
+ Object.assign(columns, {
168
+ ...this.parseFixedLength(extras, {
169
+ 'Kortin numero': 19,
170
+ Tyhjää: 1,
171
+ 'Kaupan arkistoviite': 14,
172
+ }, {})
173
+ })
174
+ break
175
+
176
+ case '06':
177
+ Object.assign(columns, {
178
+ ...this.parseFixedLength(extras, {
179
+ 'Toimeksiantajan tieto-1': 35,
180
+ 'Toimeksiantajan tieto-2': 35,
181
+ }, {
182
+ 'Toimeksiantajan tieto-1': (s) => s.replace(/^0+/, ''),
183
+ 'Toimeksiantajan tieto-2': (s) => s.replace(/^0+/, ''),
184
+ })
185
+ })
186
+ break
187
+
188
+ case '11':
189
+ Object.assign(columns, {
190
+ ...this.parseFixedLength(extras, {
191
+ 'Maksajan viite': 35,
192
+ }, {})
193
+ })
194
+ break
195
+
196
+ default:
197
+ throw new NotImplemented(`Parsing a record of subtype '${columns['Lisätiedon tyyppi']}' is not implemented for record type 'T11'.`)
198
+ }
199
+ return columns
200
+
201
+ // Balance record.
202
+ case '40':
203
+ return {
204
+ Tietuetunnus: code,
205
+ ...this.parseFixedLength(s.substring(6), {
206
+ Kirjauspäivä: 6,
207
+ 'Kirjauspäivän loppusaldo': 19,
208
+ 'Käytettävissä oleva saldo': 19,
209
+ }, {
210
+ Kirjauspäivä: (s) => `20${s.substring(0, 2)}-${s.substring(2, 4)}-${s.substring(4, 6)}`,
211
+ 'Kirjauspäivän loppusaldo': (s) => `${parseInt(s) / 100}`,
212
+ 'Käytettävissä oleva saldo': (s) => `${parseInt(s) / 100}`,
213
+ })
214
+ }
215
+
216
+ // Balance record.
217
+ case '50':
218
+ return {
219
+ Tietuetunnus: code,
220
+ ...this.parseFixedLength(s.substring(6), {
221
+ 'Jakson tunnus': 1,
222
+ Jaksopäivä: 6,
223
+ 'Panot Kappalemäärä': 8,
224
+ 'Panot Summa': 19,
225
+ 'Otot Kappalemäärä': 8,
226
+ 'Otot Summa': 19,
227
+ }, {
228
+ Jaksopäivä: (s) => `20${s.substring(0, 2)}-${s.substring(2, 4)}-${s.substring(4, 6)}`,
229
+ 'Panot Summa': (s) => `${parseInt(s) / 100}`,
230
+ 'Panot Kappalemäärä': (s) => `${parseInt(s)}`,
231
+ 'Otot Summa': (s) => `${parseInt(s) / 100}`,
232
+ 'Otot Kappalemäärä': (s) => `${parseInt(s)}`,
233
+ })
234
+ }
235
+
236
+ // Notification record.
237
+ case '70':
238
+ return {
239
+ Tietuetunnus: code,
240
+ ...this.parseFixedLength(s.substring(6), {
241
+ 'Pankkiryhmän tunnus': 3,
242
+ Tiedote: 80 * 6,
243
+ }, {
244
+ })
245
+ }
246
+
247
+ default:
248
+ throw new NotImplemented(`Parsing a record of type 'T${code}' is not implemented.`)
249
+ }
250
+ return {}
251
+ }
252
+ }
253
+ }
254
+ }
255
+
256
+ canHandle(file: ProcessFile): boolean {
257
+ return file.startsWith('T00322100')
258
+ }
259
+
260
+ time(line: TextFileLine): Date | undefined {
261
+ const date = line.columns['Kirjauspäivä'] || line.columns['Jaksopäivä'] || undefined
262
+ return date ? new Date(date) : undefined
263
+ }
264
+
265
+ segmentId(line: TextFileLine): SegmentId | typeof NO_SEGMENT {
266
+ return line.columns.Arkistointitunnus || line.columns['Edellinen Arkistointitunnus'] || NO_SEGMENT
267
+ }
268
+ }