@tasenor/common-node 1.9.32 → 1.9.34

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 (211) hide show
  1. package/dist/migrations/01_init.js +60 -0
  2. package/dist/src/cli.d.ts +81 -0
  3. package/dist/src/cli.js +242 -0
  4. package/dist/src/cli.js.map +1 -0
  5. package/dist/src/commands/account.d.ts +12 -0
  6. package/dist/src/commands/account.js +58 -0
  7. package/dist/src/commands/account.js.map +1 -0
  8. package/dist/src/commands/balance.d.ts +11 -0
  9. package/dist/src/commands/balance.js +117 -0
  10. package/dist/src/commands/balance.js.map +1 -0
  11. package/dist/src/commands/db.d.ts +14 -0
  12. package/dist/src/commands/db.js +69 -0
  13. package/dist/src/commands/db.js.map +1 -0
  14. package/dist/src/commands/entry.d.ts +13 -0
  15. package/dist/src/commands/entry.js +106 -0
  16. package/dist/src/commands/entry.js.map +1 -0
  17. package/dist/src/commands/import.d.ts +17 -0
  18. package/dist/src/commands/import.js +140 -0
  19. package/dist/src/commands/import.js.map +1 -0
  20. package/dist/src/commands/importer.d.ts +13 -0
  21. package/dist/src/commands/importer.js +71 -0
  22. package/dist/src/commands/importer.js.map +1 -0
  23. package/dist/src/commands/index.d.ts +191 -0
  24. package/dist/src/commands/index.js +482 -0
  25. package/dist/src/commands/index.js.map +1 -0
  26. package/dist/src/commands/period.d.ts +12 -0
  27. package/dist/src/commands/period.js +48 -0
  28. package/dist/src/commands/period.js.map +1 -0
  29. package/dist/src/commands/plugin.d.ts +15 -0
  30. package/dist/src/commands/plugin.js +78 -0
  31. package/dist/src/commands/plugin.js.map +1 -0
  32. package/dist/src/commands/report.d.ts +11 -0
  33. package/dist/src/commands/report.js +96 -0
  34. package/dist/src/commands/report.js.map +1 -0
  35. package/dist/src/commands/settings.d.ts +10 -0
  36. package/dist/src/commands/settings.js +64 -0
  37. package/dist/src/commands/settings.js.map +1 -0
  38. package/dist/src/commands/stock.d.ts +8 -0
  39. package/dist/src/commands/stock.js +73 -0
  40. package/dist/src/commands/stock.js.map +1 -0
  41. package/dist/src/commands/tag.d.ts +13 -0
  42. package/dist/src/commands/tag.js +89 -0
  43. package/dist/src/commands/tag.js.map +1 -0
  44. package/dist/src/commands/tx.d.ts +12 -0
  45. package/dist/src/commands/tx.js +81 -0
  46. package/dist/src/commands/tx.js.map +1 -0
  47. package/dist/src/commands/user.d.ts +12 -0
  48. package/dist/src/commands/user.js +52 -0
  49. package/dist/src/commands/user.js.map +1 -0
  50. package/dist/src/database/BookkeeperImporter.d.ts +77 -0
  51. package/dist/src/database/BookkeeperImporter.js +343 -0
  52. package/dist/src/database/BookkeeperImporter.js.map +1 -0
  53. package/dist/src/database/DB.d.ts +51 -0
  54. package/dist/src/database/DB.js +354 -0
  55. package/dist/src/database/DB.js.map +1 -0
  56. package/dist/src/database/index.d.ts +7 -0
  57. package/dist/src/database/index.js +8 -0
  58. package/dist/src/database/index.js.map +1 -0
  59. package/dist/src/doccer.d.ts +29 -0
  60. package/dist/src/doccer.js +30 -0
  61. package/dist/src/doccer.js.map +1 -0
  62. package/dist/src/error.d.ts +30 -0
  63. package/dist/src/error.js +35 -0
  64. package/dist/src/error.js.map +1 -0
  65. package/dist/src/export/Exporter.d.ts +69 -0
  66. package/dist/src/export/Exporter.js +123 -0
  67. package/dist/src/export/Exporter.js.map +1 -0
  68. package/dist/src/export/TasenorExporter.d.ts +55 -0
  69. package/dist/src/export/TasenorExporter.js +135 -0
  70. package/dist/src/export/TasenorExporter.js.map +1 -0
  71. package/dist/src/export/TilitinExporter.d.ts +71 -0
  72. package/dist/src/export/TilitinExporter.js +290 -0
  73. package/dist/src/export/TilitinExporter.js.map +1 -0
  74. package/dist/src/export/index.d.ts +8 -0
  75. package/dist/src/export/index.js +9 -0
  76. package/dist/src/export/index.js.map +1 -0
  77. package/dist/src/import/TextFileProcessHandler.d.ts +104 -0
  78. package/dist/src/import/TextFileProcessHandler.js +354 -0
  79. package/dist/src/import/TextFileProcessHandler.js.map +1 -0
  80. package/dist/src/import/TransactionImportConnector.d.ts +38 -0
  81. package/dist/src/import/TransactionImportConnector.js +27 -0
  82. package/dist/src/import/TransactionImportConnector.js.map +1 -0
  83. package/dist/src/import/TransactionImportHandler.d.ts +174 -0
  84. package/dist/src/import/TransactionImportHandler.js +736 -0
  85. package/dist/src/import/TransactionImportHandler.js.map +1 -0
  86. package/dist/src/import/TransactionRules.d.ts +238 -0
  87. package/dist/src/import/TransactionRules.js +522 -0
  88. package/dist/src/import/TransactionRules.js.map +1 -0
  89. package/dist/src/import/TransactionUI.d.ts +181 -0
  90. package/dist/src/import/TransactionUI.js +482 -0
  91. package/dist/src/import/TransactionUI.js.map +1 -0
  92. package/dist/src/import/TransferAnalyzer.d.ts +324 -0
  93. package/dist/src/import/TransferAnalyzer.js +1379 -0
  94. package/dist/src/import/TransferAnalyzer.js.map +1 -0
  95. package/dist/src/import/index.d.ts +11 -0
  96. package/dist/src/import/index.js +12 -0
  97. package/dist/src/import/index.js.map +1 -0
  98. package/dist/src/index.d.ts +11 -0
  99. package/dist/src/index.js +12 -0
  100. package/dist/src/index.js.map +1 -0
  101. package/dist/src/net/crypto.d.ts +33 -0
  102. package/dist/src/net/crypto.js +63 -0
  103. package/dist/src/net/crypto.js.map +1 -0
  104. package/dist/src/net/git.d.ts +49 -0
  105. package/dist/src/net/git.js +137 -0
  106. package/dist/src/net/git.js.map +1 -0
  107. package/dist/src/net/index.d.ts +10 -0
  108. package/dist/src/net/index.js +11 -0
  109. package/dist/src/net/index.js.map +1 -0
  110. package/dist/src/net/middleware.d.ts +61 -0
  111. package/dist/src/net/middleware.js +220 -0
  112. package/dist/src/net/middleware.js.map +1 -0
  113. package/dist/src/net/tokens.d.ts +50 -0
  114. package/dist/src/net/tokens.js +141 -0
  115. package/dist/src/net/tokens.js.map +1 -0
  116. package/dist/src/net/vault.d.ts +67 -0
  117. package/dist/src/net/vault.js +145 -0
  118. package/dist/src/net/vault.js.map +1 -0
  119. package/dist/src/plugins/BackendPlugin.d.ts +91 -0
  120. package/dist/src/plugins/BackendPlugin.js +165 -0
  121. package/dist/src/plugins/BackendPlugin.js.map +1 -0
  122. package/dist/src/plugins/DataPlugin.d.ts +13 -0
  123. package/dist/src/plugins/DataPlugin.js +26 -0
  124. package/dist/src/plugins/DataPlugin.js.map +1 -0
  125. package/dist/src/plugins/ImportPlugin.d.ts +188 -0
  126. package/dist/src/plugins/ImportPlugin.js +204 -0
  127. package/dist/src/plugins/ImportPlugin.js.map +1 -0
  128. package/dist/src/plugins/ReportPlugin.d.ts +132 -0
  129. package/dist/src/plugins/ReportPlugin.js +393 -0
  130. package/dist/src/plugins/ReportPlugin.js.map +1 -0
  131. package/dist/src/plugins/SchemePlugin.d.ts +34 -0
  132. package/dist/src/plugins/SchemePlugin.js +47 -0
  133. package/dist/src/plugins/SchemePlugin.js.map +1 -0
  134. package/dist/src/plugins/ServicePlugin.d.ts +80 -0
  135. package/dist/src/plugins/ServicePlugin.js +168 -0
  136. package/dist/src/plugins/ServicePlugin.js.map +1 -0
  137. package/dist/src/plugins/ToolPlugin.d.ts +27 -0
  138. package/dist/src/plugins/ToolPlugin.js +37 -0
  139. package/dist/src/plugins/ToolPlugin.js.map +1 -0
  140. package/dist/src/plugins/index.d.ts +13 -0
  141. package/dist/src/plugins/index.js +14 -0
  142. package/dist/src/plugins/index.js.map +1 -0
  143. package/dist/src/plugins/plugins.d.ts +101 -0
  144. package/dist/src/plugins/plugins.js +292 -0
  145. package/dist/src/plugins/plugins.js.map +1 -0
  146. package/dist/src/process/Process.d.ts +108 -0
  147. package/dist/src/process/Process.js +335 -0
  148. package/dist/src/process/Process.js.map +1 -0
  149. package/dist/src/process/ProcessConnector.d.ts +24 -0
  150. package/dist/src/process/ProcessConnector.js +28 -0
  151. package/dist/src/process/ProcessConnector.js.map +1 -0
  152. package/dist/src/process/ProcessFile.d.ts +69 -0
  153. package/dist/src/process/ProcessFile.js +145 -0
  154. package/dist/src/process/ProcessFile.js.map +1 -0
  155. package/dist/src/process/ProcessHandler.d.ts +60 -0
  156. package/dist/src/process/ProcessHandler.js +73 -0
  157. package/dist/src/process/ProcessHandler.js.map +1 -0
  158. package/dist/src/process/ProcessStep.d.ts +52 -0
  159. package/dist/src/process/ProcessStep.js +78 -0
  160. package/dist/src/process/ProcessStep.js.map +1 -0
  161. package/dist/src/process/ProcessingSystem.d.ts +60 -0
  162. package/dist/src/process/ProcessingSystem.js +182 -0
  163. package/dist/src/process/ProcessingSystem.js.map +1 -0
  164. package/dist/src/process/index.d.ts +11 -0
  165. package/dist/src/process/index.js +12 -0
  166. package/dist/src/process/index.js.map +1 -0
  167. package/dist/src/reports/conversions.d.ts +8 -0
  168. package/dist/src/reports/conversions.js +47 -0
  169. package/dist/src/reports/conversions.js.map +1 -0
  170. package/dist/src/reports/index.d.ts +6 -0
  171. package/dist/src/reports/index.js +7 -0
  172. package/dist/src/reports/index.js.map +1 -0
  173. package/dist/src/server/ISPDemoServer.d.ts +43 -0
  174. package/dist/src/server/ISPDemoServer.js +112 -0
  175. package/dist/src/server/ISPDemoServer.js.map +1 -0
  176. package/dist/src/server/api.d.ts +15 -0
  177. package/dist/src/server/api.js +27 -0
  178. package/dist/src/server/api.js.map +1 -0
  179. package/dist/src/server/index.d.ts +7 -0
  180. package/dist/src/server/index.js +8 -0
  181. package/dist/src/server/index.js.map +1 -0
  182. package/dist/src/server/router.d.ts +5 -0
  183. package/dist/src/server/router.js +37 -0
  184. package/dist/src/server/router.js.map +1 -0
  185. package/dist/src/system.d.ts +27 -0
  186. package/dist/src/system.js +95 -0
  187. package/dist/src/system.js.map +1 -0
  188. package/dist/tests/TransactionRules.spec.d.ts +1 -0
  189. package/dist/tests/TransactionRules.spec.js +64 -0
  190. package/dist/tests/TransactionRules.spec.js.map +1 -0
  191. package/dist/tests/password.spec.d.ts +1 -0
  192. package/dist/tests/password.spec.js +8 -0
  193. package/dist/tests/password.spec.js.map +1 -0
  194. package/dist/tests/tokens.spec.d.ts +1 -0
  195. package/dist/tests/tokens.spec.js +49 -0
  196. package/dist/tests/tokens.spec.js.map +1 -0
  197. package/dist/tests/vault.spec.d.ts +1 -0
  198. package/dist/tests/vault.spec.js +19 -0
  199. package/dist/tests/vault.spec.js.map +1 -0
  200. package/package.json +3 -3
  201. package/src/import/TransactionImportHandler.ts +5 -1
  202. package/src/index.ts +0 -1
  203. package/src/testing/ProcessingSystemMock.ts +0 -45
  204. package/src/testing/UnitTestImportConnector.ts +0 -86
  205. package/src/testing/UnitTester.ts +0 -231
  206. package/src/testing/index.ts +0 -4
  207. package/src/testing/test-handlers.ts +0 -47
  208. package/tests/TransferAnalyzer-account-address.spec.ts +0 -87
  209. package/tests/TransferAnalyzer-buying-and-selling.spec.ts +0 -354
  210. package/tests/TransferAnalyzer-loans.spec.ts +0 -197
  211. package/tests/TransferAnalyzer-multiple-null-amounts.spec.ts +0 -181
