Skip to content

Commit ead915f

Browse files
committed
Add ignore patterns, remove Bun
1 parent ce798f2 commit ead915f

File tree

6 files changed

+65
-16
lines changed

6 files changed

+65
-16
lines changed

README.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,29 @@ A short summary:
6161

6262
Once you have configured your importer, run `actual-monmon verify` to verify that the configuration has the correct format.
6363

64-
**Usage**
64+
## Usage
6565

6666
Once configured, importing is as simple as running `actual-monmon import`. Make sure that the Actual servers are running and that MoneyMoney is unlocked. By default, the importer will import 1 month worth of transactions. You can override this by passing the `--from` property, like so: `actual-monmon import --from=2024-01-01`.
6767

6868
The importer will not track previous imports, so if you wait more than one month between imports, you might need to manually specify the last import date. Running the importer twice in the same month is no problem, as duplicate transactions will automatically be detected and skipped.
6969

70-
**Bugs**
70+
## Advanced Configuration
7171

72-
If there are any bugs or issues, please file an issue.
72+
The following configuration options can optionally be added
73+
74+
### Ignore patterns
75+
76+
Ignore patterns allow you to specify payee names, comments, or purposes which should be ignored. *Note:* Currently, the strings are treated as is, meaning they are case-sensitive, and will be checked for inclusion, not exact matches.
77+
78+
```
79+
[import.ignorePatterns]
80+
commentPatterns = ["[actual-ignore]"]
81+
payeePatterns = []
82+
purposePatterns = []
83+
```
84+
85+
The above configuration would ignore all transactions that have a comment containing the string `[actual-ignore]`.
86+
87+
## Bugs
88+
89+
If you notice any bugs or issues, please file an issue.

bun.lockb

-81.5 KB
Binary file not shown.

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@actual-app/api": "^6.5.0",
3232
"chalk": "^5.3.0",
3333
"date-fns": "^3.1.0",
34-
"moneymoney": "^1.2.0",
34+
"moneymoney": "^1.2.1",
3535
"node-fetch": "^3.3.2",
3636
"openai": "^3.2.1",
3737
"toml": "^3.0.0",

src/utils/Importer.ts

+30-5
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,50 @@ class Importer {
138138
}) {
139139
const fromDate = from ?? subMonths(new Date(), 1);
140140

141-
let monMonTransactionsSinceFromDate = await getTransactions({
141+
let monMonTransactions = await getTransactions({
142142
from: fromDate,
143143
});
144144

145145
if (!this.config.import.importUncheckedTransactions) {
146-
monMonTransactionsSinceFromDate =
147-
monMonTransactionsSinceFromDate.filter((t) => t.booked);
146+
monMonTransactions = monMonTransactions.filter((t) => t.booked);
147+
}
148+
149+
if (this.config.import.ignorePatterns !== undefined) {
150+
const ignorePatterns = this.config.import.ignorePatterns;
151+
152+
monMonTransactions = monMonTransactions.filter((t) => {
153+
let isIgnored = (ignorePatterns.commentPatterns ?? []).some(
154+
(pattern) => t.comment?.includes(pattern)
155+
);
156+
157+
isIgnored ||= (ignorePatterns.payeePatterns ?? []).some(
158+
(pattern) => t.name.includes(pattern)
159+
);
160+
161+
isIgnored ||= (ignorePatterns.purposePatterns ?? []).some(
162+
(pattern) => t.purpose?.includes(pattern)
163+
);
164+
165+
if (isIgnored) {
166+
this.logger.debug(
167+
`Ignoring transaction ${t.id} (${t.name}) due to ignore patterns`
168+
);
169+
}
170+
171+
return !isIgnored;
172+
});
148173
}
149174

150175
this.logger.debug(
151176
`Found ${
152-
monMonTransactionsSinceFromDate.length
177+
monMonTransactions.length
153178
} total transactions in MoneyMoney since ${format(
154179
fromDate,
155180
DATE_FORMAT
156181
)}`
157182
);
158183

159-
const monMonTransactionMap = monMonTransactionsSinceFromDate.reduce(
184+
const monMonTransactionMap = monMonTransactions.reduce(
160185
(acc, transaction) => {
161186
if (!acc[transaction.accountUuid]) {
162187
acc[transaction.accountUuid] = [];

src/utils/config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export const configSchema = z
4040
}),
4141
import: z.object({
4242
importUncheckedTransactions: z.boolean(),
43+
ignorePatterns: z
44+
.object({
45+
commentPatterns: z.array(z.string()).optional(),
46+
payeePatterns: z.array(z.string()).optional(),
47+
purposePatterns: z.array(z.string()).optional(),
48+
})
49+
.optional(),
4350
}),
4451
actualServers: z.array(actualServerSchema).min(1),
4552
})

0 commit comments

Comments
 (0)