@bateikoed/monobank-mcp 0.0.0-stage → 0.1.3
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/CHANGELOG.md +37 -0
- package/LICENSE +21 -0
- package/README.md +240 -2
- package/README.uk.md +241 -0
- package/SECURITY.md +31 -0
- package/dist/config.js +81 -0
- package/dist/config.js.map +1 -0
- package/dist/data/currencies.js +203 -0
- package/dist/data/currencies.js.map +1 -0
- package/dist/data/mcc.js +336 -0
- package/dist/data/mcc.js.map +1 -0
- package/dist/domain/client-info.js +140 -0
- package/dist/domain/client-info.js.map +1 -0
- package/dist/domain/currency.js +67 -0
- package/dist/domain/currency.js.map +1 -0
- package/dist/domain/dates.js +167 -0
- package/dist/domain/dates.js.map +1 -0
- package/dist/domain/decimal.js +49 -0
- package/dist/domain/decimal.js.map +1 -0
- package/dist/domain/mcc.js +26 -0
- package/dist/domain/mcc.js.map +1 -0
- package/dist/domain/money.js +38 -0
- package/dist/domain/money.js.map +1 -0
- package/dist/domain/net-worth.js +183 -0
- package/dist/domain/net-worth.js.map +1 -0
- package/dist/domain/rates.js +139 -0
- package/dist/domain/rates.js.map +1 -0
- package/dist/domain/statement-range.js +53 -0
- package/dist/domain/statement-range.js.map +1 -0
- package/dist/domain/statement.js +225 -0
- package/dist/domain/statement.js.map +1 -0
- package/dist/domain/text.js +25 -0
- package/dist/domain/text.js.map +1 -0
- package/dist/errors.js +254 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle.js +29 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/limits.js +34 -0
- package/dist/limits.js.map +1 -0
- package/dist/logger.js +35 -0
- package/dist/logger.js.map +1 -0
- package/dist/monobank/cache.js +71 -0
- package/dist/monobank/cache.js.map +1 -0
- package/dist/monobank/client-info-schema.js +64 -0
- package/dist/monobank/client-info-schema.js.map +1 -0
- package/dist/monobank/client.js +391 -0
- package/dist/monobank/client.js.map +1 -0
- package/dist/monobank/endpoints.js +66 -0
- package/dist/monobank/endpoints.js.map +1 -0
- package/dist/monobank/http.js +110 -0
- package/dist/monobank/http.js.map +1 -0
- package/dist/monobank/rate-limiter.js +41 -0
- package/dist/monobank/rate-limiter.js.map +1 -0
- package/dist/monobank/schemas.js +39 -0
- package/dist/monobank/schemas.js.map +1 -0
- package/dist/monobank/statement-schema.js +51 -0
- package/dist/monobank/statement-schema.js.map +1 -0
- package/dist/server.js +32 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/define-tool.js +18 -0
- package/dist/tools/define-tool.js.map +1 -0
- package/dist/tools/get-client-info.js +38 -0
- package/dist/tools/get-client-info.js.map +1 -0
- package/dist/tools/get-currency-rates.js +30 -0
- package/dist/tools/get-currency-rates.js.map +1 -0
- package/dist/tools/get-net-worth.js +53 -0
- package/dist/tools/get-net-worth.js.map +1 -0
- package/dist/tools/get-statement.js +126 -0
- package/dist/tools/get-statement.js.map +1 -0
- package/dist/tools/register.js +11 -0
- package/dist/tools/register.js.map +1 -0
- package/package.json +64 -4
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { MalformedResponseError } from '../errors.js';
|
|
3
|
+
// D-15, D-16, locked resolution 2: only `accounts` and `jars` are read, and only the fields below
|
|
4
|
+
// survive. z.object strips unknown keys, so sendId, maskedPan, iban and every top-level field
|
|
5
|
+
// other than accounts and jars (clientId, name, webHookUrl, permissions and the accountant's
|
|
6
|
+
// managedClients with their TIN) never enter ClientInfo. TOOL-02's "masked sensitive fields" is
|
|
7
|
+
// met by omission, which is stricter (F-11).
|
|
8
|
+
// Safe integers only: a float, a string or a value beyond 2^53 fails the entry, so precision can
|
|
9
|
+
// never be lost silently.
|
|
10
|
+
const minor = z.int();
|
|
11
|
+
const currencyCode = z.int().min(0).max(9999);
|
|
12
|
+
// An opaque id can never carry markup or instructions into the output.
|
|
13
|
+
const opaqueId = z.string().regex(/^[A-Za-z0-9_-]{1,64}$/);
|
|
14
|
+
export const AccountSchema = z.object({
|
|
15
|
+
id: opaqueId,
|
|
16
|
+
balance: minor,
|
|
17
|
+
creditLimit: z.int().min(0).optional(),
|
|
18
|
+
currencyCode,
|
|
19
|
+
// Strings, not enums: the sets may grow, and they are sanitised before output.
|
|
20
|
+
type: z.string().optional(),
|
|
21
|
+
cashbackType: z.string().optional(),
|
|
22
|
+
});
|
|
23
|
+
export const JarSchema = z.object({
|
|
24
|
+
id: opaqueId,
|
|
25
|
+
balance: minor,
|
|
26
|
+
currencyCode,
|
|
27
|
+
title: z.string().optional(),
|
|
28
|
+
description: z.string().optional(),
|
|
29
|
+
goal: z.int().min(0).optional(),
|
|
30
|
+
});
|
|
31
|
+
function isPlainObject(value) {
|
|
32
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
function parseItems(items, schema) {
|
|
35
|
+
const kept = [];
|
|
36
|
+
let dropped = 0;
|
|
37
|
+
for (const item of items) {
|
|
38
|
+
const parsed = schema.safeParse(item);
|
|
39
|
+
if (parsed.success)
|
|
40
|
+
kept.push(parsed.data);
|
|
41
|
+
else
|
|
42
|
+
dropped += 1;
|
|
43
|
+
}
|
|
44
|
+
return { kept, dropped };
|
|
45
|
+
}
|
|
46
|
+
// Never puts item contents in a message: MalformedResponseError carries a constant text.
|
|
47
|
+
export function parseClientInfo(input) {
|
|
48
|
+
if (!isPlainObject(input))
|
|
49
|
+
throw new MalformedResponseError();
|
|
50
|
+
const rawAccounts = input.accounts;
|
|
51
|
+
if (!Array.isArray(rawAccounts))
|
|
52
|
+
throw new MalformedResponseError();
|
|
53
|
+
const rawJars = input.jars;
|
|
54
|
+
if (rawJars !== undefined && !Array.isArray(rawJars))
|
|
55
|
+
throw new MalformedResponseError();
|
|
56
|
+
const accounts = parseItems(rawAccounts, AccountSchema);
|
|
57
|
+
const jars = parseItems((rawJars ?? []), JarSchema);
|
|
58
|
+
return {
|
|
59
|
+
accounts: accounts.kept,
|
|
60
|
+
jars: jars.kept,
|
|
61
|
+
dropped: accounts.dropped + jars.dropped,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=client-info-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-info-schema.js","sourceRoot":"","sources":["../../src/monobank/client-info-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,kGAAkG;AAClG,8FAA8F;AAC9F,6FAA6F;AAC7F,gGAAgG;AAChG,6CAA6C;AAE7C,iGAAiG;AACjG,0BAA0B;AAC1B,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;AACtB,MAAM,YAAY,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC9C,uEAAuE;AACvE,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE,KAAK;IACd,WAAW,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACtC,YAAY;IACZ,+EAA+E;IAC/E,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACpC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE,KAAK;IACd,YAAY;IACZ,KAAK,EAAE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,CAAC;IACzF,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAwB,EAAE,aAAa,CAAC,CAAC;IACrE,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,OAAO,IAAI,EAAE,CAAc,EAAE,SAAS,CAAC,CAAC;IACjE,OAAO;QACL,QAAQ,EAAE,QAAQ,CAAC,IAAI;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO;KACzC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { AuthError, IpBlockedError, RateLimitedError, StatementRejectedError, UpstreamError, } from '../errors.js';
|
|
2
|
+
import { DOCUMENTED_LIMITS } from '../limits.js';
|
|
3
|
+
import { TtlCache } from './cache.js';
|
|
4
|
+
import { parseClientInfo } from './client-info-schema.js';
|
|
5
|
+
import { ENDPOINTS, IP_BLOCK_COOLDOWN_SECONDS, statementPath } from './endpoints.js';
|
|
6
|
+
import { getJson } from './http.js';
|
|
7
|
+
import { RateLimiter } from './rate-limiter.js';
|
|
8
|
+
import { parseRates } from './schemas.js';
|
|
9
|
+
import { parseStatement, } from './statement-schema.js';
|
|
10
|
+
// D-09, F8: this server's own memory bounds, not Monobank figures. Statement data stays in process
|
|
11
|
+
// memory only. Twenty pages and twenty boundary memos keep a long session from growing unbounded.
|
|
12
|
+
const STATEMENT_CACHE_MAX_ENTRIES = 20;
|
|
13
|
+
const BOUNDARY_MEMO_MAX_ENTRIES = 20;
|
|
14
|
+
// D-07: everything arrives by injection, so tests need no network (TEST-01).
|
|
15
|
+
export class MonobankClient {
|
|
16
|
+
#http;
|
|
17
|
+
#logger;
|
|
18
|
+
// D-15: holds only the validated public rates array, never anything token-bearing or personal.
|
|
19
|
+
#cache;
|
|
20
|
+
// D-19: one entry, shared by every tool that reads client info. Holds only the validated,
|
|
21
|
+
// PII-free ClientInfo.
|
|
22
|
+
#infoCache;
|
|
23
|
+
// D-09, F3: validated statement pages, keyed by account, from and to-or-'now'.
|
|
24
|
+
#statementCache;
|
|
25
|
+
// F8: bounded to BOUNDARY_MEMO_MAX_ENTRIES, oldest key evicted first, keyed `account|cursor`.
|
|
26
|
+
#boundary = new Map();
|
|
27
|
+
// F1: numeric currency of every account and jar, replaced from each successful client-info load.
|
|
28
|
+
// Ids and codes only, in memory, never logged.
|
|
29
|
+
#currencyById = new Map();
|
|
30
|
+
// D-18: one fail-fast limiter, one bucket per endpoint. Only the client-info loader uses it.
|
|
31
|
+
#limiter;
|
|
32
|
+
// A true private field: JSON.stringify and util.inspect cannot show it (T-03-03).
|
|
33
|
+
#token;
|
|
34
|
+
#now;
|
|
35
|
+
// D-11, D-12: local cooldowns, as epoch milliseconds. While one is active no request leaves
|
|
36
|
+
// this process, and nothing retries by itself (RELI-03).
|
|
37
|
+
#blockedUntil = 0;
|
|
38
|
+
#rateLimitedUntil = 0;
|
|
39
|
+
// F-10: when Monobank last rejected the token, as epoch milliseconds. A rejected token is reported
|
|
40
|
+
// again for one interval without a request, instead of a misleading "rate limited".
|
|
41
|
+
#authRejectedAt;
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.#http = {
|
|
44
|
+
fetch: options.fetch,
|
|
45
|
+
baseUrl: options.baseUrl,
|
|
46
|
+
timeoutMs: options.timeoutMs,
|
|
47
|
+
userAgent: options.userAgent,
|
|
48
|
+
};
|
|
49
|
+
this.#logger = options.logger;
|
|
50
|
+
this.#now = options.now;
|
|
51
|
+
this.#cache = new TtlCache(options.now);
|
|
52
|
+
this.#infoCache = new TtlCache(options.now);
|
|
53
|
+
this.#statementCache = new TtlCache(options.now, {
|
|
54
|
+
maxEntries: STATEMENT_CACHE_MAX_ENTRIES,
|
|
55
|
+
});
|
|
56
|
+
this.#limiter = new RateLimiter(options.now);
|
|
57
|
+
this.#token = options.token;
|
|
58
|
+
}
|
|
59
|
+
async getClientInfo() {
|
|
60
|
+
const endpoint = ENDPOINTS.clientInfo;
|
|
61
|
+
try {
|
|
62
|
+
const hit = await this.#infoCache.getOrLoad('client-info', endpoint.ttlSeconds * 1000, () => this.#loadClientInfo());
|
|
63
|
+
return { info: hit.value, ageSeconds: Math.floor(hit.ageMs / 1000), stale: false };
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
// D-19 extended by F-3: a labelled stale value only for a rate limit (local or upstream), an IP
|
|
67
|
+
// block, a 5xx and a network failure, and only within the stale cap. A malformed response, a
|
|
68
|
+
// rejected token and a missing token never fall back. Every joiner of a failed in-flight load
|
|
69
|
+
// lands here and gets the same answer.
|
|
70
|
+
if (err instanceof RateLimitedError ||
|
|
71
|
+
err instanceof IpBlockedError ||
|
|
72
|
+
err instanceof UpstreamError) {
|
|
73
|
+
const old = this.#infoCache.peek('client-info', endpoint.staleMaxSeconds * 1000);
|
|
74
|
+
if (old !== undefined) {
|
|
75
|
+
const reason = err instanceof RateLimitedError
|
|
76
|
+
? err.origin === 'local'
|
|
77
|
+
? 'limited-locally'
|
|
78
|
+
: 'rate-limited'
|
|
79
|
+
: err instanceof IpBlockedError
|
|
80
|
+
? 'ip-blocked'
|
|
81
|
+
: 'unavailable';
|
|
82
|
+
const ageSeconds = Math.floor(old.ageMs / 1000);
|
|
83
|
+
this.#logger.info(`serving stale client info (reason ${reason}, age ${String(ageSeconds)} s)`);
|
|
84
|
+
// Never written back to the cache: the next call after the window fetches afresh.
|
|
85
|
+
return {
|
|
86
|
+
info: old.value,
|
|
87
|
+
ageSeconds,
|
|
88
|
+
stale: true,
|
|
89
|
+
reason,
|
|
90
|
+
retryAfterSeconds: err instanceof UpstreamError ? undefined : err.retryAfterSeconds,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async getStatement(request) {
|
|
98
|
+
const endpoint = ENDPOINTS.statement;
|
|
99
|
+
const key = statementKey(request);
|
|
100
|
+
try {
|
|
101
|
+
const hit = await this.#statementCache.getOrLoad(key, endpoint.ttlSeconds * 1000, () => this.#loadStatement(request));
|
|
102
|
+
return { page: hit.value, ageSeconds: Math.floor(hit.ageMs / 1000), stale: false };
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
// D-09: a labelled stale page only for a rate limit (local or upstream), an IP block, a 5xx
|
|
106
|
+
// and a network failure, and only within the stale cap. A malformed response, a rejected
|
|
107
|
+
// token, a missing token and an HTTP 400 (StatementRejectedError is not an UpstreamError)
|
|
108
|
+
// never fall back. Every joiner of a failed in-flight load gets the same answer.
|
|
109
|
+
if (err instanceof RateLimitedError ||
|
|
110
|
+
err instanceof IpBlockedError ||
|
|
111
|
+
err instanceof UpstreamError) {
|
|
112
|
+
const old = this.#statementCache.peek(key, endpoint.staleMaxSeconds * 1000);
|
|
113
|
+
if (old !== undefined) {
|
|
114
|
+
const reason = err instanceof RateLimitedError
|
|
115
|
+
? err.origin === 'local'
|
|
116
|
+
? 'limited-locally'
|
|
117
|
+
: 'rate-limited'
|
|
118
|
+
: err instanceof IpBlockedError
|
|
119
|
+
? 'ip-blocked'
|
|
120
|
+
: 'unavailable';
|
|
121
|
+
const ageSeconds = Math.floor(old.ageMs / 1000);
|
|
122
|
+
this.#logger.info(`serving stale statement (reason ${reason}, age ${String(ageSeconds)} s)`);
|
|
123
|
+
// Never written back to the cache: the next call after the window fetches afresh.
|
|
124
|
+
return {
|
|
125
|
+
page: old.value,
|
|
126
|
+
ageSeconds,
|
|
127
|
+
stale: true,
|
|
128
|
+
reason,
|
|
129
|
+
retryAfterSeconds: err instanceof UpstreamError ? undefined : err.retryAfterSeconds,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// D-02: the ids client info currently lists, from the cached entry younger than the stale cap.
|
|
137
|
+
// Never loads, so it never spends a request or a limiter slot.
|
|
138
|
+
cachedAccountIds() {
|
|
139
|
+
const cached = this.#infoCache.peek('client-info', ENDPOINTS.clientInfo.staleMaxSeconds * 1000);
|
|
140
|
+
if (cached === undefined)
|
|
141
|
+
return undefined;
|
|
142
|
+
return new Set([...cached.value.accounts, ...cached.value.jars].map((entry) => entry.id));
|
|
143
|
+
}
|
|
144
|
+
// F1: answers from the memo of the last successful client-info load. Never loads.
|
|
145
|
+
accountCurrency(account) {
|
|
146
|
+
return this.#currencyById.get(account);
|
|
147
|
+
}
|
|
148
|
+
async getRates() {
|
|
149
|
+
const endpoint = ENDPOINTS.currency;
|
|
150
|
+
try {
|
|
151
|
+
const hit = await this.#cache.getOrLoad('rates', endpoint.ttlSeconds * 1000, () => this.#loadRates());
|
|
152
|
+
return { rates: hit.value, ageSeconds: Math.floor(hit.ageMs / 1000), stale: false };
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
// D-14: stale data only for the failures it names (429, 403 cooldown, 5xx, network). A
|
|
156
|
+
// MalformedResponseError means the pipeline cannot be trusted, so it never falls back.
|
|
157
|
+
// Every joiner of a failed in-flight load lands here and gets the same answer.
|
|
158
|
+
if (err instanceof RateLimitedError ||
|
|
159
|
+
err instanceof IpBlockedError ||
|
|
160
|
+
err instanceof UpstreamError) {
|
|
161
|
+
const old = this.#cache.peek('rates', endpoint.staleMaxSeconds * 1000);
|
|
162
|
+
if (old !== undefined) {
|
|
163
|
+
const reason = err instanceof RateLimitedError
|
|
164
|
+
? 'rate-limited'
|
|
165
|
+
: err instanceof IpBlockedError
|
|
166
|
+
? 'ip-blocked'
|
|
167
|
+
: 'unavailable';
|
|
168
|
+
const ageSeconds = Math.floor(old.ageMs / 1000);
|
|
169
|
+
this.#logger.info(`serving stale rates (reason ${reason}, age ${String(ageSeconds)} s)`);
|
|
170
|
+
// Never written back to the cache: the next call after the cooldown fetches afresh.
|
|
171
|
+
return {
|
|
172
|
+
rates: old.value,
|
|
173
|
+
ageSeconds,
|
|
174
|
+
stale: true,
|
|
175
|
+
reason,
|
|
176
|
+
retryAfterSeconds: err instanceof UpstreamError ? undefined : err.retryAfterSeconds,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
throw err;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async #loadRates() {
|
|
184
|
+
// The cooldown checks sit inside the loader, so a fresh cache hit is still served first.
|
|
185
|
+
const start = this.#now();
|
|
186
|
+
if (start < this.#blockedUntil) {
|
|
187
|
+
throw new IpBlockedError(Math.ceil((this.#blockedUntil - start) / 1000));
|
|
188
|
+
}
|
|
189
|
+
if (start < this.#rateLimitedUntil) {
|
|
190
|
+
throw new RateLimitedError(Math.ceil((this.#rateLimitedUntil - start) / 1000));
|
|
191
|
+
}
|
|
192
|
+
let body;
|
|
193
|
+
try {
|
|
194
|
+
body = await getJson(this.#http, ENDPOINTS.currency);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
if (err instanceof IpBlockedError) {
|
|
198
|
+
this.#blockedUntil = this.#now() + IP_BLOCK_COOLDOWN_SECONDS * 1000;
|
|
199
|
+
this.#logger.warn(`Monobank answered 403; no requests for ${String(IP_BLOCK_COOLDOWN_SECONDS)} s`);
|
|
200
|
+
}
|
|
201
|
+
else if (err instanceof RateLimitedError) {
|
|
202
|
+
this.#rateLimitedUntil = this.#now() + err.retryAfterSeconds * 1000;
|
|
203
|
+
this.#logger.warn(`Monobank answered 429; no requests for ${String(err.retryAfterSeconds)} s`);
|
|
204
|
+
}
|
|
205
|
+
throw err;
|
|
206
|
+
}
|
|
207
|
+
const { rates, dropped } = parseRates(body);
|
|
208
|
+
// Counts only: entry contents never reach the log.
|
|
209
|
+
if (dropped > 0) {
|
|
210
|
+
this.#logger.warn(`dropped ${String(dropped)} malformed entries from the currency response`);
|
|
211
|
+
}
|
|
212
|
+
this.#logger.info(`fetched ${String(rates.length)} currency pairs`);
|
|
213
|
+
return rates;
|
|
214
|
+
}
|
|
215
|
+
async #loadClientInfo() {
|
|
216
|
+
// The checks sit inside the loader, so a fresh cache hit is still served first. Order matters.
|
|
217
|
+
const endpoint = ENDPOINTS.clientInfo;
|
|
218
|
+
const intervalMs = endpoint.minIntervalSeconds * 1000;
|
|
219
|
+
const start = this.#now();
|
|
220
|
+
// F-10: a recently rejected token is reported again, with no request.
|
|
221
|
+
if (this.#authRejectedAt !== undefined &&
|
|
222
|
+
start >= this.#authRejectedAt &&
|
|
223
|
+
start - this.#authRejectedAt < intervalMs) {
|
|
224
|
+
throw new AuthError();
|
|
225
|
+
}
|
|
226
|
+
// F-4: an IP block is per IP, so the pause is shared with get_currency_rates.
|
|
227
|
+
if (start < this.#blockedUntil) {
|
|
228
|
+
throw new IpBlockedError(Math.ceil((this.#blockedUntil - start) / 1000));
|
|
229
|
+
}
|
|
230
|
+
// D-18, D-20: the limiter stamps the attempt before the request, so a failing upstream is asked
|
|
231
|
+
// at most once per interval. It throws a local RateLimitedError while the window is open.
|
|
232
|
+
this.#limiter.acquire(endpoint.bucket, intervalMs);
|
|
233
|
+
let body;
|
|
234
|
+
try {
|
|
235
|
+
body = await getJson(this.#http, endpoint, this.#token);
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
// Warn lines carry numbers and a reason word only, never a body or the token (T-03-07).
|
|
239
|
+
if (err instanceof RateLimitedError) {
|
|
240
|
+
// D-08: whether the 60 s window is shared with statements is unverified (A8), so a real 429
|
|
241
|
+
// pauses both personal buckets.
|
|
242
|
+
this.#limiter.cooldown(endpoint.bucket, err.retryAfterSeconds * 1000);
|
|
243
|
+
this.#limiter.cooldown(ENDPOINTS.statement.bucket, err.retryAfterSeconds * 1000);
|
|
244
|
+
this.#logger.warn(`Monobank answered 429 on client info; no personal request for ${String(err.retryAfterSeconds)} s`);
|
|
245
|
+
}
|
|
246
|
+
else if (err instanceof IpBlockedError) {
|
|
247
|
+
this.#blockedUntil = this.#now() + IP_BLOCK_COOLDOWN_SECONDS * 1000;
|
|
248
|
+
this.#logger.warn(`Monobank answered 403 on client info; no requests for ${String(IP_BLOCK_COOLDOWN_SECONDS)} s`);
|
|
249
|
+
}
|
|
250
|
+
else if (err instanceof AuthError) {
|
|
251
|
+
this.#authRejectedAt = this.#now();
|
|
252
|
+
this.#logger.warn(`Monobank rejected the token on client info; no client-info request for ${String(endpoint.minIntervalSeconds)} s`);
|
|
253
|
+
}
|
|
254
|
+
throw err;
|
|
255
|
+
}
|
|
256
|
+
const info = parseClientInfo(body);
|
|
257
|
+
// F1: replaced wholesale on every successful load, so a closed account does not linger.
|
|
258
|
+
this.#currencyById = new Map([...info.accounts, ...info.jars].map((entry) => [entry.id, entry.currencyCode]));
|
|
259
|
+
// Counts only: ids, balances, titles and bodies never reach the log.
|
|
260
|
+
if (info.dropped > 0) {
|
|
261
|
+
this.#logger.warn(`dropped ${String(info.dropped)} malformed entries from the client info`);
|
|
262
|
+
}
|
|
263
|
+
this.#logger.info(`fetched client info (${String(info.accounts.length)} accounts, ${String(info.jars.length)} jars)`);
|
|
264
|
+
return info;
|
|
265
|
+
}
|
|
266
|
+
async #loadStatement(request) {
|
|
267
|
+
// The checks sit inside the loader, so a fresh cache hit never consults them. Order matters.
|
|
268
|
+
const endpoint = ENDPOINTS.statement;
|
|
269
|
+
const intervalMs = endpoint.minIntervalSeconds * 1000;
|
|
270
|
+
const start = this.#now();
|
|
271
|
+
// A recently rejected token is reported again, with no request (shared with client info).
|
|
272
|
+
if (this.#authRejectedAt !== undefined &&
|
|
273
|
+
start >= this.#authRejectedAt &&
|
|
274
|
+
start - this.#authRejectedAt < intervalMs) {
|
|
275
|
+
throw new AuthError();
|
|
276
|
+
}
|
|
277
|
+
// An IP block is per IP, so the pause is shared with every other endpoint.
|
|
278
|
+
if (start < this.#blockedUntil) {
|
|
279
|
+
throw new IpBlockedError(Math.ceil((this.#blockedUntil - start) / 1000));
|
|
280
|
+
}
|
|
281
|
+
const openEnded = request.toSeconds === undefined;
|
|
282
|
+
const to = request.toSeconds ?? Math.floor(start / 1000);
|
|
283
|
+
// F4: the path is pure and can throw, so it is built and validated before the slot is taken. An
|
|
284
|
+
// invalid path never spends the one-per-60-seconds slot.
|
|
285
|
+
const path = statementPath(request.account, request.fromSeconds, to);
|
|
286
|
+
// D-10: the slot is taken synchronously, before the request is sent. Of two different requests
|
|
287
|
+
// started together the second is refused locally, which is what serializes them.
|
|
288
|
+
this.#limiter.acquire(ENDPOINTS.statement.bucket, intervalMs);
|
|
289
|
+
let body;
|
|
290
|
+
try {
|
|
291
|
+
body = await getJson(this.#http, { ...endpoint, path }, this.#token);
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
// Warn lines carry numbers and a reason word only, never a body, an id or the token.
|
|
295
|
+
if (err instanceof RateLimitedError) {
|
|
296
|
+
// D-08: a real 429 on either personal endpoint pauses both buckets. `cooldown` only ever
|
|
297
|
+
// extends a window, so the statement bucket keeps its own 60 s after a shorter Retry-After.
|
|
298
|
+
this.#limiter.cooldown(ENDPOINTS.statement.bucket, err.retryAfterSeconds * 1000);
|
|
299
|
+
this.#limiter.cooldown(ENDPOINTS.clientInfo.bucket, err.retryAfterSeconds * 1000);
|
|
300
|
+
this.#logger.warn(`Monobank answered 429 on statement; no personal request for ${String(err.retryAfterSeconds)} s`);
|
|
301
|
+
}
|
|
302
|
+
else if (err instanceof IpBlockedError) {
|
|
303
|
+
this.#blockedUntil = this.#now() + IP_BLOCK_COOLDOWN_SECONDS * 1000;
|
|
304
|
+
this.#logger.warn(`Monobank answered 403 on statement; no requests for ${String(IP_BLOCK_COOLDOWN_SECONDS)} s`);
|
|
305
|
+
}
|
|
306
|
+
else if (err instanceof AuthError) {
|
|
307
|
+
this.#authRejectedAt = this.#now();
|
|
308
|
+
this.#logger.warn(`Monobank rejected the token on statement; no personal request for ${String(endpoint.minIntervalSeconds)} s`);
|
|
309
|
+
}
|
|
310
|
+
else if (err instanceof UpstreamError && err.status === 400) {
|
|
311
|
+
// F4: the slot stays spent (the safe side) and the error is never served stale.
|
|
312
|
+
this.#logger.warn('Monobank rejected the statement request (HTTP 400)');
|
|
313
|
+
throw new StatementRejectedError();
|
|
314
|
+
}
|
|
315
|
+
throw err;
|
|
316
|
+
}
|
|
317
|
+
const parsed = parseStatement(body);
|
|
318
|
+
// F6: never trust upstream order. Array.prototype.sort is stable, so ties keep upstream order.
|
|
319
|
+
let items = [...parsed.items].sort((a, b) => b.time - a.time);
|
|
320
|
+
// F8, D-12: an explicit `to` that continues a truncated page may repeat the cursor second, so
|
|
321
|
+
// drop the ids remembered for it. With no usable memo the repeat risk is counted, not hidden.
|
|
322
|
+
let duplicatesDropped = 0;
|
|
323
|
+
let unmatchedBoundaryCount = 0;
|
|
324
|
+
if (!openEnded) {
|
|
325
|
+
const memo = this.#boundary.get(boundaryKey(request.account, to));
|
|
326
|
+
const usable = memo !== undefined && this.#now() - memo.storedAt < endpoint.staleMaxSeconds * 1000;
|
|
327
|
+
if (usable) {
|
|
328
|
+
const before = items.length;
|
|
329
|
+
items = items.filter((item) => !(item.time === to && memo.ids.has(item.id)));
|
|
330
|
+
duplicatesDropped = before - items.length;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
unmatchedBoundaryCount = items.filter((item) => item.time === to).length;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// D-11: truncated is decided on the raw count (a full page whose entries were dropped as
|
|
337
|
+
// malformed is still full). The cursor is the oldest returned time; when every item sits on the
|
|
338
|
+
// requested end second it steps back one second so the next call cannot repeat the same page.
|
|
339
|
+
// A cursor that cannot move past the range start means the range is complete.
|
|
340
|
+
const oldest = items.at(-1)?.time;
|
|
341
|
+
let nextTo;
|
|
342
|
+
if (parsed.rawCount >= DOCUMENTED_LIMITS.statement.maxItems && oldest !== undefined) {
|
|
343
|
+
const candidate = oldest === to ? to - 1 : oldest;
|
|
344
|
+
if (candidate > request.fromSeconds)
|
|
345
|
+
nextTo = candidate;
|
|
346
|
+
}
|
|
347
|
+
if (nextTo !== undefined)
|
|
348
|
+
this.#rememberBoundary(request.account, nextTo, items);
|
|
349
|
+
// Counts only: ids, times, texts and amounts never reach the log.
|
|
350
|
+
if (parsed.dropped > 0) {
|
|
351
|
+
this.#logger.warn(`dropped ${String(parsed.dropped)} malformed entries from the statement`);
|
|
352
|
+
}
|
|
353
|
+
this.#logger.info(`fetched statement (${String(items.length)} items, truncated ${nextTo === undefined ? 'no' : 'yes'})`);
|
|
354
|
+
return {
|
|
355
|
+
items,
|
|
356
|
+
rawCount: parsed.rawCount,
|
|
357
|
+
dropped: parsed.dropped,
|
|
358
|
+
duplicatesDropped,
|
|
359
|
+
unmatchedBoundaryCount,
|
|
360
|
+
fromSeconds: request.fromSeconds,
|
|
361
|
+
toSeconds: to,
|
|
362
|
+
openEnded,
|
|
363
|
+
truncated: nextTo !== undefined,
|
|
364
|
+
nextTo,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
// Delete then set moves a refreshed key to the end of the Map's insertion order, so the first key
|
|
368
|
+
// is always the oldest one and is the one evicted when the bound is passed.
|
|
369
|
+
#rememberBoundary(account, cursor, items) {
|
|
370
|
+
const key = boundaryKey(account, cursor);
|
|
371
|
+
const ids = new Set(items.filter((item) => item.time === cursor).map((item) => item.id));
|
|
372
|
+
this.#boundary.delete(key);
|
|
373
|
+
this.#boundary.set(key, { ids, storedAt: this.#now() });
|
|
374
|
+
while (this.#boundary.size > BOUNDARY_MEMO_MAX_ENTRIES) {
|
|
375
|
+
const oldest = this.#boundary.keys().next();
|
|
376
|
+
if (oldest.done === true)
|
|
377
|
+
break;
|
|
378
|
+
this.#boundary.delete(oldest.value);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function boundaryKey(account, to) {
|
|
383
|
+
return `${account}|${String(to)}`;
|
|
384
|
+
}
|
|
385
|
+
// F3: an open-ended request is keyed with the literal 'now', so "this week" asked twice is one
|
|
386
|
+
// request. Keying with the computed seconds would make every call a different key.
|
|
387
|
+
function statementKey(request) {
|
|
388
|
+
const to = request.toSeconds === undefined ? 'now' : String(request.toSeconds);
|
|
389
|
+
return `${request.account}|${String(request.fromSeconds)}|${to}`;
|
|
390
|
+
}
|
|
391
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/monobank/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,eAAe,EAAmB,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,OAAO,EAAiB,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAa,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,cAAc,GAMf,MAAM,uBAAuB,CAAC;AAE/B,mGAAmG;AACnG,kGAAkG;AAClG,MAAM,2BAA2B,GAAG,EAAE,CAAC;AACvC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAmErC,6EAA6E;AAC7E,MAAM,OAAO,cAAc;IAChB,KAAK,CAAW;IAChB,OAAO,CAAgC;IAChD,+FAA+F;IACtF,MAAM,CAA4B;IAC3C,0FAA0F;IAC1F,uBAAuB;IACd,UAAU,CAAuB;IAC1C,+EAA+E;IACtE,eAAe,CAA0B;IAClD,8FAA8F;IACrF,SAAS,GAAG,IAAI,GAAG,EAAwB,CAAC;IACrD,iGAAiG;IACjG,+CAA+C;IAC/C,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,6FAA6F;IACpF,QAAQ,CAAc;IAC/B,kFAAkF;IACzE,MAAM,CAAqB;IAC3B,IAA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GAAG,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/E,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// D-07, D-12, D-13: endpoint facts are data, so a limit or cooldown change needs no code edit.
|
|
2
|
+
// Domain code stays free of I/O: nothing here imports the SDK or reads the environment.
|
|
3
|
+
export const DEFAULT_BASE_URL = 'https://api.monobank.ua';
|
|
4
|
+
export const DEFAULT_TIMEOUT_MS = 10_000;
|
|
5
|
+
// Upper bound for one response body; consumed by the capped body reader (plan 02-04).
|
|
6
|
+
export const MAX_BODY_BYTES = 1_048_576;
|
|
7
|
+
// Community-reported (assumption A4): a Monobank IP block lasts about 24 h. Kept as data so it
|
|
8
|
+
// can change without code edits; consumed by plans 02-04 and 02-05.
|
|
9
|
+
export const IP_BLOCK_COOLDOWN_SECONDS = 86_400;
|
|
10
|
+
export const ENDPOINTS = {
|
|
11
|
+
// 300 s is Monobank's documented refresh cadence for public rates ("refreshed at most once per
|
|
12
|
+
// 5 minutes"), not a documented per-client request limit.
|
|
13
|
+
currency: {
|
|
14
|
+
path: '/bank/currency',
|
|
15
|
+
auth: false,
|
|
16
|
+
bucket: 'currency',
|
|
17
|
+
ttlSeconds: 300,
|
|
18
|
+
staleMaxSeconds: 3600,
|
|
19
|
+
minIntervalSeconds: 300,
|
|
20
|
+
forbidden: 'ip-block',
|
|
21
|
+
},
|
|
22
|
+
// The official OpenAPI (v250818) says client info may be called "not more often than once per
|
|
23
|
+
// 60 seconds". Whether that window is per endpoint, per token or shared with statements is
|
|
24
|
+
// unverified (assumption A8), which is why the limiter is keyed by `bucket`. 900 s is this
|
|
25
|
+
// server's own stale cap for personal data (D-19, discretion), not a Monobank figure.
|
|
26
|
+
clientInfo: {
|
|
27
|
+
path: '/personal/client-info',
|
|
28
|
+
auth: true,
|
|
29
|
+
bucket: 'client-info',
|
|
30
|
+
ttlSeconds: 60,
|
|
31
|
+
staleMaxSeconds: 900,
|
|
32
|
+
minIntervalSeconds: 60,
|
|
33
|
+
forbidden: 'auth',
|
|
34
|
+
},
|
|
35
|
+
// The official OpenAPI (v250818) says statements may be requested "not more often than once per
|
|
36
|
+
// 60 seconds". The TTL of 300 s and the stale cap of 900 s are this server's own choices (D-09),
|
|
37
|
+
// not Monobank figures. The bucket is separate from client info (D-08) because a shared one would
|
|
38
|
+
// block get_statement for 60 s after every get_client_info. Whether Monobank's real window is
|
|
39
|
+
// shared is unverified (assumption A8); switching is the one-line edit `bucket: 'client-info'`.
|
|
40
|
+
// `path` is the prefix only: the request path comes from statementPath().
|
|
41
|
+
statement: {
|
|
42
|
+
path: '/personal/statement',
|
|
43
|
+
auth: true,
|
|
44
|
+
bucket: 'statement',
|
|
45
|
+
ttlSeconds: 300,
|
|
46
|
+
staleMaxSeconds: 900,
|
|
47
|
+
minIntervalSeconds: 60,
|
|
48
|
+
forbidden: 'auth',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const STATEMENT_ACCOUNT_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
52
|
+
// T-04-04: only a regex-checked id and two safe non-negative integers are interpolated, so a
|
|
53
|
+
// slash, dot segment, query, fragment, space or control character can never reach the URL path and
|
|
54
|
+
// no encoding is needed. The message is constant and never echoes the input. An explicit `to` is
|
|
55
|
+
// always sent (research "Decision: always send an explicit to").
|
|
56
|
+
export function statementPath(account, fromSeconds, toSeconds) {
|
|
57
|
+
if (!STATEMENT_ACCOUNT_PATTERN.test(account) ||
|
|
58
|
+
!Number.isSafeInteger(fromSeconds) ||
|
|
59
|
+
fromSeconds < 0 ||
|
|
60
|
+
!Number.isSafeInteger(toSeconds) ||
|
|
61
|
+
toSeconds < 0) {
|
|
62
|
+
throw new RangeError('Invalid statement request parameters.');
|
|
63
|
+
}
|
|
64
|
+
return `${ENDPOINTS.statement.path}/${account}/${String(fromSeconds)}/${String(toSeconds)}`;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=endpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../src/monobank/endpoints.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,wFAAwF;AAExF,MAAM,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAC1D,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,sFAAsF;AACtF,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AACxC,+FAA+F;AAC/F,oEAAoE;AACpE,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAchD,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,+FAA+F;IAC/F,0DAA0D;IAC1D,QAAQ,EAAE;QACR,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,UAAU;QAClB,UAAU,EAAE,GAAG;QACf,eAAe,EAAE,IAAI;QACrB,kBAAkB,EAAE,GAAG;QACvB,SAAS,EAAE,UAAU;KACtB;IACD,8FAA8F;IAC9F,2FAA2F;IAC3F,2FAA2F;IAC3F,sFAAsF;IACtF,UAAU,EAAE;QACV,IAAI,EAAE,uBAAuB;QAC7B,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,aAAa;QACrB,UAAU,EAAE,EAAE;QACd,eAAe,EAAE,GAAG;QACpB,kBAAkB,EAAE,EAAE;QACtB,SAAS,EAAE,MAAM;KAClB;IACD,gGAAgG;IAChG,iGAAiG;IACjG,kGAAkG;IAClG,8FAA8F;IAC9F,gGAAgG;IAChG,0EAA0E;IAC1E,SAAS,EAAE;QACT,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,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