@@ -0,0 +1,354 @@
1
+ import * as csvParse from 'csv-parse';
2
+ import { BadState, NotImplemented } from '../error';
3
+ import { ProcessHandler } from '../process/ProcessHandler';
4
+ import { isImportAction, isImportAnswerAction, isImportConfigureAction, isImportOpAction, Directions, isImportRetryAction } from '@tasenor/common';
5
+ /**
6
+ * Utility class to provide tools for implementing any text file based process handler.
7
+ */
8
+ export class TextFileProcessHandler extends ProcessHandler {
9
+ importOptions = {
10
+ parser: 'csv',
11
+ numericFields: [],
12
+ requiredFields: [],
13
+ insignificantFields: [],
14
+ sharedFields: [],
15
+ textField: null,
16
+ totalAmountField: null
17
+ };
18
+ /**
19
+ * Split the file to lines and keep line numbers with the lines. Mark state type as initial state.
20
+ * @param file
21
+ * @returns
22
+ */
23
+ startingState(processFiles) {
24
+ const files = {};
25
+ for (const processFile of processFiles) {
26
+ const original = processFile.decode();
27
+ let lines;
28
+ if (this.importOptions.custom) {
29
+ // Use custom splitter if defined.
30
+ lines = this.importOptions.custom.splitToLines(original).map((text, idx) => ({
31
+ text,
32
+ line: idx,
33
+ columns: {}
34
+ }));
35
+ }
36
+ else {
37
+ // Otherwise just split from new lines.
38
+ lines = original.replace(/\n+$/, '').split('\n').map((text, line) => ({
39
+ text,
40
+ line,
41
+ columns: {}
42
+ }));
43
+ }
44
+ files[processFile.name] = { lines };
45
+ }
46
+ return {
47
+ stage: 'initial',
48
+ files
49
+ };
50
+ }
51
+ /**
52
+ * Check the state type is matching to 'complete'.
53
+ * @param state
54
+ */
55
+ checkCompletion(state) {
56
+ if (state.stage === 'executed') {
57
+ return true;
58
+ }
59
+ return undefined;
60
+ }
61
+ /**
62
+ * A hook to check alternative directions from initial state.
63
+ * @param state
64
+ * @returns
65
+ */
66
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
67
+ async needInputForSegmentation(state, config) {
68
+ return false;
69
+ }
70
+ /**
71
+ * A hook to check alternative directions from segmented state.
72
+ * @param state
73
+ * @returns
74
+ */
75
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
76
+ async needInputForClassification(state, config) {
77
+ return false;
78
+ }
79
+ /**
80
+ * A hook to check alternative directions from classified state.
81
+ * @param state
82
+ * @returns
83
+ */
84
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
85
+ async needInputForAnalysis(state, config) {
86
+ return false;
87
+ }
88
+ /**
89
+ * A hook to check alternative directions from analyzed state.
90
+ * @param state
91
+ * @returns
92
+ */
93
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
94
+ async needInputForExecution(state, config) {
95
+ return false;
96
+ }
97
+ /**
98
+ * Run steps in order 'segmentation', 'classification', 'analysis', 'execution'.
99
+ * @param state
100
+ * @returns
101
+ */
102
+ async getDirections(state, config) {
103
+ let input;
104
+ let directions;
105
+ switch (state.stage) {
106
+ case 'initial':
107
+ input = await this.needInputForSegmentation(state, config);
108
+ if (input)
109
+ return input;
110
+ directions = new Directions({
111
+ type: 'action',
112
+ action: { op: 'segmentation' }
113
+ });
114
+ break;
115
+ case 'segmented':
116
+ input = await this.needInputForClassification(state, config);
117
+ if (input)
118
+ return input;
119
+ directions = new Directions({
120
+ type: 'action',
121
+ action: { op: 'classification' }
122
+ });
123
+ break;
124
+ case 'classified':
125
+ input = await this.needInputForAnalysis(state, config);
126
+ if (input)
127
+ return input;
128
+ directions = new Directions({
129
+ type: 'action',
130
+ action: { op: 'analysis' }
131
+ });
132
+ break;
133
+ case 'analyzed':
134
+ input = await this.needInputForExecution(state, config);
135
+ if (input)
136
+ return input;
137
+ directions = new Directions({
138
+ type: 'action',
139
+ action: { op: 'execution' }
140
+ });
141
+ break;
142
+ default:
143
+ throw new BadState('Cannot find directions from the current state.');
144
+ }
145
+ return directions;
146
+ }
147
+ /**
148
+ * Call subclass implementation for each action.
149
+ * @param action
150
+ * @param state
151
+ * @param files
152
+ */
153
+ async action(process, action, state, files) {
154
+ if (!isImportAction(action)) {
155
+ throw new BadState(`Action is not import action ${JSON.stringify(action)}`);
156
+ }
157
+ if (isImportRetryAction(action)) {
158
+ this.system.logger.info(`Executing 'retry' action on process #${process.id}.`);
159
+ process.status = 'INCOMPLETE';
160
+ process.error = undefined;
161
+ await process.save();
162
+ return state;
163
+ }
164
+ if (isImportOpAction(action)) {
165
+ this.system.logger.info(`Executing '${action.op}' action on process #${process.id}.`);
166
+ switch (action.op) {
167
+ case 'analysis':
168
+ case 'classification':
169
+ case 'segmentation':
170
+ case 'execution':
171
+ return this[action.op](process, state, files, process.config);
172
+ default:
173
+ throw new BadState(`Cannot parse action ${JSON.stringify(action)}`);
174
+ }
175
+ }
176
+ if (isImportConfigureAction(action)) {
177
+ this.system.logger.info(`Updating 'configuration' on process #${process.id}.`);
178
+ Object.assign(process.config, action.configure);
179
+ await process.save();
180
+ }
181
+ if (isImportAnswerAction(action)) {
182
+ this.system.logger.info(`Updating 'answers' on process #${process.id}.`);
183
+ if (!process.config.answers) {
184
+ process.config.answers = {};
185
+ }
186
+ const answers = process.config.answers;
187
+ for (const segmentId of Object.keys(action.answer)) {
188
+ answers[segmentId] = answers[segmentId] || {};
189
+ for (const variable of Object.keys(action.answer[segmentId])) {
190
+ answers[segmentId][variable] = action.answer[segmentId][variable];
191
+ }
192
+ }
193
+ await process.save();
194
+ }
195
+ return state;
196
+ }
197
+ /**
198
+ * This function must implement gathering of each line together that forms together one import activity.
199
+ * @param state
200
+ * @param files
201
+ */
202
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
203
+ async segmentation(process, state, files, config) {
204
+ throw new NotImplemented(`A class ${this.constructor.name} does not implement segmentation().`);
205
+ }
206
+ /**
207
+ * This function must implement gathering of each line together that forms together one import activity.
208
+ * @param state
209
+ * @param files
210
+ */
211
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
212
+ async classification(process, state, files, config) {
213
+ throw new NotImplemented(`A class ${this.constructor.name} does not implement classification().`);
214
+ }
215
+ /**
216
+ * This function must implement conversion from classified data to the actual executable operations.
217
+ * @param state
218
+ * @param files
219
+ */
220
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
221
+ async analysis(process, state, files, config) {
222
+ throw new NotImplemented(`A class ${this.constructor.name} does not implement analysis().`);
223
+ }
224
+ /**
225
+ * This function must implement applying the result in practice.
226
+ * @param state
227
+ * @param files
228
+ */
229
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
230
+ async execution(process, state, files, config) {
231
+ throw new NotImplemented(`A class ${this.constructor.name} does not implement execution().`);
232
+ }
233
+ /**
234
+ * Parse a single line of CSV.
235
+ * @param line
236
+ * @param options
237
+ * @returns
238
+ */
239
+ async parseCsvLine(line, options = {}) {
240
+ return new Promise((resolve, reject) => {
241
+ csvParse.parse(line, {
242
+ delimiter: options.columnSeparator || ',',
243
+ skip_records_with_error: !!options.skipErrors
244
+ }, function (err, out) {
245
+ if (err) {
246
+ reject(err);
247
+ }
248
+ else {
249
+ resolve(out[0]);
250
+ }
251
+ });
252
+ });
253
+ }
254
+ /**
255
+ * Go through each file and each line and add CSV interpretation of the content to each line.
256
+ * @param state
257
+ * @param options
258
+ * @returns The original state that has been modified by adding CSV parsed field `columns`.
259
+ */
260
+ async parseCSV(state, options = {}) {
261
+ // Heading names per column.
262
+ let headings = [];
263
+ let dropLines = options.cutFromBeginning || 0;
264
+ // Run loop over all files.
265
+ let firstLine = true;
266
+ for (const fileName of Object.keys(state.files)) {
267
+ // Process each line from CSV.
268
+ for (let n = 0; n < state.files[fileName].lines.length; n++) {
269
+ if (dropLines) {
270
+ dropLines--;
271
+ continue;
272
+ }
273
+ const line = { ...state.files[fileName].lines[n] };
274
+ const text = options.trimLines ? line.text.trim() : line.text;
275
+ // Collect or define headings on the first line.
276
+ if (firstLine) {
277
+ firstLine = false;
278
+ if (options.useFirstLineHeadings) {
279
+ headings = await this.parseCsvLine(text, options);
280
+ const headCount = {};
281
+ for (let i = 0; i < headings.length; i++) {
282
+ headCount[headings[i]] = headCount[headings[i]] || 0;
283
+ headCount[headings[i]]++;
284
+ if (headCount[headings[i]] > 1) {
285
+ headings[i] = `${headings[i]}${headCount[headings[i]]}`;
286
+ }
287
+ }
288
+ continue;
289
+ }
290
+ else {
291
+ const size = (await this.parseCsvLine(text, options)).length;
292
+ for (let i = 0; i < size; i++) {
293
+ headings.push(`${i}`);
294
+ }
295
+ }
296
+ }
297
+ // Map each column to its heading name.
298
+ const columns = {};
299
+ const pieces = text.trim() !== '' ? await this.parseCsvLine(text, options) : null;
300
+ if (pieces) {
301
+ pieces.forEach((column, index) => {
302
+ if (index < headings.length) {
303
+ columns[headings[index]] = column;
304
+ }
305
+ else {
306
+ columns['+'] = columns['+'] || '';
307
+ columns['+'] += column + '\n';
308
+ }
309
+ });
310
+ line.columns = columns;
311
+ // Add it back with columns.
312
+ state.files[fileName].lines[n] = line;
313
+ }
314
+ }
315
+ }
316
+ const newState = {
317
+ ...state,
318
+ stage: 'segmented'
319
+ };
320
+ return newState;
321
+ }
322
+ /**
323
+ * Handler for pure custom handler.
324
+ */
325
+ async parseCustom(state, options) {
326
+ for (const fileName of Object.keys(state.files)) {
327
+ for (const line of state.files[fileName].lines) {
328
+ line.columns = options.splitToColumns(line.text);
329
+ }
330
+ }
331
+ const newState = {
332
+ ...state,
333
+ stage: 'segmented'
334
+ };
335
+ return newState;
336
+ }
337
+ /**
338
+ * Split a string to fixed length fields given as name and length mapping.
339
+ */
340
+ parseFixedLength(src, offsets, conversions) {
341
+ const ret = {};
342
+ const keys = Object.keys(offsets);
343
+ for (let n = 0, i = 0; i < keys.length; i++) {
344
+ const column = src.substring(n, n + offsets[keys[i]]);
345
+ ret[keys[i]] = column.trim();
346
+ if (conversions[keys[i]]) {
347
+ ret[keys[i]] = conversions[keys[i]](ret[keys[i]]);
348
+ }
349
+ n += offsets[keys[i]];
350
+ }
351
+ return ret;
352
+ }
353
+ }
354
+ //# sourceMappingURL=TextFileProcessHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextFileProcessHandler.js","sourceRoot":"","sources":["../../../src/import/TextFileProcessHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAgB,cAAc,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,gBAAgB,EAA4B,UAAU,EAAgE,mBAAmB,EAAiD,MAAM,iBAAiB,CAAA;AAGvS;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,cAAc;IAEjD,aAAa,GAA6B;QAC/C,MAAM,EAAE,KAAK;QACb,aAAa,EAAE,EAAE;QACjB,cAAc,EAAE,EAAE;QAClB,mBAAmB,EAAE,EAAE;QACvB,YAAY,EAAE,EAAE;QAChB,SAAS,EAAE,IAAI;QACf,gBAAgB,EAAE,IAAI;KACvB,CAAA;IAED;;;;OAIG;IACH,aAAa,CAAC,YAA2B;QACvC,MAAM,KAAK,GAA8C,EAAE,CAAA;QAE3D,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE;YACtC,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,EA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AI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YACrD,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;YAC5B,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;gBACxB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;aAClD;YACD,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;SACtB;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ import { Asset, AssetType, AssetExchange, AccountNumber, TradeableAsset, StockValueData, Currency, AssetTransfer, BalanceBookkeeping, ProcessConfig, AccountAddress } from '@tasenor/common';
2
+ import { ProcessConnector } from '../process';
3
+ /**
4
+ * An interface definition for linking generic import processor to the Bookkeeper.
5
+ */
6
+ export interface TransactionImportConnector extends ProcessConnector {
7
+ /**
8
+ * Set the balances at the given time stamp.
9
+ * @param time
10
+ * @param balances
11
+ */
12
+ initializeBalances(time: Date, balances: BalanceBookkeeping, config: ProcessConfig): Promise<void>;
13
+ /**
14
+ * Get the list of accounts that are canditates for holding matching transactions of the given account address.
15
+ * @param asset
16
+ */
17
+ getAccountCanditates(addr: AccountAddress, config: ProcessConfig): Promise<AccountNumber[]>;
18
+ /**
19
+ * Get the preferred default account for the given account address.
20
+ * @param addr
21
+ */
22
+ getRate(time: Date, type: AssetType, asset: Asset, currency: Currency, exchange: AssetExchange): Promise<number>;
23
+ /**
24
+ * Find out how many assets we have at the given time.
25
+ * @param time
26
+ * @param account
27
+ * @param symbol
28
+ */
29
+ getStock(time: Date, account: AccountNumber, symbol: TradeableAsset): Promise<StockValueData>;
30
+ /**
31
+ * Find the VAT value for the transfer if any.
32
+ * @param time
33
+ * @param transfer
34
+ * @param currency
35
+ */
36
+ getVAT(time: Date, transfer: AssetTransfer, currency: Currency): Promise<null | number>;
37
+ }
38
+ export declare function isTransactionImportConnector(o: unknown): o is TransactionImportConnector;
@@ -0,0 +1,27 @@
1
+ export function isTransactionImportConnector(o) {
2
+ if (typeof o !== 'object' || o === null) {
3
+ return false;
4
+ }
5
+ let f = o.getRate;
6
+ if (typeof f !== 'function') {
7
+ return false;
8
+ }
9
+ f = o.getStock;
10
+ if (typeof f !== 'function') {
11
+ return false;
12
+ }
13
+ f = o.initializeBalances;
14
+ if (typeof f !== 'function') {
15
+ return false;
16
+ }
17
+ f = o.getAccountCanditates;
18
+ if (typeof f !== 'function') {
19
+ return false;
20
+ }
21
+ f = o.getVAT;
22
+ if (typeof f !== 'function') {
23
+ return false;
24
+ }
25
+ return true;
26
+ }
27
+ //# sourceMappingURL=TransactionImportConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionImportConnector.js","sourceRoot":"","sources":["../../../src/import/TransactionImportConnector.ts"],"names":[],"mappings":"AAuCA,MAAM,UAAU,4BAA4B,CAAC,CAAU;IACrD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,EAAE;QACvC,OAAO,KAAK,CAAA;KACb;IACD,IAAI,CAAC,GAAI,CAA6B,CAAC,OAAO,CAAA;IAC9C,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;QAC3B,OAAO,KAAK,CAAA;KACb;IACD,CAAC,GAAI,CAA6B,CAAC,QAAQ,CAAA;IAC3C,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;QAC3B,OAAO,KAAK,CAAA;KACb;IACD,CAAC,GAAI,CAA6B,CAAC,kBAAkB,CAAA;IACrD,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;QAC3B,OAAO,KAAK,CAAA;KACb;IACD,CAAC,GAAI,CAA6B,CAAC,oBAAoB,CAAA;IACvD,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;QAC3B,OAAO,KAAK,CAAA;KACb;IACD,CAAC,GAAI,CAA6B,CAAC,MAAM,CAAA;IACzC,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;QAC3B,OAAO,KAAK,CAAA;KACb;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,174 @@
1
+ import { AccountAddress, Asset, AssetExchange, AssetTransfer, AssetType, Currency, Language, TransactionDescription, AccountNumber, ProcessConfig, ImportStateText, TextFileLine, SegmentId, NO_SEGMENT, ImportSegment, Directions, ImportConfig, BalanceSummaryEntry, DirectoryPath } from '@tasenor/common';
2
+ import { TransactionUI } from './TransactionUI';
3
+ import { TransactionRules } from './TransactionRules';
4
+ import { TextFileProcessHandler } from './TextFileProcessHandler';
5
+ import { Process, ProcessFile } from '../process';
6
+ /**
7
+ * Core functionality for all transaction import handlers.
8
+ */
9
+ export declare class TransactionImportHandler extends TextFileProcessHandler {
10
+ UI: TransactionUI;
11
+ rules: TransactionRules;
12
+ private analyzer;
13
+ constructor(name: string);
14
+ get path(): DirectoryPath;
15
+ /**
16
+ * By default, we don't support multifile.
17
+ * @param file
18
+ * @returns
19
+ */
20
+ canAppend(file: ProcessFile): boolean;
21
+ /**
22
+ * Get a single account balance.
23
+ * @param addr
24
+ */
25
+ getBalance(addr: AccountAddress): number;
26
+ /**
27
+ * Get the translation for the text to the currently configured language.
28
+ * @param text
29
+ * @returns
30
+ */
31
+ getTranslation(text: string, language: Language | undefined): Promise<string>;
32
+ /**
33
+ * Get the account having matching asset in their code.
34
+ * @param asset
35
+ * @returns
36
+ */
37
+ getAccountCanditates(addr: AccountAddress, config: ProcessConfig): Promise<AccountNumber[]>;
38
+ /**
39
+ * Construct grouping for the line data with columns defined using sub class that can generate unique ID per transaction.
40
+ * @param state
41
+ */
42
+ groupingById(state: ImportStateText<'segmented'>): Promise<ImportStateText<'segmented'>>;
43
+ /**
44
+ * Default parser for file data.
45
+ */
46
+ parse(state: ImportStateText<'initial'>, config?: ProcessConfig): Promise<ImportStateText<'segmented'>>;
47
+ /**
48
+ * Default segmentation is parsing CSV and then grouping by segment ID constructed for each line.
49
+ * @param state
50
+ * @param files
51
+ * @returns
52
+ */
53
+ segmentationCSV(process: Process, state: ImportStateText<'initial'>, files: ProcessFile[]): Promise<ImportStateText<'segmented'>>;
54
+ /**
55
+ * Hook to do some post proccessing for segmentation process. Collects standard fields.
56
+ * @param state
57
+ * @returns
58
+ */
59
+ segmentationPostProcess(state: ImportStateText<'segmented'>): Promise<ImportStateText<'segmented'>>;
60
+ segmentation(process: Process, state: ImportStateText<'initial'>, files: ProcessFile[]): Promise<ImportStateText<'segmented'>>;
61
+ /**
62
+ * Helper to dump segmentation results.
63
+ */
64
+ debugSegmentation(state: ImportStateText<'segmented'>): void;
65
+ /**
66
+ * Construct a hash for a text line usable as unique segment ID.
67
+ * @param line
68
+ */
69
+ hash(line: TextFileLine, columns?: string[] | undefined): SegmentId;
70
+ /**
71
+ * Segmentation by ID can use this function to group lines by their ID. By default the hash is used.
72
+ * @param line
73
+ */
74
+ segmentId(line: TextFileLine, columns?: string[] | undefined): SegmentId | typeof NO_SEGMENT;
75
+ /**
76
+ * Find out the timestamp from the line data if any.
77
+ * @param line
78
+ */
79
+ time(line: TextFileLine): Date | undefined;
80
+ /**
81
+ * Default classification constructs lines belonging to each segment and asks subclass to classify them.
82
+ *
83
+ * @param state
84
+ * @param files
85
+ * @returns
86
+ */
87
+ classification(process: Process, state: ImportStateText<'segmented'>, files: ProcessFile[]): Promise<ImportStateText<'classified'>>;
88
+ /**
89
+ * Helper to dump classification results.
90
+ */
91
+ debugClassification(state: ImportStateText<'classified'>): void;
92
+ /**
93
+ * By default, use rules to classify.
94
+ * @param lines
95
+ */
96
+ classifyLines(lines: TextFileLine[], config: ProcessConfig, segment: ImportSegment): Promise<TransactionDescription>;
97
+ /**
98
+ * Collect lines related to the segment.
99
+ * @param state
100
+ * @param segmentId
101
+ */
102
+ getLines(state: ImportStateText<'classified'>, segmentId: SegmentId): TextFileLine[] | null;
103
+ /**
104
+ * Check if all accounts are configured and if not, construct query UI for it.
105
+ * @param state
106
+ * @returns
107
+ */
108
+ needInputForAnalysis(state: ImportStateText<'classified'>, config: ProcessConfig): Promise<Directions | false>;
109
+ /**
110
+ * Study configured accounts and missing accounts and construct appropriate UI query for accounts.
111
+ * @param missing
112
+ * @param config
113
+ * @returns
114
+ */
115
+ directionsForMissingAccounts(missing: Set<AccountAddress>, config: ProcessConfig): Promise<Directions | false>;
116
+ /**
117
+ * Insert custom segments based on answer collection, if necessary.
118
+ */
119
+ createCustomSegments(state: ImportStateText<'classified'>, config: ImportConfig): Promise<ImportStateText<'classified'>>;
120
+ /**
121
+ * Sort the segments by their date.
122
+ * @param segments
123
+ * @returns
124
+ */
125
+ sortSegments(segments: Record<string, ImportSegment>): ImportSegment[];
126
+ /**
127
+ * Convert transfers to the actual transactions with account numbers.
128
+ * @param state
129
+ * @param files
130
+ */
131
+ analysis(process: Process, state: ImportStateText<'classified'>, files: ProcessFile[], config: ProcessConfig): Promise<ImportStateText<'analyzed'>>;
132
+ /**
133
+ * Analyze and construct transaction details from a transaction description.
134
+ * @param txs
135
+ */
136
+ analyze(txs: TransactionDescription, segment: ImportSegment, config: ProcessConfig, state: ImportStateText<'classified'>, debtAccounts: Record<AccountNumber, BalanceSummaryEntry>): Promise<TransactionDescription>;
137
+ /**
138
+ * Check if the resulting transactions needs to be recorded to loan account.
139
+ */
140
+ checkForLoan(result: TransactionDescription, debtAccounts: Record<AccountNumber, BalanceSummaryEntry>): Promise<TransactionDescription>;
141
+ /**
142
+ * Dump analysis results.
143
+ * @param state
144
+ */
145
+ debugAnalysis(state: ImportStateText<'analyzed'>): void;
146
+ /**
147
+ * Apply the result using the connector.
148
+ * @param state
149
+ * @param files
150
+ * @returns
151
+ */
152
+ execution(process: Process, state: ImportStateText<'analyzed'>, files: ProcessFile[]): Promise<ImportStateText<'executed'>>;
153
+ /**
154
+ * Ask VAT from connector.
155
+ * @param time
156
+ * @param reason
157
+ * @param asset
158
+ * @param currency
159
+ */
160
+ getVAT(time: Date, transfer: AssetTransfer, currency: Currency): Promise<null | number>;
161
+ /**
162
+ * Find the rate in the default currency for the asset.
163
+ * If there is information about rates inside the files, this function could be overridden and
164
+ * used for digging actual values. Those values can be collected during parse() call.
165
+ * @param time
166
+ * @param type
167
+ * @param asset
168
+ */
169
+ getRate(time: Date, type: AssetType, asset: Asset, currency: Currency, exchange: AssetExchange): Promise<number>;
170
+ /**
171
+ * Remove transactions created.
172
+ */
173
+ rollback(process: Process, state: ImportStateText<'executed'>): Promise<ImportStateText<'rolledback'>>;
174
+ }