@rfc0/patty 1.2.0 → 1.2.2
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/config.js +8 -11
- package/dist/diplomat/db/schema.js +37 -14
- package/dist/diplomat/http/routes/users.js +1 -4
- package/dist/diplomat/mcp/register.js +10 -1
- package/dist/models/account.js +20 -18
- package/dist/models/credit-card.js +9 -9
- package/dist/models/currency-rate.js +16 -12
- package/dist/wire/db/change-events.js +1 -1
- package/dist/wire/in/cli.js +16 -6
- package/dist/wire/in/transactions.js +1 -1
- package/package.json +8 -8
package/dist/config.js
CHANGED
|
@@ -36,11 +36,8 @@ const unsetWhenEmpty = (value) => (value === '' ? undefined : value);
|
|
|
36
36
|
const optionalEnv = (schema) => z.preprocess(unsetWhenEmpty, schema.optional());
|
|
37
37
|
// The external origin only — it is compared verbatim against the browser's `Origin` header (CSRF) and
|
|
38
38
|
// decides the cookie `Secure` flag, so a path or trailing slash would make both silently wrong.
|
|
39
|
-
const PublicUrl = z
|
|
40
|
-
|
|
41
|
-
.url()
|
|
42
|
-
.refine((value) => /^https?:\/\//.test(value) && new URL(value).origin === value, {
|
|
43
|
-
message: 'PUBLIC_URL must be an http(s) origin with no path or trailing slash, e.g. https://patty.example.com',
|
|
39
|
+
const PublicUrl = z.url().refine((value) => /^https?:\/\//.test(value) && new URL(value).origin === value, {
|
|
40
|
+
error: 'PUBLIC_URL must be an http(s) origin with no path or trailing slash, e.g. https://patty.example.com',
|
|
44
41
|
});
|
|
45
42
|
// Fastify's `trustProxy`: `true`/`false`, or a comma-separated list of trusted addresses/CIDRs (anything else is
|
|
46
43
|
// passed through for Fastify (proxy-addr) to interpret). A hop count is refused: Fastify trusts nobody for one,
|
|
@@ -52,7 +49,7 @@ export const HOP_COUNT_REFUSED_MESSAGE = 'TRUST_PROXY cannot be a hop count: a c
|
|
|
52
49
|
const TrustProxy = z
|
|
53
50
|
.string()
|
|
54
51
|
.min(1)
|
|
55
|
-
.refine((value) => !HOP_COUNT.test(value) || value === NO_PROXY_HOPS, {
|
|
52
|
+
.refine((value) => !HOP_COUNT.test(value) || value === NO_PROXY_HOPS, { error: HOP_COUNT_REFUSED_MESSAGE })
|
|
56
53
|
.transform((value) => {
|
|
57
54
|
if (value === 'true')
|
|
58
55
|
return true;
|
|
@@ -66,7 +63,7 @@ const Env = z
|
|
|
66
63
|
DB_PATH: z
|
|
67
64
|
.string()
|
|
68
65
|
.refine(isAbsolute, {
|
|
69
|
-
|
|
66
|
+
error: `DB_PATH must be an absolute path — "~" is not expanded by Node. Use a full path, e.g. ${DEFAULT_DB_PATH}`,
|
|
70
67
|
})
|
|
71
68
|
.optional(),
|
|
72
69
|
PATTY_DB_KEY: EncryptionKey.optional(),
|
|
@@ -74,7 +71,7 @@ const Env = z
|
|
|
74
71
|
// `docker inspect`, unlike the env var (ADR-032).
|
|
75
72
|
PATTY_DB_KEY_FILE: z
|
|
76
73
|
.string()
|
|
77
|
-
.refine(isAbsolute, {
|
|
74
|
+
.refine(isAbsolute, { error: 'PATTY_DB_KEY_FILE must be an absolute path' })
|
|
78
75
|
.optional(),
|
|
79
76
|
PATTY_LOCALE: Locale.optional(),
|
|
80
77
|
PORT: z.coerce.number().default(DEFAULT_PORT),
|
|
@@ -111,11 +108,11 @@ const Env = z
|
|
|
111
108
|
})
|
|
112
109
|
.refine((env) => !(env.PATTY_DB_KEY && env.PATTY_DB_KEY_FILE), {
|
|
113
110
|
path: ['PATTY_DB_KEY_FILE'],
|
|
114
|
-
|
|
111
|
+
error: 'PATTY_DB_KEY and PATTY_DB_KEY_FILE are both set — the key source is ambiguous; set only one',
|
|
115
112
|
})
|
|
116
113
|
.refine((env) => !(env.PATTY_DEMO && (env.PATTY_DB_KEY || env.PATTY_DB_KEY_FILE)), {
|
|
117
114
|
path: [DEMO_ENV_VAR],
|
|
118
|
-
|
|
115
|
+
error: `${DEMO_ENV_VAR} fixes the database key — do not also set PATTY_DB_KEY or PATTY_DB_KEY_FILE`,
|
|
119
116
|
})
|
|
120
117
|
.transform((env) => ({
|
|
121
118
|
...env,
|
|
@@ -125,7 +122,7 @@ const Env = z
|
|
|
125
122
|
.transform((env) => env.PATTY_DEMO ? { ...env, PATTY_DB_KEY: DEMO_DB_KEY, PATTY_AUTH: AuthMode.enum.disabled } : env)
|
|
126
123
|
.refine((env) => !(env.PATTY_AUTH === AuthMode.enum.disabled && isExposed(env)), {
|
|
127
124
|
path: ['PATTY_AUTH'],
|
|
128
|
-
|
|
125
|
+
error: 'PATTY_AUTH=disabled is only allowed on a loopback HOST (127.0.0.0/8, ::1, localhost) with no PUBLIC_URL ' +
|
|
129
126
|
'or TRUST_PROXY — the API would be unauthenticated to everyone who can reach it (directly or through a ' +
|
|
130
127
|
'reverse proxy). Remove PATTY_AUTH (it defaults to required) or drop the exposure.',
|
|
131
128
|
});
|
|
@@ -11,6 +11,9 @@ import { DEFAULT_INSTANCE_KIND, InstanceKind } from '../../models/instance.js';
|
|
|
11
11
|
import { Locale, LocaleSource } from '../../models/locale.js';
|
|
12
12
|
import { RecurringPeriod } from '../../models/recurring.js';
|
|
13
13
|
import { ClassificationMethod, TransactionStatus } from '../../models/transaction.js';
|
|
14
|
+
// A zod 4 enum lists its members as `T[]`; drizzle wants a non-empty tuple. A zod enum is never empty, so this only
|
|
15
|
+
// tells the type system what the schema already guarantees.
|
|
16
|
+
const columnValues = (options) => options;
|
|
14
17
|
// Owned rows name their user (RESTRICT); shared defaults carry null.
|
|
15
18
|
const ownerColumn = () => text('user_id')
|
|
16
19
|
.notNull()
|
|
@@ -111,14 +114,16 @@ export const transactions = sqliteTable('transactions', {
|
|
|
111
114
|
description: text('description').notNull(),
|
|
112
115
|
amount: real('amount').notNull(),
|
|
113
116
|
type: text('type', { enum: ['income', 'expense', 'transfer'] }).notNull(),
|
|
114
|
-
status: text('status', { enum: TransactionStatus.options })
|
|
117
|
+
status: text('status', { enum: columnValues(TransactionStatus.options) })
|
|
118
|
+
.notNull()
|
|
119
|
+
.default(TransactionStatus.enum.effective),
|
|
115
120
|
date: text('date').notNull(),
|
|
116
121
|
currency: text('currency')
|
|
117
122
|
.notNull()
|
|
118
123
|
.references(() => currencies.code),
|
|
119
124
|
source: text('source', { enum: ['mcp', 'rest', 'import'] }).notNull(),
|
|
120
125
|
idempotencyKey: text('idempotency_key').notNull(),
|
|
121
|
-
classificationMethod: text('classification_method', { enum: ClassificationMethod.options }).notNull(),
|
|
126
|
+
classificationMethod: text('classification_method', { enum: columnValues(ClassificationMethod.options) }).notNull(),
|
|
122
127
|
confidence: real('confidence').notNull(),
|
|
123
128
|
rawInput: text('raw_input'),
|
|
124
129
|
fromAccountId: text('from_account_id').references(() => accounts.id),
|
|
@@ -155,7 +160,7 @@ export const recurringRules = sqliteTable('recurring_rules', {
|
|
|
155
160
|
description: text('description').notNull(),
|
|
156
161
|
amount: real('amount').notNull(),
|
|
157
162
|
type: text('type', { enum: ['income', 'expense'] }).notNull(),
|
|
158
|
-
period: text('period', { enum: RecurringPeriod.options }).notNull(),
|
|
163
|
+
period: text('period', { enum: columnValues(RecurringPeriod.options) }).notNull(),
|
|
159
164
|
nextDue: text('next_due').notNull(),
|
|
160
165
|
currency: text('currency')
|
|
161
166
|
.notNull()
|
|
@@ -172,7 +177,9 @@ export const dashboards = sqliteTable('dashboards', {
|
|
|
172
177
|
// Nullable — a source: 'file' row resolves content from `path` at read time instead
|
|
173
178
|
// (ADR-027 Phase 2); exactly one of html/path is non-null per source, enforced below.
|
|
174
179
|
html: text('html'),
|
|
175
|
-
source: text('source', { enum: DashboardSource.options })
|
|
180
|
+
source: text('source', { enum: columnValues(DashboardSource.options) })
|
|
181
|
+
.notNull()
|
|
182
|
+
.default(DashboardSource.enum.inline),
|
|
176
183
|
path: text('path'),
|
|
177
184
|
updatedAt: text('updated_at').notNull(),
|
|
178
185
|
version: integer('version').notNull().default(0),
|
|
@@ -199,7 +206,9 @@ export const budgets = sqliteTable('budgets', {
|
|
|
199
206
|
.notNull()
|
|
200
207
|
.references(() => currencies.code),
|
|
201
208
|
limitAmount: real('limit_amount').notNull(),
|
|
202
|
-
period: text('period', { enum: BudgetPeriod.options })
|
|
209
|
+
period: text('period', { enum: columnValues(BudgetPeriod.options) })
|
|
210
|
+
.notNull()
|
|
211
|
+
.default(BudgetPeriod.enum.monthly),
|
|
203
212
|
version: integer('version').notNull().default(0),
|
|
204
213
|
userId: ownerColumn(),
|
|
205
214
|
}, (t) => [uniqueIndex('budgets_user_category_currency_period').on(t.userId, t.categoryId, t.currency, t.period)]);
|
|
@@ -209,10 +218,14 @@ export const budgets = sqliteTable('budgets', {
|
|
|
209
218
|
// `demo_country` is the data set it seeded (null off the demo, and on a demo seeded before it was recorded).
|
|
210
219
|
export const settings = sqliteTable('settings', {
|
|
211
220
|
id: text('id').primaryKey().default('singleton'),
|
|
212
|
-
maxSignInDuration: text('max_sign_in_duration', { enum: SignInCap.options })
|
|
213
|
-
|
|
221
|
+
maxSignInDuration: text('max_sign_in_duration', { enum: columnValues(SignInCap.options) })
|
|
222
|
+
.notNull()
|
|
223
|
+
.default(DEFAULT_SIGN_IN_CAP),
|
|
224
|
+
instanceKind: text('instance_kind', { enum: columnValues(InstanceKind.options) })
|
|
225
|
+
.notNull()
|
|
226
|
+
.default(DEFAULT_INSTANCE_KIND),
|
|
214
227
|
demoSeededAt: text('demo_seeded_at'),
|
|
215
|
-
demoCountry: text('demo_country', { enum: DemoCountry.options }),
|
|
228
|
+
demoCountry: text('demo_country', { enum: columnValues(DemoCountry.options) }),
|
|
216
229
|
version: integer('version').notNull().default(0),
|
|
217
230
|
});
|
|
218
231
|
// One row per user; none means the defaults apply.
|
|
@@ -220,8 +233,12 @@ export const userSettings = sqliteTable('user_settings', {
|
|
|
220
233
|
userId: text('user_id')
|
|
221
234
|
.primaryKey()
|
|
222
235
|
.references(() => users.id, { onDelete: 'cascade' }),
|
|
223
|
-
locale: text('locale', { enum: Locale.options })
|
|
224
|
-
|
|
236
|
+
locale: text('locale', { enum: columnValues(Locale.options) })
|
|
237
|
+
.notNull()
|
|
238
|
+
.default(Locale.enum.en),
|
|
239
|
+
localeSource: text('locale_source', { enum: columnValues(LocaleSource.options) })
|
|
240
|
+
.notNull()
|
|
241
|
+
.default(LocaleSource.enum.default),
|
|
225
242
|
// Nullable — unset means "derive from locale" (pt->BRL, en/es->USD), resolved at read time by
|
|
226
243
|
// logic/locale.ts's resolveBaseCurrency (ADR-026 Phase 2); no DB default, unlike locale/localeSource,
|
|
227
244
|
// since there is no third "explicit vs inferred" source to track here.
|
|
@@ -251,7 +268,7 @@ export const users = sqliteTable('users', {
|
|
|
251
268
|
id: text('id').primaryKey(),
|
|
252
269
|
username: text('username').unique(),
|
|
253
270
|
passwordHash: text('password_hash'),
|
|
254
|
-
role: text('role', { enum: UserRole.options }).notNull(),
|
|
271
|
+
role: text('role', { enum: columnValues(UserRole.options) }).notNull(),
|
|
255
272
|
createdAt: text('created_at').notNull(),
|
|
256
273
|
disabledAt: text('disabled_at'),
|
|
257
274
|
lastLoginAt: text('last_login_at'),
|
|
@@ -298,7 +315,9 @@ export const accessTokens = sqliteTable('access_tokens', {
|
|
|
298
315
|
userId: text('user_id')
|
|
299
316
|
.notNull()
|
|
300
317
|
.references(() => users.id, { onDelete: 'cascade' }),
|
|
301
|
-
kind: text('kind', { enum: AccessTokenKind.options })
|
|
318
|
+
kind: text('kind', { enum: columnValues(AccessTokenKind.options) })
|
|
319
|
+
.notNull()
|
|
320
|
+
.default(AccessTokenKind.enum.pat),
|
|
302
321
|
clientName: text('client_name'),
|
|
303
322
|
profile: text('profile'),
|
|
304
323
|
name: text('name').notNull(),
|
|
@@ -329,10 +348,14 @@ export const clientGrants = sqliteTable('client_grants', {
|
|
|
329
348
|
clientName: text('client_name').notNull(),
|
|
330
349
|
clientVersion: text('client_version').notNull(),
|
|
331
350
|
profile: text('profile').notNull(),
|
|
332
|
-
channel: text('channel', { enum: GrantChannel.options })
|
|
351
|
+
channel: text('channel', { enum: columnValues(GrantChannel.options) })
|
|
352
|
+
.notNull()
|
|
353
|
+
.default(GrantChannel.enum.stdio),
|
|
333
354
|
hintAccess: text('hint_access').$type(),
|
|
334
355
|
hintDuration: text('hint_duration').$type(),
|
|
335
|
-
status: text('status', { enum: GrantStatus.options })
|
|
356
|
+
status: text('status', { enum: columnValues(GrantStatus.options) })
|
|
357
|
+
.notNull()
|
|
358
|
+
.default(GrantStatus.enum.pending),
|
|
336
359
|
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }),
|
|
337
360
|
scopes: text('scopes', { mode: 'json' }).$type(),
|
|
338
361
|
duration: text('duration').$type(),
|
|
@@ -69,10 +69,7 @@ const showInvited = (pages, heading) => async (issued, req, reply) => {
|
|
|
69
69
|
return page(reply, 200, await renderInvitedPage({ heading, issued, link }));
|
|
70
70
|
};
|
|
71
71
|
const redirectToUsers = (_value, _req, reply) => reply.redirect(USERS_PATH, SEE_OTHER);
|
|
72
|
-
const NO_PARAMS = z
|
|
73
|
-
.object({})
|
|
74
|
-
.strip()
|
|
75
|
-
.transform(() => ({}));
|
|
72
|
+
const NO_PARAMS = z.object({}).transform(() => ({}));
|
|
76
73
|
/**
|
|
77
74
|
* One state-changing admin action: decode the path parameters and the form, run the flow as the typed-password actor
|
|
78
75
|
* through the throttled `attemptAs`, then render the success or the refusal on the users page. Every action that
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import { isEmpty } from 'remeda';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* A tool's arguments are advertised as a closed object (`additionalProperties: false`) while an unknown argument is
|
|
5
|
+
* still dropped, not rejected — what the surface said before zod 4, which only writes that keyword for a strict
|
|
6
|
+
* object. `.meta` adds it to the generated JSON Schema without making the decoding strict. A tool with no
|
|
7
|
+
* arguments never carried the keyword, and still does not.
|
|
8
|
+
*/
|
|
9
|
+
const toolInputSchema = (shape) => isEmpty(shape) ? z.object(shape) : z.object(shape).meta({ additionalProperties: false });
|
|
1
10
|
/**
|
|
2
11
|
* The one registrar (ADR-025): registers any list of definitions on `server`. `server.registerTool/Resource/Prompt`
|
|
3
12
|
* are the scope-guarded ones (`guardScopes`), so a definition cannot be registered around the guard; each callback asks
|
|
@@ -8,5 +17,5 @@ export const registerDefinitions = (server, ctx, definitions) => {
|
|
|
8
17
|
? server.registerPrompt(name, { ...config, argsSchema: config.argsSchema }, (args, extra) => handle(args, ctx.as(extra), ctx))
|
|
9
18
|
: server.registerPrompt(name, config, (extra) => handle({}, ctx.as(extra), ctx)));
|
|
10
19
|
definitions.resources.forEach(({ name, uri, config, read }) => server.registerResource(name, uri, config, (resourceUri, extra) => read(resourceUri, ctx.as(extra), ctx)));
|
|
11
|
-
definitions.tools.forEach(({ name, config, handle }) => server.registerTool(name, config, (args, extra) => handle(args, ctx.as(extra), ctx)));
|
|
20
|
+
definitions.tools.forEach(({ name, config, handle }) => server.registerTool(name, { ...config, inputSchema: toolInputSchema(config.inputSchema) }, (args, extra) => handle(args, ctx.as(extra), ctx)));
|
|
12
21
|
};
|
package/dist/models/account.js
CHANGED
|
@@ -19,13 +19,14 @@ export const accountTypeLabels = {
|
|
|
19
19
|
// Defaults split by intent: integrity defaults (a value that must exist for the entity to be
|
|
20
20
|
// valid, e.g. initialBalance → 0) live here; quality-of-life convenience defaults live at the
|
|
21
21
|
// wire boundary (see wire/in/accounts.ts), keeping the domain contract honest about what is required.
|
|
22
|
+
const INITIAL_BALANCE_DESCRIPTION = 'Balance at account creation; current balance is always derived';
|
|
22
23
|
export const AccountSchema = z.object({
|
|
23
24
|
id: Id,
|
|
24
25
|
name: z.string().min(1).describe('Account name'),
|
|
25
26
|
type: AccountType.describe('checking | savings | wallet | investment (credit is card-managed)'),
|
|
26
27
|
typeLabel: z.string().optional(),
|
|
27
28
|
currency: CurrencyCode.describe('Account currency (ISO code); fixed once the account has activity'),
|
|
28
|
-
initialBalance: z.number().default(0).describe(
|
|
29
|
+
initialBalance: z.number().default(0).describe(INITIAL_BALANCE_DESCRIPTION),
|
|
29
30
|
});
|
|
30
31
|
// The persistence-side entity (docs/canonical/functional-core-imperative-shell.md): `Account` plus
|
|
31
32
|
// the optimistic-concurrency `version` token. Never sent over the wire — kept off `AccountSchema`
|
|
@@ -41,8 +42,13 @@ export const AccountEntitySchema = withPersistenceMeta(AccountSchema);
|
|
|
41
42
|
export const ACCOUNT_ENTITY_TAG = 'account';
|
|
42
43
|
export const CreateAccountSchema = AccountSchema.omit({ id: true, typeLabel: true });
|
|
43
44
|
export const UpdateAccountSchema = AccountSchema.omit({ id: true, typeLabel: true })
|
|
44
|
-
.partial({
|
|
45
|
-
|
|
45
|
+
.partial({ type: true, currency: true })
|
|
46
|
+
// zod 4 applies a default inside `.partial()`, so an update that omits the balance would reset it to 0:
|
|
47
|
+
// the balance is restated as plainly optional (an omitted field means "leave it as it is").
|
|
48
|
+
.extend({
|
|
49
|
+
initialBalance: z.number().optional().describe(INITIAL_BALANCE_DESCRIPTION),
|
|
50
|
+
newName: z.string().min(1).optional().describe('New account name'),
|
|
51
|
+
});
|
|
46
52
|
export const AccountBalanceSchema = AccountSchema.extend({
|
|
47
53
|
balance: z.number(),
|
|
48
54
|
income: z.number(),
|
|
@@ -69,27 +75,25 @@ export const AccountBalancesResultSchema = z.object({
|
|
|
69
75
|
* vocabulary never reaches this schema at all, since the core no longer carries it). `account`
|
|
70
76
|
* stays optional: an omitted account records an unattached (e.g. cash) movement. Depends on the
|
|
71
77
|
* transaction core's schema (aggregate → core, the allowed direction) — never the reverse.
|
|
72
|
-
*
|
|
78
|
+
* `z.strictObject`: `card`/`type`/`billMonth`/`billYear` are meaningful fields on the sibling aggregate
|
|
73
79
|
* schema (`AddCardPurchaseSchema`), not server-managed ones — a caller who mistakenly sends them
|
|
74
80
|
* here should get a validation error, not have them silently stripped by zod's default unknown-key
|
|
75
81
|
* behavior (REST boundary only; the MCP tool's inputSchema is a raw shape, which the MCP SDK
|
|
76
82
|
* reconstructs into its own non-strict object internally). */
|
|
77
|
-
export const AddAccountMovementSchema = CreateTransactionSchema.extend({
|
|
83
|
+
export const AddAccountMovementSchema = z.strictObject(CreateTransactionSchema.extend({
|
|
78
84
|
account: z.string().min(1).optional().describe('Account name, e.g. "Nubank"'),
|
|
79
|
-
})
|
|
80
|
-
.omit({ type: true })
|
|
81
|
-
.strict();
|
|
85
|
+
}).omit({ type: true }).shape);
|
|
82
86
|
/** A single line of an `import_account_statement` request: the transaction core's minimal
|
|
83
87
|
* `CreateTransactionSchema` minus `rawInput`/`subCategory`/`tags` (statement-level concerns) — no
|
|
84
88
|
* `account` (fixed once, at the statement's top level — single-source, no per-line account) and no
|
|
85
89
|
* `card`/`billMonth`/`billYear` (card/bill-assignment vocabulary the core never carries). Unlike
|
|
86
90
|
* `AddAccountMovementSchema`, `type` stays required — a statement line still needs its own
|
|
87
91
|
* expense-vs-income marker, since the movement kind isn't fixed by which tool was called. */
|
|
88
|
-
export const ImportAccountStatementItemSchema = CreateTransactionSchema.omit({
|
|
92
|
+
export const ImportAccountStatementItemSchema = z.strictObject(CreateTransactionSchema.omit({
|
|
89
93
|
rawInput: true,
|
|
90
94
|
subCategory: true,
|
|
91
95
|
tags: true,
|
|
92
|
-
}).
|
|
96
|
+
}).shape);
|
|
93
97
|
/** Account statement import: single-source — every item is an expense or income (per item's
|
|
94
98
|
* `type`) on the ONE account named here (omit for unattached, e.g. cash, movements), via
|
|
95
99
|
* `addAccountExpense`/`addAccountIncome`. A statement can't carry a conflicting per-line owner
|
|
@@ -106,16 +110,15 @@ export const ImportAccountStatementSchema = z.object({
|
|
|
106
110
|
/** Account-aggregate update schema: `.extend`s the core's minimal `UpdateTransactionSchema` with
|
|
107
111
|
* `account` — the core no longer carries bill-assignment (`billMonth`/`billYear`) at all, so it
|
|
108
112
|
* structurally can't reach this schema (mirrors `AddAccountMovementSchema`'s create-side shape).
|
|
109
|
-
*
|
|
110
|
-
export const UpdateAccountTransactionSchema = UpdateTransactionSchema.extend({
|
|
113
|
+
* `z.strictObject`: same REST-boundary-only reasoning as `AddAccountMovementSchema` above. */
|
|
114
|
+
export const UpdateAccountTransactionSchema = z.strictObject(UpdateTransactionSchema.extend({
|
|
111
115
|
account: z.string().min(1).optional().describe('New account name'),
|
|
112
|
-
}).
|
|
116
|
+
}).shape);
|
|
113
117
|
/** Natural input for a transfer: account-context vocabulary — a transfer request is an
|
|
114
118
|
* account-aggregate concern even though it persists as a transaction row via the shared core
|
|
115
|
-
* primitive (account → core, the allowed direction).
|
|
119
|
+
* primitive (account → core, the allowed direction). `z.strictObject`: same REST-boundary-only
|
|
116
120
|
* reasoning as `AddAccountMovementSchema` above. */
|
|
117
|
-
export const CreateTransferSchema = z
|
|
118
|
-
.object({
|
|
121
|
+
export const CreateTransferSchema = z.strictObject(z.object({
|
|
119
122
|
from: z.string().min(1).describe('Source account name'),
|
|
120
123
|
to: z.string().min(1).describe('Destination account name'),
|
|
121
124
|
amount: Money.describe('Transfer amount in full units'),
|
|
@@ -123,8 +126,7 @@ export const CreateTransferSchema = z
|
|
|
123
126
|
date: IsoDate.optional().describe('YYYY-MM-DD; defaults to today'),
|
|
124
127
|
description: z.string().optional().describe('e.g. "aporte mensal"'),
|
|
125
128
|
discriminator: z.string().min(1).optional().describe(DISCRIMINATOR_DESCRIPTION),
|
|
126
|
-
})
|
|
127
|
-
.strict();
|
|
129
|
+
}).shape);
|
|
128
130
|
const CREDIT_REJECTED_MESSAGE = 'credit accounts are managed by their credit card — use the card flow instead';
|
|
129
131
|
const creditTransferFromMessage = (name) => `cannot transfer from a credit account (${name}) — pay the card's bill instead`;
|
|
130
132
|
const creditTransferToMessage = (name) => `cannot transfer to a credit account (${name}) — pay the card's bill instead`;
|
|
@@ -62,32 +62,32 @@ export const UpdateCreditCardSchema = CreditCardSchema.omit({
|
|
|
62
62
|
* `CreateTransactionSchema` (ADR-019) plus `card` (required — the card's own internal liability
|
|
63
63
|
* account is always the destination) and bill-assignment (`billMonth`/`billYear`) — both are
|
|
64
64
|
* credit-card-only vocabulary the core no longer carries. Depends on the transaction core's schema
|
|
65
|
-
* (aggregate → core, the allowed direction) — never the reverse.
|
|
65
|
+
* (aggregate → core, the allowed direction) — never the reverse. `z.strictObject`: `account` is a
|
|
66
66
|
* meaningful field on the sibling aggregate schema (`AddAccountMovementSchema`), not a
|
|
67
67
|
* server-managed one — a caller who mistakenly sends it here should get a validation error, not
|
|
68
68
|
* have it silently stripped by zod's default unknown-key behavior (REST boundary only; the MCP
|
|
69
69
|
* tool's inputSchema is a raw shape, which the MCP SDK reconstructs into its own non-strict object
|
|
70
70
|
* internally). */
|
|
71
|
-
export const AddCardPurchaseSchema = CreateTransactionSchema.extend({
|
|
71
|
+
export const AddCardPurchaseSchema = z.strictObject(CreateTransactionSchema.extend({
|
|
72
72
|
card: z.string().min(1).describe('Credit card name — joins the cycle bill'),
|
|
73
73
|
billMonth: BillQuerySchema.shape.month
|
|
74
74
|
.optional()
|
|
75
75
|
.describe('Explicit target bill cycle month (1-12) for a card transaction; overrides cycle-based auto-assignment. ' +
|
|
76
76
|
'Provide with billYear together; requires card. Auto-creates the bill if that cycle has none yet'),
|
|
77
77
|
billYear: BillQuerySchema.shape.year.optional().describe('Explicit target bill cycle year; provide with billMonth'),
|
|
78
|
-
}).
|
|
78
|
+
}).shape);
|
|
79
79
|
/** A single line of an `import_card_statement` request (ADR-017 step 2): same shape as
|
|
80
80
|
* `AddCardPurchaseSchema` minus `card` (fixed once, at the statement's top level — single-source,
|
|
81
81
|
* no per-line card) and minus `rawInput`/`subCategory`/`tags` (statement-level concerns: `rawInput`
|
|
82
82
|
* belongs to the whole pasted statement, and bulk import classifies automatically rather than
|
|
83
83
|
* taking a sub-category or tags per line — the same reduced shape the retired god bulk item
|
|
84
84
|
* carried). */
|
|
85
|
-
export const ImportCardStatementItemSchema = AddCardPurchaseSchema.omit({
|
|
85
|
+
export const ImportCardStatementItemSchema = z.strictObject(AddCardPurchaseSchema.omit({
|
|
86
86
|
card: true,
|
|
87
87
|
rawInput: true,
|
|
88
88
|
subCategory: true,
|
|
89
89
|
tags: true,
|
|
90
|
-
}).
|
|
90
|
+
}).shape);
|
|
91
91
|
/** Credit-card statement import (ADR-017 step 2): single-source — every item is a purchase on the
|
|
92
92
|
* ONE card named here, joining each line's own cycle bill via `addCardPurchase`. Replaces the god
|
|
93
93
|
* `create_transactions_bulk`'s per-line card routing entirely (a statement can't carry a
|
|
@@ -100,10 +100,10 @@ export const ImportCardStatementSchema = z.object({
|
|
|
100
100
|
/** Card-aggregate update schema (ADR-017/ADR-019): `.extend`s the core's minimal
|
|
101
101
|
* `UpdateTransactionSchema` with `account` — kept reachable (not omitted) so it can be explicitly
|
|
102
102
|
* rejected with a helpful message (`cardErrors.accountChangeRejectedForCard`) rather than a generic
|
|
103
|
-
*
|
|
104
|
-
* vocabulary.
|
|
103
|
+
* `z.strictObject` unrecognized-key error — and `billMonth`/`billYear`, genuine card-only reassignment
|
|
104
|
+
* vocabulary. `z.strictObject` still rejects truly foreign fields at the REST boundary (MCP tool args
|
|
105
105
|
* are reconstructed as a non-strict shape by the SDK). */
|
|
106
|
-
export const UpdateCardTransactionSchema = UpdateTransactionSchema.extend({
|
|
106
|
+
export const UpdateCardTransactionSchema = z.strictObject(UpdateTransactionSchema.extend({
|
|
107
107
|
account: z
|
|
108
108
|
.string()
|
|
109
109
|
.min(1)
|
|
@@ -119,7 +119,7 @@ export const UpdateCardTransactionSchema = UpdateTransactionSchema.extend({
|
|
|
119
119
|
billYear: BillQuerySchema.shape.year
|
|
120
120
|
.optional()
|
|
121
121
|
.describe('Reassignment target bill cycle year; provide with billMonth'),
|
|
122
|
-
}).
|
|
122
|
+
}).shape);
|
|
123
123
|
/** `deleteCreditCard`'s dry-run response (`controllers/credit-card/credit-card.ts`) — named so the
|
|
124
124
|
* string can't drift between the response and its own test's assertion, matching
|
|
125
125
|
* `DELETE_TRANSACTION_CONFIRM_HINT` (`models/transaction.ts`)'s reason for existing. */
|
|
@@ -4,13 +4,24 @@ import { CurrencyCode } from './money.js';
|
|
|
4
4
|
import { withPersistenceMeta } from '@rfc0/effect-runner';
|
|
5
5
|
// Entity tag for this aggregate's `Persistable`s.
|
|
6
6
|
export const CURRENCY_RATE_ENTITY_TAG = 'currency_rate';
|
|
7
|
+
const strictTimestamp = z.iso.datetime({ offset: true });
|
|
8
|
+
const COMPACT_OFFSET = /([+-]\d{2})(\d{2})?$/;
|
|
9
|
+
/** An ISO 8601 timestamp with an offset. zod 3 also accepted the compact offsets `+0200` and `+02`, and rates stored
|
|
10
|
+
* with them are reparsed on every read, so they stay valid (ADR-037 §3: no behavior change): the offset is only
|
|
11
|
+
* normalized to `+02:00` for the check, the value itself is never rewritten. */
|
|
12
|
+
export const IsoTimestamp = z
|
|
13
|
+
.string()
|
|
14
|
+
.meta({ format: 'date-time' })
|
|
15
|
+
.refine((text) => strictTimestamp.safeParse(text.replace(COMPACT_OFFSET, (_, hours, minutes) => `${hours}:${minutes ?? '00'}`)).success, {
|
|
16
|
+
error: 'Invalid datetime',
|
|
17
|
+
});
|
|
7
18
|
/** Agent/scheduler-supplied external data (ADR-026 Phase 2) — decoded at the boundary like any
|
|
8
19
|
* other input, never treated as authoritative beyond its own `asOf`. */
|
|
9
20
|
export const SetExchangeRateSchema = z.object({
|
|
10
21
|
from: CurrencyCode.describe('Base currency — 1 unit of this equals `rate` units of `to`'),
|
|
11
22
|
to: CurrencyCode.describe('Quote currency — the unit `rate` is expressed in'),
|
|
12
23
|
rate: z.number().positive().describe('1 unit of `from` = `rate` units of `to`, as of `asOf`'),
|
|
13
|
-
asOf:
|
|
24
|
+
asOf: IsoTimestamp.describe('ISO 8601 timestamp this rate was observed/sourced'),
|
|
14
25
|
source: z.string().min(1).optional().describe('Free-text provenance, e.g. "PTAX", "coingecko"'),
|
|
15
26
|
});
|
|
16
27
|
/** `from`/`to` are this module's own vocabulary for the `from_code`/`to_code` columns —
|
|
@@ -20,10 +31,7 @@ export const CurrencyRateSchema = z.object({
|
|
|
20
31
|
fromCode: CurrencyCode.describe('Base currency — 1 unit of this equals `rate` units of toCode'),
|
|
21
32
|
toCode: CurrencyCode.describe('Quote currency — the unit `rate` is expressed in'),
|
|
22
33
|
rate: z.number().positive().describe('1 unit of fromCode = `rate` units of toCode, as of `asOf`'),
|
|
23
|
-
asOf:
|
|
24
|
-
.string()
|
|
25
|
-
.datetime({ offset: true })
|
|
26
|
-
.describe('ISO 8601 timestamp this rate was observed/sourced (agent-supplied)'),
|
|
34
|
+
asOf: IsoTimestamp.describe('ISO 8601 timestamp this rate was observed/sourced (agent-supplied)'),
|
|
27
35
|
source: z
|
|
28
36
|
.string()
|
|
29
37
|
.min(1)
|
|
@@ -39,7 +47,7 @@ export const CurrencyRateViewSchema = z.object({
|
|
|
39
47
|
from: CurrencyCode.describe('Base currency'),
|
|
40
48
|
to: CurrencyCode.describe('Quote currency'),
|
|
41
49
|
rate: z.number().positive().describe('1 unit of `from` = `rate` units of `to`, as of `asOf`'),
|
|
42
|
-
asOf:
|
|
50
|
+
asOf: IsoTimestamp.describe('ISO 8601 timestamp this rate was observed/sourced'),
|
|
43
51
|
source: z.string().min(1).optional().describe('Free-text provenance, e.g. "PTAX", "coingecko"'),
|
|
44
52
|
});
|
|
45
53
|
/** A single balance's read-time valuation against a base currency (ADR-026 Phase 3) — omitted by
|
|
@@ -48,7 +56,7 @@ export const ConvertedValueSchema = z.object({
|
|
|
48
56
|
baseCurrency: CurrencyCode.describe('The currency this value is expressed in'),
|
|
49
57
|
value: z.number().describe('Amount converted to baseCurrency, rounded to its own decimals'),
|
|
50
58
|
rate: z.number().positive().describe('Exchange rate applied (1 when the source currency already is baseCurrency)'),
|
|
51
|
-
asOf:
|
|
59
|
+
asOf: IsoTimestamp.describe('When the applied rate was observed/sourced'),
|
|
52
60
|
stale: z.boolean().describe('True when the rate is older than its class staleness threshold'),
|
|
53
61
|
});
|
|
54
62
|
/** Why a currency was left out of a `displayCurrency` grand total — currently the only reason is a
|
|
@@ -66,11 +74,7 @@ export const ConvertedTotalSchema = z.object({
|
|
|
66
74
|
displayCurrency: CurrencyCode.describe('Currency the grand total is expressed in'),
|
|
67
75
|
total: z.number().describe('Sum of every convertible per-currency amount, rounded to displayCurrency decimals'),
|
|
68
76
|
stale: z.boolean().describe('True when any contributing rate is older than its class staleness threshold'),
|
|
69
|
-
asOf:
|
|
70
|
-
.string()
|
|
71
|
-
.datetime({ offset: true })
|
|
72
|
-
.nullable()
|
|
73
|
-
.describe('Oldest contributing rate timestamp, or null when nothing was converted'),
|
|
77
|
+
asOf: IsoTimestamp.nullable().describe('Oldest contributing rate timestamp, or null when nothing was converted'),
|
|
74
78
|
excluded: z.array(ExcludedCurrencySchema).describe('Currencies with no rate to displayCurrency, left out of total'),
|
|
75
79
|
});
|
|
76
80
|
export const currencyRateErrors = {
|
|
@@ -7,7 +7,7 @@ const EntityTagsSchema = z
|
|
|
7
7
|
return JSON.parse(text);
|
|
8
8
|
}
|
|
9
9
|
catch {
|
|
10
|
-
context.
|
|
10
|
+
context.issues.push({ code: 'custom', message: 'entities is not valid JSON', input: text });
|
|
11
11
|
return z.NEVER;
|
|
12
12
|
}
|
|
13
13
|
})
|
package/dist/wire/in/cli.js
CHANGED
|
@@ -7,6 +7,8 @@ import { TokenAccess } from '../../models/auth/token.js';
|
|
|
7
7
|
import { DemoCountry } from '../../models/demo/core.js';
|
|
8
8
|
/** The CLI's argv grammar: the commands, their subcommands, their flags and how many positionals each takes. */
|
|
9
9
|
export const PASSWORD_STDIN_FLAG = 'password-stdin';
|
|
10
|
+
export const DURATION_FLAG = 'duration';
|
|
11
|
+
export const SCOPE_FLAG = 'scope';
|
|
10
12
|
/** How many positional arguments each command takes: `setup` names one client, the `auth` subcommands none. */
|
|
11
13
|
export const SETUP_POSITIONALS = 1;
|
|
12
14
|
export const AUTH_POSITIONALS = 0;
|
|
@@ -26,7 +28,11 @@ export const ClaimOptionsSchema = z
|
|
|
26
28
|
export const ResetOptionsSchema = z
|
|
27
29
|
.object({
|
|
28
30
|
[PASSWORD_STDIN_FLAG]: z.boolean().default(false),
|
|
29
|
-
user: z
|
|
31
|
+
user: z
|
|
32
|
+
.string()
|
|
33
|
+
.transform(normalizeUsername)
|
|
34
|
+
.pipe(z.string().min(1, { error: '--user must not be empty' }).max(OPTION_MAX_LENGTH))
|
|
35
|
+
.optional(),
|
|
30
36
|
})
|
|
31
37
|
.transform((flags) => ({ passwordStdin: flags[PASSWORD_STDIN_FLAG], user: flags.user }));
|
|
32
38
|
export const DEMO_FLAG = 'demo';
|
|
@@ -45,7 +51,7 @@ export const SetupOptionsSchema = z
|
|
|
45
51
|
(flags[DEMO_FLAG] !== flags[REMOVE_DEMO_FLAG] &&
|
|
46
52
|
!flags[PASSWORD_STDIN_FLAG] &&
|
|
47
53
|
flags.username === undefined &&
|
|
48
|
-
flags.profile === undefined), {
|
|
54
|
+
flags.profile === undefined), { error: DEMO_EXCLUSIVE_MESSAGE })
|
|
49
55
|
.transform((flags) => ({
|
|
50
56
|
passwordStdin: flags[PASSWORD_STDIN_FLAG],
|
|
51
57
|
username: flags.username,
|
|
@@ -58,18 +64,22 @@ export const DemoOptionsSchema = z.object({
|
|
|
58
64
|
country: z
|
|
59
65
|
.string()
|
|
60
66
|
.refine((value) => DemoCountry.safeParse(value).success, {
|
|
61
|
-
|
|
67
|
+
error: `--country must be one of: ${DemoCountry.options.join(', ')}`,
|
|
62
68
|
})
|
|
63
69
|
.pipe(DemoCountry)
|
|
64
70
|
.optional(),
|
|
65
71
|
reset: z.boolean().default(false),
|
|
66
72
|
});
|
|
73
|
+
/** A flag given a value outside its choices says which flag, what it got and what is allowed. */
|
|
74
|
+
const flagValueError = (flag, choices) => (issue) => issue.input === undefined ? undefined : `--${flag}: '${String(issue.input)}' is not one of ${choices.join(', ')}`;
|
|
67
75
|
/** `login`: `profile` falls back to `PATTY_PROFILE` (the shell decides); `duration`/`scope` only pre-select the
|
|
68
76
|
* consent page — the person approving still chooses. */
|
|
69
77
|
export const LoginOptionsSchema = z.object({
|
|
70
78
|
profile: ProfileSchema.optional(),
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
[DURATION_FLAG]: z
|
|
80
|
+
.enum(LoginDuration.options, { error: flagValueError(DURATION_FLAG, LoginDuration.options) })
|
|
81
|
+
.optional(),
|
|
82
|
+
[SCOPE_FLAG]: z.enum(TokenAccess.options, { error: flagValueError(SCOPE_FLAG, TokenAccess.options) }).optional(),
|
|
73
83
|
});
|
|
74
84
|
export const LogoutOptionsSchema = z.object({ profile: ProfileSchema.optional() });
|
|
75
85
|
export const UsersSubcommand = z.enum(['list', 'invite', 'reissue', 'disable', 'enable', 'role']);
|
|
@@ -96,7 +106,7 @@ export const DbSubcommand = z.enum(['export', 'import']);
|
|
|
96
106
|
export const EXPORT_POSITIONALS = 0;
|
|
97
107
|
export const IMPORT_POSITIONALS = 0;
|
|
98
108
|
const pathOption = (flag) => z
|
|
99
|
-
.string({
|
|
109
|
+
.string({ error: (issue) => (issue.input === undefined ? `the file is required: --${flag} <file>` : undefined) })
|
|
100
110
|
.min(1)
|
|
101
111
|
.max(PATH_MAX_LENGTH);
|
|
102
112
|
export const ExportOptionsSchema = z.object({ to: pathOption('to') });
|
|
@@ -9,7 +9,7 @@ import { coerceToNumber } from './coerce.js';
|
|
|
9
9
|
// Pass-through — no boundary-only defaults needed.
|
|
10
10
|
export const ConfirmTransactionSchema = modelTransaction.ConfirmTransactionSchema;
|
|
11
11
|
// Pre-transform query shape — a plain ZodObject, so it can also serve as the route's
|
|
12
|
-
// OpenAPI query schema (routes.ts), which needs a ZodObject rather than the
|
|
12
|
+
// OpenAPI query schema (routes.ts), which needs a ZodObject rather than the pipe
|
|
13
13
|
// that .transform() produces below. QoL defaults (limit → 50, sort → date, dir → desc) are
|
|
14
14
|
// applied by the transform below, per the defaults-by-intent rule (domain stays honest about
|
|
15
15
|
// what's genuinely required). `includeTotal` arrives as a query string, not a real boolean.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rfc0/patty",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "AI-first personal finance manager — MCP server (local-first, encrypted libSQL).",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -69,34 +69,34 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@asteasolutions/zod-to-openapi": "^
|
|
72
|
+
"@asteasolutions/zod-to-openapi": "^9.1.0",
|
|
73
73
|
"@libsql/client": "^0.17.4",
|
|
74
74
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
75
75
|
"@napi-rs/keyring": "^1.3.0",
|
|
76
76
|
"@node-rs/argon2": "^2.2.2",
|
|
77
|
-
"@rfc0/effect-runner": "^0.
|
|
77
|
+
"@rfc0/effect-runner": "^1.0.0",
|
|
78
78
|
"drizzle-orm": "^0.45.2",
|
|
79
79
|
"fastify": "^5.12.8",
|
|
80
80
|
"jsonc-parser": "^3.3.1",
|
|
81
81
|
"neverthrow": "^8.2.0",
|
|
82
82
|
"openapi3-ts": "^4.6.0",
|
|
83
83
|
"remeda": "^2.21.0",
|
|
84
|
-
"zod": "^
|
|
84
|
+
"zod": "^4.6.6"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@eslint/css": "^2.0.1",
|
|
88
88
|
"@eslint/js": "^9.39.5",
|
|
89
|
-
"@html-eslint/eslint-plugin": "^0.
|
|
90
|
-
"@html-eslint/parser": "^0.
|
|
89
|
+
"@html-eslint/eslint-plugin": "^0.68.0",
|
|
90
|
+
"@html-eslint/parser": "^0.68.0",
|
|
91
91
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
92
92
|
"@semantic-release/github": "^12.0.8",
|
|
93
93
|
"@semantic-release/npm": "^13.1.5",
|
|
94
94
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
95
|
-
"@types/node": "^
|
|
95
|
+
"@types/node": "^26.0.0",
|
|
96
96
|
"@vitest/coverage-v8": "^4.1.8",
|
|
97
97
|
"cross-env": "^10.1.0",
|
|
98
98
|
"drizzle-kit": "^0.31.10",
|
|
99
|
-
"eslint": "^
|
|
99
|
+
"eslint": "^10.14.0",
|
|
100
100
|
"eslint-plugin-check-file": "^3.3.2",
|
|
101
101
|
"globals": "^17.13.0",
|
|
102
102
|
"prettier": "^3.9.4",
|