@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.
- package/dist/migrations/01_init.js +60 -0
- package/dist/src/cli.d.ts +81 -0
- package/dist/src/cli.js +242 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/account.d.ts +12 -0
- package/dist/src/commands/account.js +58 -0
- package/dist/src/commands/account.js.map +1 -0
- package/dist/src/commands/balance.d.ts +11 -0
- package/dist/src/commands/balance.js +117 -0
- package/dist/src/commands/balance.js.map +1 -0
- package/dist/src/commands/db.d.ts +14 -0
- package/dist/src/commands/db.js +69 -0
- package/dist/src/commands/db.js.map +1 -0
- package/dist/src/commands/entry.d.ts +13 -0
- package/dist/src/commands/entry.js +106 -0
- package/dist/src/commands/entry.js.map +1 -0
- package/dist/src/commands/import.d.ts +17 -0
- package/dist/src/commands/import.js +140 -0
- package/dist/src/commands/import.js.map +1 -0
- package/dist/src/commands/importer.d.ts +13 -0
- package/dist/src/commands/importer.js +71 -0
- package/dist/src/commands/importer.js.map +1 -0
- package/dist/src/commands/index.d.ts +191 -0
- package/dist/src/commands/index.js +482 -0
- package/dist/src/commands/index.js.map +1 -0
- package/dist/src/commands/period.d.ts +12 -0
- package/dist/src/commands/period.js +48 -0
- package/dist/src/commands/period.js.map +1 -0
- package/dist/src/commands/plugin.d.ts +15 -0
- package/dist/src/commands/plugin.js +78 -0
- package/dist/src/commands/plugin.js.map +1 -0
- package/dist/src/commands/report.d.ts +11 -0
- package/dist/src/commands/report.js +96 -0
- package/dist/src/commands/report.js.map +1 -0
- package/dist/src/commands/settings.d.ts +10 -0
- package/dist/src/commands/settings.js +64 -0
- package/dist/src/commands/settings.js.map +1 -0
- package/dist/src/commands/stock.d.ts +8 -0
- package/dist/src/commands/stock.js +73 -0
- package/dist/src/commands/stock.js.map +1 -0
- package/dist/src/commands/tag.d.ts +13 -0
- package/dist/src/commands/tag.js +89 -0
- package/dist/src/commands/tag.js.map +1 -0
- package/dist/src/commands/tx.d.ts +12 -0
- package/dist/src/commands/tx.js +81 -0
- package/dist/src/commands/tx.js.map +1 -0
- package/dist/src/commands/user.d.ts +12 -0
- package/dist/src/commands/user.js +52 -0
- package/dist/src/commands/user.js.map +1 -0
- package/dist/src/database/BookkeeperImporter.d.ts +77 -0
- package/dist/src/database/BookkeeperImporter.js +343 -0
- package/dist/src/database/BookkeeperImporter.js.map +1 -0
- package/dist/src/database/DB.d.ts +51 -0
- package/dist/src/database/DB.js +354 -0
- package/dist/src/database/DB.js.map +1 -0
- package/dist/src/database/index.d.ts +7 -0
- package/dist/src/database/index.js +8 -0
- package/dist/src/database/index.js.map +1 -0
- package/dist/src/doccer.d.ts +29 -0
- package/dist/src/doccer.js +30 -0
- package/dist/src/doccer.js.map +1 -0
- package/dist/src/error.d.ts +30 -0
- package/dist/src/error.js +35 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/export/Exporter.d.ts +69 -0
- package/dist/src/export/Exporter.js +123 -0
- package/dist/src/export/Exporter.js.map +1 -0
- package/dist/src/export/TasenorExporter.d.ts +55 -0
- package/dist/src/export/TasenorExporter.js +135 -0
- package/dist/src/export/TasenorExporter.js.map +1 -0
- package/dist/src/export/TilitinExporter.d.ts +71 -0
- package/dist/src/export/TilitinExporter.js +290 -0
- package/dist/src/export/TilitinExporter.js.map +1 -0
- package/dist/src/export/index.d.ts +8 -0
- package/dist/src/export/index.js +9 -0
- package/dist/src/export/index.js.map +1 -0
- package/dist/src/import/TextFileProcessHandler.d.ts +104 -0
- package/dist/src/import/TextFileProcessHandler.js +354 -0
- package/dist/src/import/TextFileProcessHandler.js.map +1 -0
- package/dist/src/import/TransactionImportConnector.d.ts +38 -0
- package/dist/src/import/TransactionImportConnector.js +27 -0
- package/dist/src/import/TransactionImportConnector.js.map +1 -0
- package/dist/src/import/TransactionImportHandler.d.ts +174 -0
- package/dist/src/import/TransactionImportHandler.js +736 -0
- package/dist/src/import/TransactionImportHandler.js.map +1 -0
- package/dist/src/import/TransactionRules.d.ts +238 -0
- package/dist/src/import/TransactionRules.js +522 -0
- package/dist/src/import/TransactionRules.js.map +1 -0
- package/dist/src/import/TransactionUI.d.ts +181 -0
- package/dist/src/import/TransactionUI.js +482 -0
- package/dist/src/import/TransactionUI.js.map +1 -0
- package/dist/src/import/TransferAnalyzer.d.ts +324 -0
- package/dist/src/import/TransferAnalyzer.js +1379 -0
- package/dist/src/import/TransferAnalyzer.js.map +1 -0
- package/dist/src/import/index.d.ts +11 -0
- package/dist/src/import/index.js +12 -0
- package/dist/src/import/index.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +12 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/net/crypto.d.ts +33 -0
- package/dist/src/net/crypto.js +63 -0
- package/dist/src/net/crypto.js.map +1 -0
- package/dist/src/net/git.d.ts +49 -0
- package/dist/src/net/git.js +137 -0
- package/dist/src/net/git.js.map +1 -0
- package/dist/src/net/index.d.ts +10 -0
- package/dist/src/net/index.js +11 -0
- package/dist/src/net/index.js.map +1 -0
- package/dist/src/net/middleware.d.ts +61 -0
- package/dist/src/net/middleware.js +220 -0
- package/dist/src/net/middleware.js.map +1 -0
- package/dist/src/net/tokens.d.ts +50 -0
- package/dist/src/net/tokens.js +141 -0
- package/dist/src/net/tokens.js.map +1 -0
- package/dist/src/net/vault.d.ts +67 -0
- package/dist/src/net/vault.js +145 -0
- package/dist/src/net/vault.js.map +1 -0
- package/dist/src/plugins/BackendPlugin.d.ts +91 -0
- package/dist/src/plugins/BackendPlugin.js +165 -0
- package/dist/src/plugins/BackendPlugin.js.map +1 -0
- package/dist/src/plugins/DataPlugin.d.ts +13 -0
- package/dist/src/plugins/DataPlugin.js +26 -0
- package/dist/src/plugins/DataPlugin.js.map +1 -0
- package/dist/src/plugins/ImportPlugin.d.ts +188 -0
- package/dist/src/plugins/ImportPlugin.js +204 -0
- package/dist/src/plugins/ImportPlugin.js.map +1 -0
- package/dist/src/plugins/ReportPlugin.d.ts +132 -0
- package/dist/src/plugins/ReportPlugin.js +393 -0
- package/dist/src/plugins/ReportPlugin.js.map +1 -0
- package/dist/src/plugins/SchemePlugin.d.ts +34 -0
- package/dist/src/plugins/SchemePlugin.js +47 -0
- package/dist/src/plugins/SchemePlugin.js.map +1 -0
- package/dist/src/plugins/ServicePlugin.d.ts +80 -0
- package/dist/src/plugins/ServicePlugin.js +168 -0
- package/dist/src/plugins/ServicePlugin.js.map +1 -0
- package/dist/src/plugins/ToolPlugin.d.ts +27 -0
- package/dist/src/plugins/ToolPlugin.js +37 -0
- package/dist/src/plugins/ToolPlugin.js.map +1 -0
- package/dist/src/plugins/index.d.ts +13 -0
- package/dist/src/plugins/index.js +14 -0
- package/dist/src/plugins/index.js.map +1 -0
- package/dist/src/plugins/plugins.d.ts +101 -0
- package/dist/src/plugins/plugins.js +292 -0
- package/dist/src/plugins/plugins.js.map +1 -0
- package/dist/src/process/Process.d.ts +108 -0
- package/dist/src/process/Process.js +335 -0
- package/dist/src/process/Process.js.map +1 -0
- package/dist/src/process/ProcessConnector.d.ts +24 -0
- package/dist/src/process/ProcessConnector.js +28 -0
- package/dist/src/process/ProcessConnector.js.map +1 -0
- package/dist/src/process/ProcessFile.d.ts +69 -0
- package/dist/src/process/ProcessFile.js +145 -0
- package/dist/src/process/ProcessFile.js.map +1 -0
- package/dist/src/process/ProcessHandler.d.ts +60 -0
- package/dist/src/process/ProcessHandler.js +73 -0
- package/dist/src/process/ProcessHandler.js.map +1 -0
- package/dist/src/process/ProcessStep.d.ts +52 -0
- package/dist/src/process/ProcessStep.js +78 -0
- package/dist/src/process/ProcessStep.js.map +1 -0
- package/dist/src/process/ProcessingSystem.d.ts +60 -0
- package/dist/src/process/ProcessingSystem.js +182 -0
- package/dist/src/process/ProcessingSystem.js.map +1 -0
- package/dist/src/process/index.d.ts +11 -0
- package/dist/src/process/index.js +12 -0
- package/dist/src/process/index.js.map +1 -0
- package/dist/src/reports/conversions.d.ts +8 -0
- package/dist/src/reports/conversions.js +47 -0
- package/dist/src/reports/conversions.js.map +1 -0
- package/dist/src/reports/index.d.ts +6 -0
- package/dist/src/reports/index.js +7 -0
- package/dist/src/reports/index.js.map +1 -0
- package/dist/src/server/ISPDemoServer.d.ts +43 -0
- package/dist/src/server/ISPDemoServer.js +112 -0
- package/dist/src/server/ISPDemoServer.js.map +1 -0
- package/dist/src/server/api.d.ts +15 -0
- package/dist/src/server/api.js +27 -0
- package/dist/src/server/api.js.map +1 -0
- package/dist/src/server/index.d.ts +7 -0
- package/dist/src/server/index.js +8 -0
- package/dist/src/server/index.js.map +1 -0
- package/dist/src/server/router.d.ts +5 -0
- package/dist/src/server/router.js +37 -0
- package/dist/src/server/router.js.map +1 -0
- package/dist/src/system.d.ts +27 -0
- package/dist/src/system.js +95 -0
- package/dist/src/system.js.map +1 -0
- package/dist/tests/TransactionRules.spec.d.ts +1 -0
- package/dist/tests/TransactionRules.spec.js +64 -0
- package/dist/tests/TransactionRules.spec.js.map +1 -0
- package/dist/tests/password.spec.d.ts +1 -0
- package/dist/tests/password.spec.js +8 -0
- package/dist/tests/password.spec.js.map +1 -0
- package/dist/tests/tokens.spec.d.ts +1 -0
- package/dist/tests/tokens.spec.js +49 -0
- package/dist/tests/tokens.spec.js.map +1 -0
- package/dist/tests/vault.spec.d.ts +1 -0
- package/dist/tests/vault.spec.js +19 -0
- package/dist/tests/vault.spec.js.map +1 -0
- package/package.json +3 -3
- package/src/import/TransactionImportHandler.ts +5 -1
- package/src/index.ts +0 -1
- package/src/testing/ProcessingSystemMock.ts +0 -45
- package/src/testing/UnitTestImportConnector.ts +0 -86
- package/src/testing/UnitTester.ts +0 -231
- package/src/testing/index.ts +0 -4
- package/src/testing/test-handlers.ts +0 -47
- package/tests/TransferAnalyzer-account-address.spec.ts +0 -87
- package/tests/TransferAnalyzer-buying-and-selling.spec.ts +0 -354
- package/tests/TransferAnalyzer-loans.spec.ts +0 -197
- package/tests/TransferAnalyzer-multiple-null-amounts.spec.ts +0 -181
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { afterAll, beforeAll, expect, test } from '@jest/globals';
|
|
2
|
+
import { mute, unmute, TOKEN_ISSUER } from '@tasenor/common';
|
|
3
|
+
import { tokens, vault } from '../src';
|
|
4
|
+
import jwt from 'jsonwebtoken';
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
mute();
|
|
7
|
+
});
|
|
8
|
+
afterAll(() => {
|
|
9
|
+
unmute();
|
|
10
|
+
});
|
|
11
|
+
const SECRET = 'ABCD1234';
|
|
12
|
+
test('Sign token and check validity', async () => {
|
|
13
|
+
process.env.VAULT_URL = 'env://';
|
|
14
|
+
process.env.SECRET = SECRET;
|
|
15
|
+
await vault.initialize();
|
|
16
|
+
const token = await tokens.sign({
|
|
17
|
+
owner: 'root@localhost',
|
|
18
|
+
feats: {},
|
|
19
|
+
plugins: []
|
|
20
|
+
}, 'refresh');
|
|
21
|
+
// Sanity checks.
|
|
22
|
+
expect(typeof token === 'string').toBeTruthy();
|
|
23
|
+
expect(token.length > 32).toBeTruthy();
|
|
24
|
+
// Check the token.
|
|
25
|
+
const payload = tokens.verify(token, SECRET, 'refresh');
|
|
26
|
+
expect(payload).toBeTruthy();
|
|
27
|
+
expect(payload.owner).toBe('root@localhost');
|
|
28
|
+
expect(payload.feats).toStrictEqual({});
|
|
29
|
+
expect(payload.plugins).toStrictEqual([]);
|
|
30
|
+
expect(tokens.verify(token, SECRET, 'no-api')).toBeFalsy();
|
|
31
|
+
expect(tokens.verify(token, 'WRONG', 'erp')).toBeFalsy();
|
|
32
|
+
expect(() => tokens.verify(token, null, 'erp')).toThrow();
|
|
33
|
+
});
|
|
34
|
+
test('Check that invalid token does not pass the check', () => {
|
|
35
|
+
const SECRET = 'ABCD1234';
|
|
36
|
+
const bad1 = jwt.sign({ data: {} }, SECRET, {});
|
|
37
|
+
expect(tokens.verify(bad1, SECRET, 'erp')).toBeFalsy();
|
|
38
|
+
const bad2 = jwt.sign({ data: { user: 'x', feats: {}, plugins: [] } }, SECRET, {});
|
|
39
|
+
expect(tokens.verify(bad2, SECRET, 'erp')).toBeFalsy();
|
|
40
|
+
const bad3 = jwt.sign({ data: { user: 'x', feats: {}, plugins: [] } }, SECRET, { issuer: 'Bad' });
|
|
41
|
+
expect(tokens.verify(bad3, SECRET, 'erp')).toBeFalsy();
|
|
42
|
+
const bad4 = jwt.sign({ data: { user: 'x', feats: {}, plugins: [] } }, SECRET, { issuer: TOKEN_ISSUER });
|
|
43
|
+
expect(tokens.verify(bad4, SECRET, 'erp')).toBeFalsy();
|
|
44
|
+
const bad5 = jwt.sign({ data: { user: 'x', feats: {}, plugins: [] } }, SECRET, { issuer: TOKEN_ISSUER, expiresIn: -5 });
|
|
45
|
+
expect(tokens.verify(bad5, SECRET, 'erp')).toBeFalsy();
|
|
46
|
+
const bad6 = jwt.sign({ data: { user: 'x', feats: {}, plugins: [] } }, SECRET, { audience: 'bad-api', issuer: TOKEN_ISSUER, expiresIn: 60 });
|
|
47
|
+
expect(tokens.verify(bad6, SECRET, 'erp')).toBeFalsy();
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=tokens.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.spec.js","sourceRoot":"","sources":["../../tests/tokens.spec.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { expect, test } from '@jest/globals';
|
|
2
|
+
import { vault } from '../src';
|
|
3
|
+
test('Test simple environment vault', async () => {
|
|
4
|
+
process.env.VAULT_URL = '';
|
|
5
|
+
await expect(async () => await vault.initialize()).rejects.toThrow();
|
|
6
|
+
await expect(async () => await vault.get('SECRET')).rejects.toThrow();
|
|
7
|
+
process.env.VAULT_URL = 'env://foo';
|
|
8
|
+
expect(vault.getVault().url).toBe('env://foo');
|
|
9
|
+
process.env.VAULT_URL = 'env://bar';
|
|
10
|
+
expect(vault.getVault().url).toBe('env://bar');
|
|
11
|
+
expect(vault.getVault().url).toBe('env://bar');
|
|
12
|
+
process.env.SECRET = 'Hush!';
|
|
13
|
+
await vault.initialize();
|
|
14
|
+
expect(await vault.get('SECRET')).toBe('Hush!');
|
|
15
|
+
// Secrets are not affected.
|
|
16
|
+
process.env.SECRET = 'Smash!';
|
|
17
|
+
expect(await vault.get('SECRET')).toBe('Hush!');
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=vault.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.spec.js","sourceRoot":"","sources":["../../tests/vault.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAE9B,IAAI,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;IAC/C,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,EAAE,CAAA;IAC1B,MAAM,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;IACpE,MAAM,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;IACrE,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,WAAW,CAAA;IACnC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,WAAW,CAAA;IACnC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAC9C,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAE9C,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,OAAO,CAAA;IAC5B,MAAM,KAAK,CAAC,UAAU,EAAE,CAAA;IACxB,MAAM,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC/C,4BAA4B;IAC5B,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAA;IAC7B,MAAM,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACjD,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tasenor/common-node",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.34",
|
|
4
4
|
"description": "Common Node-parts of Tasenor project",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"sqlite3": "^5.1.6",
|
|
37
37
|
"tar": "^6.1.15",
|
|
38
38
|
"ts-opaque": "^3.0.1",
|
|
39
|
-
"@tasenor/common": "1.9.
|
|
39
|
+
"@tasenor/common": "1.9.34"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@jest/globals": "^29.6.1",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"tsconfig": "0.0.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"ci": "pnpm run lint && pnpm run
|
|
53
|
+
"ci": "pnpm run lint && pnpm run test",
|
|
54
54
|
"build": "rm -rf dist && tsc && cp -r migrations dist/",
|
|
55
55
|
"fix": "eslint --fix 'src/**/*.ts' 'tests/**/*.ts'",
|
|
56
56
|
"lint": "eslint 'src/**/*.ts' 'tests/**/*.ts'",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import { TasenorElement, AccountAddress, Asset, AssetExchange, AssetTransfer, AssetTransferReason, AssetType, Currency, Language, TransactionDescription, TransactionApplyResults, debug, realNegative, AccountNumber, realPositive, ProcessConfig, ImportStateText, TextFileLine, SegmentId, NO_SEGMENT, num, ImportSegment, Directions, ImportAnswers, ImportConfig, BalanceSummaryEntry, less, mergeTags, log } from '@tasenor/common'
|
|
2
|
+
import { TasenorElement, AccountAddress, Asset, AssetExchange, AssetTransfer, AssetTransferReason, AssetType, Currency, Language, TransactionDescription, TransactionApplyResults, debug, realNegative, AccountNumber, realPositive, ProcessConfig, ImportStateText, TextFileLine, SegmentId, NO_SEGMENT, num, ImportSegment, Directions, ImportAnswers, ImportConfig, BalanceSummaryEntry, less, mergeTags, log, DirectoryPath } from '@tasenor/common'
|
|
3
3
|
import { TransferAnalyzer } from './TransferAnalyzer'
|
|
4
4
|
import hash from 'object-hash'
|
|
5
5
|
import { TransactionUI } from './TransactionUI'
|
|
@@ -25,6 +25,10 @@ export class TransactionImportHandler extends TextFileProcessHandler {
|
|
|
25
25
|
this.rules = new TransactionRules(this)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
get path(): DirectoryPath {
|
|
29
|
+
throw new Error(`Import handler '${this.name}' does not implement get path().`)
|
|
30
|
+
}
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
33
|
* By default, we don't support multifile.
|
|
30
34
|
* @param file
|
package/src/index.ts
CHANGED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import { ID, ProcessConfig, ProcessName } from '@tasenor/common'
|
|
3
|
-
import { UnitTestImportConnector } from './UnitTestImportConnector'
|
|
4
|
-
import { KnexDatabase, Process, ProcessConnector, ProcessFile, ProcessFileData, ProcessHandler, ProcessHandlerMap, ProcessStep } from '..'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Processing system mock for unit testing.
|
|
8
|
-
*/
|
|
9
|
-
export class SystemMock {
|
|
10
|
-
db: KnexDatabase
|
|
11
|
-
handlers: ProcessHandlerMap = {}
|
|
12
|
-
connector: ProcessConnector
|
|
13
|
-
logger: {
|
|
14
|
-
info: (...msg) => void
|
|
15
|
-
error: (...msg) => void
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
this.connector = new UnitTestImportConnector()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async getTranslation(text: string, language: string): Promise<string> {
|
|
23
|
-
return this.connector.getTranslation(text, language)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
register(handler: ProcessHandler): void {
|
|
27
|
-
//
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async createProcess(name: ProcessName, filed: ProcessFileData[], config: ProcessConfig): Promise<Process> {
|
|
31
|
-
return new Process(this, name, config)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async checkFinishAndFindDirections(handler: ProcessHandler, step: ProcessStep): Promise<void> {
|
|
35
|
-
//
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getHandler(name: string): ProcessHandler {
|
|
39
|
-
return this.handlers[name]
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async loadProcess(id: ID): Promise<Process> {
|
|
43
|
-
return this.createProcess('dummy', [new ProcessFile({ name: 'file', encoding: 'utf-8', data: 'Hello' })], {})
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import { AccountAddress, AccountNumber, Asset, AssetExchange, AssetTransfer, AssetType, BalanceBookkeeping, Currency, Language, StockValueData, TradeableAsset, ImportState, ProcessConfig, Directions, ID } from '@tasenor/common'
|
|
3
|
-
import { ImportPlugin, TransactionImportConnector, TransactionImportHandler, ISPDemoServer } from '..'
|
|
4
|
-
import { CoinbaseHandler } from '../../../tasenor-common-plugins/src/CoinbaseImport/backend/CoinbaseHandler'
|
|
5
|
-
import IncomeAndExpenses from '../../../tasenor-common-plugins/src/IncomeAndExpenses/backend'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A connector mock for unit testing.
|
|
9
|
-
*/
|
|
10
|
-
export class UnitTestImportConnector implements TransactionImportConnector {
|
|
11
|
-
|
|
12
|
-
private balance: Record<AccountNumber, number> = {}
|
|
13
|
-
private number: Record<AccountAddress, AccountNumber> = {}
|
|
14
|
-
|
|
15
|
-
async initialize(server: ISPDemoServer) {
|
|
16
|
-
//
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
addMoney(address: AccountAddress, number: AccountNumber, amount: number) {
|
|
20
|
-
this.balance[address] = (this.balance[address] || 0) + amount
|
|
21
|
-
this.number[address] = number
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async initializeBalances(time: Date, balances: BalanceBookkeeping, config: ProcessConfig): Promise<void> {
|
|
25
|
-
balances.configureNames(config)
|
|
26
|
-
Object.keys(this.balance).forEach(address => balances.set(this.number[address], this.balance[address]))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async getAccountCanditates(): Promise<AccountNumber[]> {
|
|
30
|
-
return []
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async getStock(time: Date, account: AccountNumber, symbol: TradeableAsset): Promise<StockValueData> {
|
|
34
|
-
return {
|
|
35
|
-
amount: 0,
|
|
36
|
-
value: 0
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async getVAT(time: Date, transfer: AssetTransfer, currency: Currency): Promise<null | number> {
|
|
41
|
-
return null
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async getRate(time: Date, type: AssetType, asset: Asset, currency: Currency, exchange: AssetExchange|null = null): Promise<number> {
|
|
45
|
-
return 1.0
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async getTranslation(text: string, language: string): Promise<string> {
|
|
49
|
-
// Borrow a plugins to get some translations.
|
|
50
|
-
const plugin = new ImportPlugin(new CoinbaseHandler() as unknown as TransactionImportHandler)
|
|
51
|
-
const ret = plugin.t(text, language as Language)
|
|
52
|
-
if (ret !== text) {
|
|
53
|
-
return ret
|
|
54
|
-
}
|
|
55
|
-
const IEplugin = new IncomeAndExpenses()
|
|
56
|
-
return IEplugin.t(text, language as Language)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async applyResult(): Promise<Record<string, unknown>> {
|
|
60
|
-
return {}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async resultExists(processId: ID, args: unknown): Promise<boolean> {
|
|
64
|
-
return false
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async success(res: ImportState) {
|
|
68
|
-
//
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async fail(res: ImportState) {
|
|
72
|
-
//
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async waiting(res: ImportState, directions: Directions) {
|
|
76
|
-
//
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async run(): Promise<void> {
|
|
80
|
-
//
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async rollback(processId: ID): Promise<boolean> {
|
|
84
|
-
return true
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { AccountAddress, AccountNumber, AdditionalTransferInfo, AssetTransfer, StockValueData, Transaction, TransactionDescription, TransactionLine, ImportStateText, ImportConfig } from '@tasenor/common'
|
|
2
|
-
import { TransactionImportHandler, AskUI, Process } from '..'
|
|
3
|
-
import { getTestHandler } from './test-handlers'
|
|
4
|
-
import { SystemMock } from './ProcessingSystemMock'
|
|
5
|
-
import { sprintf } from 'sprintf-js'
|
|
6
|
-
import { UnitTestImportConnector } from './UnitTestImportConnector'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Helper types to reduce type forcing in simple test data.
|
|
10
|
-
*/
|
|
11
|
-
export type AssetTransferTestData = Omit<Omit<AssetTransfer, 'asset'>, 'amount'> & { asset: string, amount?: number | undefined | null }
|
|
12
|
-
|
|
13
|
-
export type AdditionalTransferInfoTestData = Omit<AdditionalTransferInfo, 'stock'> & {
|
|
14
|
-
stock?: {
|
|
15
|
-
set?: Partial<Record<string, StockValueData>>
|
|
16
|
-
change?: Partial<Record<string, StockValueData>>
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type TransactionLineTestData = Omit<Omit<TransactionLine, 'data'>, 'account'> & {
|
|
21
|
-
account: string
|
|
22
|
-
data?: AdditionalTransferInfoTestData
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A container for setting up testing system.
|
|
27
|
-
*/
|
|
28
|
-
export class UnitTester {
|
|
29
|
-
|
|
30
|
-
static accounts: string[] = [
|
|
31
|
-
'deposit.external.EUR',
|
|
32
|
-
'deposit.currency.EUR',
|
|
33
|
-
'expense.statement.TRADE_LOSS_STOCK',
|
|
34
|
-
'fee.currency.EUR',
|
|
35
|
-
'fee.currency.USD',
|
|
36
|
-
'income.statement.TRADE_PROFIT_CRYPTO',
|
|
37
|
-
'income.statement.TRADE_PROFIT_SHORT',
|
|
38
|
-
'trade.crypto.ETH',
|
|
39
|
-
'trade.currency.EUR',
|
|
40
|
-
'trade.currency.USD',
|
|
41
|
-
'trade.short.NAKD',
|
|
42
|
-
'trade.stock.NAKD',
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
accountNumber: Record<string, string> = {}
|
|
46
|
-
accountName: Record<string, string> = {}
|
|
47
|
-
config: ImportConfig
|
|
48
|
-
handler: TransactionImportHandler
|
|
49
|
-
process: Process
|
|
50
|
-
|
|
51
|
-
constructor(conf: Record<string, unknown> = {}) {
|
|
52
|
-
this.config = {
|
|
53
|
-
currency: 'EUR',
|
|
54
|
-
language: 'en',
|
|
55
|
-
isTradeFeePartOfTotal: false,
|
|
56
|
-
allowShortSelling: false,
|
|
57
|
-
recordDeposits: true,
|
|
58
|
-
rules: []
|
|
59
|
-
}
|
|
60
|
-
Object.assign(this.config, conf)
|
|
61
|
-
let number = 1000
|
|
62
|
-
this.accountName = {}
|
|
63
|
-
this.accountNumber = {}
|
|
64
|
-
for (const name of UnitTester.accounts) {
|
|
65
|
-
this.config[`account.${name}`] = `${number}`
|
|
66
|
-
this.accountName[`${number}`] = name
|
|
67
|
-
this.accountNumber[name] = `${number}`
|
|
68
|
-
number += 10
|
|
69
|
-
}
|
|
70
|
-
this.handler = getTestHandler('Coinbase')
|
|
71
|
-
this.handler.system = new SystemMock()
|
|
72
|
-
this.process = new Process(this.handler.system, 'Unit test', this.config)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Set the configuration value. Also add mapping if account.
|
|
77
|
-
* @param name
|
|
78
|
-
* @param value
|
|
79
|
-
*/
|
|
80
|
-
set(name, value) {
|
|
81
|
-
this.config[name] = value
|
|
82
|
-
if (name.startsWith('account.')) {
|
|
83
|
-
if (this.accountName[value]) {
|
|
84
|
-
throw new Error(`Account number ${value} already exists. Please choose some other for ${name}.`)
|
|
85
|
-
}
|
|
86
|
-
this.accountName[value] = name.substr(8)
|
|
87
|
-
this.accountNumber[name.substr(8)] = value
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Add an answer to the answer collection.
|
|
93
|
-
*/
|
|
94
|
-
answer(segment, name, value) {
|
|
95
|
-
this.config.answers = this.config.answers || {}
|
|
96
|
-
if (this.config.answers) {
|
|
97
|
-
this.config.answers[segment] = this.config.answers[segment] || {};
|
|
98
|
-
(this.config.answers[segment] as Record<string, unknown>)[name] = value
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Get the account balance.
|
|
104
|
-
* @param name
|
|
105
|
-
*/
|
|
106
|
-
get(addr): number {
|
|
107
|
-
const number = this.accountNumber[addr]
|
|
108
|
-
if (!number) {
|
|
109
|
-
throw new Error(`Invalid account name ${addr}.`)
|
|
110
|
-
}
|
|
111
|
-
return this.handler.getBalance(addr)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Add to the initial balance.
|
|
116
|
-
* @param accunt
|
|
117
|
-
* @param amount
|
|
118
|
-
*/
|
|
119
|
-
addMoney(account: string, amount: number) {
|
|
120
|
-
if (!this.accountNumber[`${account}`]) {
|
|
121
|
-
throw new Error(`Account ${account} not defined in UnitTester class.`)
|
|
122
|
-
}
|
|
123
|
-
(this.handler.system.connector as UnitTestImportConnector).addMoney(account as AccountAddress, this.accountNumber[`${account}`] as AccountNumber, amount)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Construct a state for transfers.
|
|
128
|
-
* @param transfers
|
|
129
|
-
*/
|
|
130
|
-
makeState(transferSets: AssetTransfer[][]): ImportStateText<'classified'> {
|
|
131
|
-
const state: ImportStateText<'classified'> = {
|
|
132
|
-
stage: 'classified',
|
|
133
|
-
files: {
|
|
134
|
-
'test.csv': {
|
|
135
|
-
lines: []
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
state.segments = {}
|
|
141
|
-
state.result = {}
|
|
142
|
-
|
|
143
|
-
for (let i = 0; i < transferSets.length; i++) {
|
|
144
|
-
const id = `segment${i}`
|
|
145
|
-
state.segments[id] = {
|
|
146
|
-
id,
|
|
147
|
-
time: new Date(`2022-01-01T00:00:${sprintf('%02d', i)}.000Z`),
|
|
148
|
-
lines: []
|
|
149
|
-
}
|
|
150
|
-
state.result[id] = [{
|
|
151
|
-
type: 'transfers',
|
|
152
|
-
transfers: transferSets[i]
|
|
153
|
-
}]
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return state
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Execute one or more transfer analysis.
|
|
161
|
-
* @param transfers
|
|
162
|
-
* @param entries
|
|
163
|
-
* @returns
|
|
164
|
-
*/
|
|
165
|
-
async test(transfers: AssetTransferTestData[], entries: TransactionLineTestData[][],
|
|
166
|
-
transfers2: AssetTransferTestData[] | undefined = undefined, entries2: TransactionLineTestData[][] | undefined = undefined,
|
|
167
|
-
transfers3: AssetTransferTestData[] | undefined = undefined, entries3: TransactionLineTestData[][] | undefined = undefined,
|
|
168
|
-
transfers4: AssetTransferTestData[] | undefined = undefined, entries4: TransactionLineTestData[][] | undefined = undefined,
|
|
169
|
-
transfers5: AssetTransferTestData[] | undefined = undefined, entries5: TransactionLineTestData[][] | undefined = undefined
|
|
170
|
-
) {
|
|
171
|
-
const transfersSets: AssetTransfer[][] = [transfers as AssetTransfer[]]
|
|
172
|
-
const entriesSet: TransactionLine[][][] = [entries as TransactionLine[][]]
|
|
173
|
-
if (transfers2) transfersSets.push(transfers2 as AssetTransfer[])
|
|
174
|
-
if (transfers3) transfersSets.push(transfers3 as AssetTransfer[])
|
|
175
|
-
if (transfers4) transfersSets.push(transfers4 as AssetTransfer[])
|
|
176
|
-
if (transfers5) transfersSets.push(transfers5 as AssetTransfer[])
|
|
177
|
-
if (entries2) entriesSet.push(entries2 as TransactionLine[][])
|
|
178
|
-
if (entries3) entriesSet.push(entries3 as TransactionLine[][])
|
|
179
|
-
if (entries4) entriesSet.push(entries4 as TransactionLine[][])
|
|
180
|
-
if (entries5) entriesSet.push(entries5 as TransactionLine[][])
|
|
181
|
-
|
|
182
|
-
const state = this.makeState(transfersSets)
|
|
183
|
-
// Check just for compiler.
|
|
184
|
-
if (!state.result || !state.segments) {
|
|
185
|
-
return
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let out
|
|
189
|
-
try {
|
|
190
|
-
out = await this.handler.analysis(this.process, state, [], this.config)
|
|
191
|
-
} catch (err) {
|
|
192
|
-
if (err instanceof AskUI) {
|
|
193
|
-
console.log('\u001b[31mTest incomplete. Need more configuration.\u001b[0m')
|
|
194
|
-
console.dir(err.element, { depth: null })
|
|
195
|
-
}
|
|
196
|
-
throw err
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (!out.result) {
|
|
200
|
-
throw new Error(`Analyse failed to get results from ${JSON.stringify(state)}.`)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
for (let i = 0; i < entriesSet.length; i++) {
|
|
204
|
-
const id = `segment${i}`
|
|
205
|
-
if (!out.result[id]) {
|
|
206
|
-
throw new Error(`Analyse failed to get results from ${JSON.stringify(state)}.`)
|
|
207
|
-
}
|
|
208
|
-
// Convert accounts to symbolic to make test writing easier.
|
|
209
|
-
for (const data of out.result[id] as TransactionDescription[]) {
|
|
210
|
-
if (data.transactions) {
|
|
211
|
-
for (const tx of data.transactions) {
|
|
212
|
-
for (const entry of tx.entries) {
|
|
213
|
-
if (this.accountName[entry.account]) {
|
|
214
|
-
entry.account = this.accountName[entry.account] as AccountNumber
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
// Verify results.
|
|
221
|
-
const result: Transaction[] = entriesSet[i].map(entries => ({
|
|
222
|
-
date: new Date(`2022-01-01T00:00:${sprintf('%02d', i)}.000Z`),
|
|
223
|
-
segmentId: id,
|
|
224
|
-
entries
|
|
225
|
-
}))
|
|
226
|
-
|
|
227
|
-
const { expect } = await import('@jest/globals')
|
|
228
|
-
expect(result).toStrictEqual(out.result[id][0].transactions)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
package/src/testing/index.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import { CoinbaseHandler } from '../../../tasenor-common-plugins/src/CoinbaseImport/backend/CoinbaseHandler'
|
|
4
|
-
import { KrakenHandler } from '../../../tasenor-common-plugins/src/KrakenImport/backend/KrakenHandler'
|
|
5
|
-
import { LynxHandler } from '../../../tasenor-common-plugins/src/LynxImport/backend/LynxHandler'
|
|
6
|
-
import { NordeaHandler } from '../../../tasenor-common-plugins/src/NordeaImport/backend/NordeaHandler'
|
|
7
|
-
import { NordnetHandler } from '../../../tasenor-common-plugins/src/NordnetImport/backend/NordnetHandler'
|
|
8
|
-
import { TITOHandler } from '../../../tasenor-common-plugins/src/TITOImport/backend/TITOHandler'
|
|
9
|
-
import { TransactionImportHandler } from '..'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Mapping from handler class names to instances.
|
|
13
|
-
*/
|
|
14
|
-
const handlers: Record<string, TransactionImportHandler> = {
|
|
15
|
-
// Typescript commonly screws up, if there are slight version differencies. Force type.
|
|
16
|
-
Coinbase: new CoinbaseHandler() as unknown as TransactionImportHandler,
|
|
17
|
-
Nordea: new NordeaHandler() as unknown as TransactionImportHandler,
|
|
18
|
-
Nordnet: new NordnetHandler() as unknown as TransactionImportHandler,
|
|
19
|
-
Lynx: new LynxHandler() as unknown as TransactionImportHandler,
|
|
20
|
-
Kraken: new KrakenHandler() as unknown as TransactionImportHandler,
|
|
21
|
-
TITO: new TITOHandler() as unknown as TransactionImportHandler,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Get a handler instance for testing.
|
|
26
|
-
* @param name
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
export function getTestHandler(className: string): TransactionImportHandler {
|
|
30
|
-
if (!handlers[className]) {
|
|
31
|
-
throw new Error(`No such import handler as '${className}'.`)
|
|
32
|
-
}
|
|
33
|
-
return handlers[className]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Get handler path.
|
|
38
|
-
* @param className
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
export function getTestHandlerPath(className: string): string {
|
|
42
|
-
const dirName = path.join(__dirname, '..', '..', '..', 'tasenor-common-plugins', 'src', `${className}Import`, 'backend')
|
|
43
|
-
if (!fs.existsSync(dirName)) {
|
|
44
|
-
throw new Error(`No such import handler path as '${className}'.`)
|
|
45
|
-
}
|
|
46
|
-
return dirName
|
|
47
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { UnitTester } from '../src/testing'
|
|
2
|
-
|
|
3
|
-
test('Direct expense account address', async () => {
|
|
4
|
-
|
|
5
|
-
const tester = new UnitTester()
|
|
6
|
-
|
|
7
|
-
await tester.test(
|
|
8
|
-
// Use direct reference to the account.
|
|
9
|
-
[
|
|
10
|
-
{
|
|
11
|
-
reason: 'expense',
|
|
12
|
-
type: 'account',
|
|
13
|
-
asset: '112233',
|
|
14
|
-
amount: -200,
|
|
15
|
-
data: {
|
|
16
|
-
text: 'My expense paid'
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
reason: 'expense',
|
|
21
|
-
type: 'account',
|
|
22
|
-
asset: '445566',
|
|
23
|
-
amount: 200
|
|
24
|
-
}
|
|
25
|
-
], [[
|
|
26
|
-
{
|
|
27
|
-
account: '112233',
|
|
28
|
-
amount: -20000,
|
|
29
|
-
description: 'My expense paid',
|
|
30
|
-
data: {
|
|
31
|
-
text: 'My expense paid'
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
account: '445566',
|
|
36
|
-
amount: 20000,
|
|
37
|
-
description: 'My expense paid',
|
|
38
|
-
}
|
|
39
|
-
]]
|
|
40
|
-
)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test('Direct income account address', async () => {
|
|
44
|
-
|
|
45
|
-
const tester = new UnitTester()
|
|
46
|
-
|
|
47
|
-
await tester.test(
|
|
48
|
-
// Use direct reference to the account.
|
|
49
|
-
[
|
|
50
|
-
{
|
|
51
|
-
reason: 'income',
|
|
52
|
-
type: 'account',
|
|
53
|
-
asset: '112233',
|
|
54
|
-
amount: -200,
|
|
55
|
-
data: {
|
|
56
|
-
text: 'My income paid.'
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
reason: 'income',
|
|
61
|
-
type: 'account',
|
|
62
|
-
asset: '445566',
|
|
63
|
-
amount: 200,
|
|
64
|
-
data: {
|
|
65
|
-
text: 'Yes it is.'
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
], [[
|
|
69
|
-
{
|
|
70
|
-
account: '112233',
|
|
71
|
-
amount: -20000,
|
|
72
|
-
description: 'My income paid. Yes it is.',
|
|
73
|
-
data: {
|
|
74
|
-
text: 'My income paid.'
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
account: '445566',
|
|
79
|
-
amount: 20000,
|
|
80
|
-
description: 'My income paid. Yes it is.',
|
|
81
|
-
data: {
|
|
82
|
-
text: 'Yes it is.'
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
]]
|
|
86
|
-
)
|
|
87
|
-
})
|