@hasna/microservices 0.0.3 → 0.0.5
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/bin/index.js +63 -0
- package/bin/mcp.js +63 -0
- package/dist/index.js +63 -0
- package/microservices/microservice-ads/package.json +27 -0
- package/microservices/microservice-ads/src/cli/index.ts +605 -0
- package/microservices/microservice-ads/src/db/campaigns.ts +797 -0
- package/microservices/microservice-ads/src/db/database.ts +93 -0
- package/microservices/microservice-ads/src/db/migrations.ts +60 -0
- package/microservices/microservice-ads/src/index.ts +39 -0
- package/microservices/microservice-ads/src/mcp/index.ts +480 -0
- package/microservices/microservice-contracts/package.json +27 -0
- package/microservices/microservice-contracts/src/cli/index.ts +770 -0
- package/microservices/microservice-contracts/src/db/contracts.ts +925 -0
- package/microservices/microservice-contracts/src/db/database.ts +93 -0
- package/microservices/microservice-contracts/src/db/migrations.ts +141 -0
- package/microservices/microservice-contracts/src/index.ts +43 -0
- package/microservices/microservice-contracts/src/mcp/index.ts +617 -0
- package/microservices/microservice-domains/package.json +27 -0
- package/microservices/microservice-domains/src/cli/index.ts +691 -0
- package/microservices/microservice-domains/src/db/database.ts +93 -0
- package/microservices/microservice-domains/src/db/domains.ts +1164 -0
- package/microservices/microservice-domains/src/db/migrations.ts +60 -0
- package/microservices/microservice-domains/src/index.ts +65 -0
- package/microservices/microservice-domains/src/mcp/index.ts +536 -0
- package/microservices/microservice-hiring/package.json +27 -0
- package/microservices/microservice-hiring/src/cli/index.ts +741 -0
- package/microservices/microservice-hiring/src/db/database.ts +93 -0
- package/microservices/microservice-hiring/src/db/hiring.ts +1085 -0
- package/microservices/microservice-hiring/src/db/migrations.ts +89 -0
- package/microservices/microservice-hiring/src/index.ts +80 -0
- package/microservices/microservice-hiring/src/lib/scoring.ts +206 -0
- package/microservices/microservice-hiring/src/mcp/index.ts +709 -0
- package/microservices/microservice-payments/package.json +27 -0
- package/microservices/microservice-payments/src/cli/index.ts +609 -0
- package/microservices/microservice-payments/src/db/database.ts +93 -0
- package/microservices/microservice-payments/src/db/migrations.ts +81 -0
- package/microservices/microservice-payments/src/db/payments.ts +1204 -0
- package/microservices/microservice-payments/src/index.ts +51 -0
- package/microservices/microservice-payments/src/mcp/index.ts +683 -0
- package/microservices/microservice-payroll/package.json +27 -0
- package/microservices/microservice-payroll/src/cli/index.ts +643 -0
- package/microservices/microservice-payroll/src/db/database.ts +93 -0
- package/microservices/microservice-payroll/src/db/migrations.ts +95 -0
- package/microservices/microservice-payroll/src/db/payroll.ts +1377 -0
- package/microservices/microservice-payroll/src/index.ts +48 -0
- package/microservices/microservice-payroll/src/mcp/index.ts +666 -0
- package/microservices/microservice-shipping/package.json +27 -0
- package/microservices/microservice-shipping/src/cli/index.ts +606 -0
- package/microservices/microservice-shipping/src/db/database.ts +93 -0
- package/microservices/microservice-shipping/src/db/migrations.ts +69 -0
- package/microservices/microservice-shipping/src/db/shipping.ts +1093 -0
- package/microservices/microservice-shipping/src/index.ts +53 -0
- package/microservices/microservice-shipping/src/mcp/index.ts +533 -0
- package/microservices/microservice-social/package.json +27 -0
- package/microservices/microservice-social/src/cli/index.ts +689 -0
- package/microservices/microservice-social/src/db/database.ts +93 -0
- package/microservices/microservice-social/src/db/migrations.ts +88 -0
- package/microservices/microservice-social/src/db/social.ts +1046 -0
- package/microservices/microservice-social/src/index.ts +46 -0
- package/microservices/microservice-social/src/mcp/index.ts +655 -0
- package/microservices/microservice-subscriptions/package.json +27 -0
- package/microservices/microservice-subscriptions/src/cli/index.ts +715 -0
- package/microservices/microservice-subscriptions/src/db/database.ts +93 -0
- package/microservices/microservice-subscriptions/src/db/migrations.ts +125 -0
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +1256 -0
- package/microservices/microservice-subscriptions/src/index.ts +41 -0
- package/microservices/microservice-subscriptions/src/mcp/index.ts +631 -0
- package/package.json +1 -1
|
@@ -0,0 +1,925 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract, Clause, and Reminder CRUD operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { getDatabase } from "./database.js";
|
|
6
|
+
|
|
7
|
+
// --- Contract types ---
|
|
8
|
+
|
|
9
|
+
export type ContractType = "nda" | "service" | "employment" | "license" | "other";
|
|
10
|
+
export type ContractStatus = "draft" | "pending_review" | "pending_signature" | "active" | "expired" | "terminated";
|
|
11
|
+
|
|
12
|
+
export interface Contract {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
type: ContractType;
|
|
16
|
+
status: ContractStatus;
|
|
17
|
+
counterparty: string | null;
|
|
18
|
+
counterparty_email: string | null;
|
|
19
|
+
start_date: string | null;
|
|
20
|
+
end_date: string | null;
|
|
21
|
+
auto_renew: boolean;
|
|
22
|
+
renewal_period: string | null;
|
|
23
|
+
value: number | null;
|
|
24
|
+
currency: string;
|
|
25
|
+
file_path: string | null;
|
|
26
|
+
metadata: Record<string, unknown>;
|
|
27
|
+
created_at: string;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ContractRow {
|
|
32
|
+
id: string;
|
|
33
|
+
title: string;
|
|
34
|
+
type: string;
|
|
35
|
+
status: string;
|
|
36
|
+
counterparty: string | null;
|
|
37
|
+
counterparty_email: string | null;
|
|
38
|
+
start_date: string | null;
|
|
39
|
+
end_date: string | null;
|
|
40
|
+
auto_renew: number;
|
|
41
|
+
renewal_period: string | null;
|
|
42
|
+
value: number | null;
|
|
43
|
+
currency: string;
|
|
44
|
+
file_path: string | null;
|
|
45
|
+
metadata: string;
|
|
46
|
+
created_at: string;
|
|
47
|
+
updated_at: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function rowToContract(row: ContractRow): Contract {
|
|
51
|
+
return {
|
|
52
|
+
...row,
|
|
53
|
+
type: row.type as ContractType,
|
|
54
|
+
status: row.status as ContractStatus,
|
|
55
|
+
auto_renew: row.auto_renew === 1,
|
|
56
|
+
metadata: JSON.parse(row.metadata || "{}"),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface CreateContractInput {
|
|
61
|
+
title: string;
|
|
62
|
+
type?: ContractType;
|
|
63
|
+
status?: ContractStatus;
|
|
64
|
+
counterparty?: string;
|
|
65
|
+
counterparty_email?: string;
|
|
66
|
+
start_date?: string;
|
|
67
|
+
end_date?: string;
|
|
68
|
+
auto_renew?: boolean;
|
|
69
|
+
renewal_period?: string;
|
|
70
|
+
value?: number;
|
|
71
|
+
currency?: string;
|
|
72
|
+
file_path?: string;
|
|
73
|
+
metadata?: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function createContract(input: CreateContractInput): Contract {
|
|
77
|
+
const db = getDatabase();
|
|
78
|
+
const id = crypto.randomUUID();
|
|
79
|
+
const metadata = JSON.stringify(input.metadata || {});
|
|
80
|
+
|
|
81
|
+
db.prepare(
|
|
82
|
+
`INSERT INTO contracts (id, title, type, status, counterparty, counterparty_email, start_date, end_date, auto_renew, renewal_period, value, currency, file_path, metadata)
|
|
83
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
84
|
+
).run(
|
|
85
|
+
id,
|
|
86
|
+
input.title,
|
|
87
|
+
input.type || "other",
|
|
88
|
+
input.status || "draft",
|
|
89
|
+
input.counterparty || null,
|
|
90
|
+
input.counterparty_email || null,
|
|
91
|
+
input.start_date || null,
|
|
92
|
+
input.end_date || null,
|
|
93
|
+
input.auto_renew ? 1 : 0,
|
|
94
|
+
input.renewal_period || null,
|
|
95
|
+
input.value ?? null,
|
|
96
|
+
input.currency || "USD",
|
|
97
|
+
input.file_path || null,
|
|
98
|
+
metadata
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return getContract(id)!;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function getContract(id: string): Contract | null {
|
|
105
|
+
const db = getDatabase();
|
|
106
|
+
const row = db.prepare("SELECT * FROM contracts WHERE id = ?").get(id) as ContractRow | null;
|
|
107
|
+
return row ? rowToContract(row) : null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface ListContractsOptions {
|
|
111
|
+
search?: string;
|
|
112
|
+
type?: ContractType;
|
|
113
|
+
status?: ContractStatus;
|
|
114
|
+
counterparty?: string;
|
|
115
|
+
limit?: number;
|
|
116
|
+
offset?: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function listContracts(options: ListContractsOptions = {}): Contract[] {
|
|
120
|
+
const db = getDatabase();
|
|
121
|
+
const conditions: string[] = [];
|
|
122
|
+
const params: unknown[] = [];
|
|
123
|
+
|
|
124
|
+
if (options.search) {
|
|
125
|
+
conditions.push(
|
|
126
|
+
"(title LIKE ? OR counterparty LIKE ? OR counterparty_email LIKE ?)"
|
|
127
|
+
);
|
|
128
|
+
const q = `%${options.search}%`;
|
|
129
|
+
params.push(q, q, q);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (options.type) {
|
|
133
|
+
conditions.push("type = ?");
|
|
134
|
+
params.push(options.type);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (options.status) {
|
|
138
|
+
conditions.push("status = ?");
|
|
139
|
+
params.push(options.status);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (options.counterparty) {
|
|
143
|
+
conditions.push("counterparty LIKE ?");
|
|
144
|
+
params.push(`%${options.counterparty}%`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let sql = "SELECT * FROM contracts";
|
|
148
|
+
if (conditions.length > 0) {
|
|
149
|
+
sql += " WHERE " + conditions.join(" AND ");
|
|
150
|
+
}
|
|
151
|
+
sql += " ORDER BY created_at DESC";
|
|
152
|
+
|
|
153
|
+
if (options.limit) {
|
|
154
|
+
sql += " LIMIT ?";
|
|
155
|
+
params.push(options.limit);
|
|
156
|
+
}
|
|
157
|
+
if (options.offset) {
|
|
158
|
+
sql += " OFFSET ?";
|
|
159
|
+
params.push(options.offset);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const rows = db.prepare(sql).all(...params) as ContractRow[];
|
|
163
|
+
return rows.map(rowToContract);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface UpdateContractInput {
|
|
167
|
+
title?: string;
|
|
168
|
+
type?: ContractType;
|
|
169
|
+
status?: ContractStatus;
|
|
170
|
+
counterparty?: string;
|
|
171
|
+
counterparty_email?: string;
|
|
172
|
+
start_date?: string;
|
|
173
|
+
end_date?: string;
|
|
174
|
+
auto_renew?: boolean;
|
|
175
|
+
renewal_period?: string;
|
|
176
|
+
value?: number;
|
|
177
|
+
currency?: string;
|
|
178
|
+
file_path?: string;
|
|
179
|
+
metadata?: Record<string, unknown>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function updateContract(
|
|
183
|
+
id: string,
|
|
184
|
+
input: UpdateContractInput
|
|
185
|
+
): Contract | null {
|
|
186
|
+
const db = getDatabase();
|
|
187
|
+
const existing = getContract(id);
|
|
188
|
+
if (!existing) return null;
|
|
189
|
+
|
|
190
|
+
const sets: string[] = [];
|
|
191
|
+
const params: unknown[] = [];
|
|
192
|
+
|
|
193
|
+
if (input.title !== undefined) {
|
|
194
|
+
sets.push("title = ?");
|
|
195
|
+
params.push(input.title);
|
|
196
|
+
}
|
|
197
|
+
if (input.type !== undefined) {
|
|
198
|
+
sets.push("type = ?");
|
|
199
|
+
params.push(input.type);
|
|
200
|
+
}
|
|
201
|
+
if (input.status !== undefined) {
|
|
202
|
+
sets.push("status = ?");
|
|
203
|
+
params.push(input.status);
|
|
204
|
+
}
|
|
205
|
+
if (input.counterparty !== undefined) {
|
|
206
|
+
sets.push("counterparty = ?");
|
|
207
|
+
params.push(input.counterparty);
|
|
208
|
+
}
|
|
209
|
+
if (input.counterparty_email !== undefined) {
|
|
210
|
+
sets.push("counterparty_email = ?");
|
|
211
|
+
params.push(input.counterparty_email);
|
|
212
|
+
}
|
|
213
|
+
if (input.start_date !== undefined) {
|
|
214
|
+
sets.push("start_date = ?");
|
|
215
|
+
params.push(input.start_date);
|
|
216
|
+
}
|
|
217
|
+
if (input.end_date !== undefined) {
|
|
218
|
+
sets.push("end_date = ?");
|
|
219
|
+
params.push(input.end_date);
|
|
220
|
+
}
|
|
221
|
+
if (input.auto_renew !== undefined) {
|
|
222
|
+
sets.push("auto_renew = ?");
|
|
223
|
+
params.push(input.auto_renew ? 1 : 0);
|
|
224
|
+
}
|
|
225
|
+
if (input.renewal_period !== undefined) {
|
|
226
|
+
sets.push("renewal_period = ?");
|
|
227
|
+
params.push(input.renewal_period);
|
|
228
|
+
}
|
|
229
|
+
if (input.value !== undefined) {
|
|
230
|
+
sets.push("value = ?");
|
|
231
|
+
params.push(input.value);
|
|
232
|
+
}
|
|
233
|
+
if (input.currency !== undefined) {
|
|
234
|
+
sets.push("currency = ?");
|
|
235
|
+
params.push(input.currency);
|
|
236
|
+
}
|
|
237
|
+
if (input.file_path !== undefined) {
|
|
238
|
+
sets.push("file_path = ?");
|
|
239
|
+
params.push(input.file_path);
|
|
240
|
+
}
|
|
241
|
+
if (input.metadata !== undefined) {
|
|
242
|
+
sets.push("metadata = ?");
|
|
243
|
+
params.push(JSON.stringify(input.metadata));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (sets.length === 0) return existing;
|
|
247
|
+
|
|
248
|
+
// Save version history before updating
|
|
249
|
+
saveContractVersion(existing);
|
|
250
|
+
|
|
251
|
+
sets.push("updated_at = datetime('now')");
|
|
252
|
+
params.push(id);
|
|
253
|
+
|
|
254
|
+
db.prepare(
|
|
255
|
+
`UPDATE contracts SET ${sets.join(", ")} WHERE id = ?`
|
|
256
|
+
).run(...params);
|
|
257
|
+
|
|
258
|
+
return getContract(id);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function deleteContract(id: string): boolean {
|
|
262
|
+
const db = getDatabase();
|
|
263
|
+
const result = db.prepare("DELETE FROM contracts WHERE id = ?").run(id);
|
|
264
|
+
return result.changes > 0;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function searchContracts(query: string): Contract[] {
|
|
268
|
+
return listContracts({ search: query });
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* List contracts expiring within the given number of days
|
|
273
|
+
*/
|
|
274
|
+
export function listExpiring(days: number): Contract[] {
|
|
275
|
+
const db = getDatabase();
|
|
276
|
+
const rows = db
|
|
277
|
+
.prepare(
|
|
278
|
+
`SELECT * FROM contracts
|
|
279
|
+
WHERE end_date IS NOT NULL
|
|
280
|
+
AND status IN ('active', 'pending_signature')
|
|
281
|
+
AND date(end_date) <= date('now', '+' || ? || ' days')
|
|
282
|
+
AND date(end_date) >= date('now')
|
|
283
|
+
ORDER BY end_date ASC`
|
|
284
|
+
)
|
|
285
|
+
.all(days) as ContractRow[];
|
|
286
|
+
return rows.map(rowToContract);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Renew a contract by extending its end_date based on renewal_period.
|
|
291
|
+
* If renewal_period is not set, extends by 1 year.
|
|
292
|
+
*/
|
|
293
|
+
export function renewContract(id: string): Contract | null {
|
|
294
|
+
const contract = getContract(id);
|
|
295
|
+
if (!contract) return null;
|
|
296
|
+
|
|
297
|
+
const period = contract.renewal_period || "1 year";
|
|
298
|
+
const baseDate = contract.end_date || new Date().toISOString().split("T")[0];
|
|
299
|
+
|
|
300
|
+
const db = getDatabase();
|
|
301
|
+
db.prepare(
|
|
302
|
+
`UPDATE contracts
|
|
303
|
+
SET end_date = date(?, '+' || ?),
|
|
304
|
+
status = 'active',
|
|
305
|
+
updated_at = datetime('now')
|
|
306
|
+
WHERE id = ?`
|
|
307
|
+
).run(baseDate, period, id);
|
|
308
|
+
|
|
309
|
+
return getContract(id);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Get aggregate stats about contracts
|
|
314
|
+
*/
|
|
315
|
+
export function getContractStats(): {
|
|
316
|
+
total: number;
|
|
317
|
+
by_status: Record<string, number>;
|
|
318
|
+
by_type: Record<string, number>;
|
|
319
|
+
total_value: number;
|
|
320
|
+
expiring_30_days: number;
|
|
321
|
+
} {
|
|
322
|
+
const db = getDatabase();
|
|
323
|
+
|
|
324
|
+
const total = (
|
|
325
|
+
db.prepare("SELECT COUNT(*) as count FROM contracts").get() as { count: number }
|
|
326
|
+
).count;
|
|
327
|
+
|
|
328
|
+
const statusRows = db
|
|
329
|
+
.prepare("SELECT status, COUNT(*) as count FROM contracts GROUP BY status")
|
|
330
|
+
.all() as { status: string; count: number }[];
|
|
331
|
+
const by_status: Record<string, number> = {};
|
|
332
|
+
for (const row of statusRows) {
|
|
333
|
+
by_status[row.status] = row.count;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const typeRows = db
|
|
337
|
+
.prepare("SELECT type, COUNT(*) as count FROM contracts GROUP BY type")
|
|
338
|
+
.all() as { type: string; count: number }[];
|
|
339
|
+
const by_type: Record<string, number> = {};
|
|
340
|
+
for (const row of typeRows) {
|
|
341
|
+
by_type[row.type] = row.count;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const valueRow = db
|
|
345
|
+
.prepare("SELECT COALESCE(SUM(value), 0) as total FROM contracts WHERE status = 'active'")
|
|
346
|
+
.get() as { total: number };
|
|
347
|
+
|
|
348
|
+
const expiringRow = db
|
|
349
|
+
.prepare(
|
|
350
|
+
`SELECT COUNT(*) as count FROM contracts
|
|
351
|
+
WHERE end_date IS NOT NULL
|
|
352
|
+
AND status IN ('active', 'pending_signature')
|
|
353
|
+
AND date(end_date) <= date('now', '+30 days')
|
|
354
|
+
AND date(end_date) >= date('now')`
|
|
355
|
+
)
|
|
356
|
+
.get() as { count: number };
|
|
357
|
+
|
|
358
|
+
return {
|
|
359
|
+
total,
|
|
360
|
+
by_status,
|
|
361
|
+
by_type,
|
|
362
|
+
total_value: valueRow.total,
|
|
363
|
+
expiring_30_days: expiringRow.count,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// --- Clause operations ---
|
|
368
|
+
|
|
369
|
+
export interface Clause {
|
|
370
|
+
id: string;
|
|
371
|
+
contract_id: string;
|
|
372
|
+
name: string;
|
|
373
|
+
text: string;
|
|
374
|
+
type: "standard" | "custom" | "negotiated";
|
|
375
|
+
created_at: string;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export interface CreateClauseInput {
|
|
379
|
+
contract_id: string;
|
|
380
|
+
name: string;
|
|
381
|
+
text: string;
|
|
382
|
+
type?: "standard" | "custom" | "negotiated";
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export function createClause(input: CreateClauseInput): Clause {
|
|
386
|
+
const db = getDatabase();
|
|
387
|
+
const id = crypto.randomUUID();
|
|
388
|
+
|
|
389
|
+
db.prepare(
|
|
390
|
+
`INSERT INTO clauses (id, contract_id, name, text, type)
|
|
391
|
+
VALUES (?, ?, ?, ?, ?)`
|
|
392
|
+
).run(id, input.contract_id, input.name, input.text, input.type || "standard");
|
|
393
|
+
|
|
394
|
+
return getClause(id)!;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export function getClause(id: string): Clause | null {
|
|
398
|
+
const db = getDatabase();
|
|
399
|
+
const row = db.prepare("SELECT * FROM clauses WHERE id = ?").get(id) as Clause | null;
|
|
400
|
+
return row || null;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export function listClauses(contractId: string): Clause[] {
|
|
404
|
+
const db = getDatabase();
|
|
405
|
+
return db
|
|
406
|
+
.prepare("SELECT * FROM clauses WHERE contract_id = ? ORDER BY created_at ASC")
|
|
407
|
+
.all(contractId) as Clause[];
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function deleteClause(id: string): boolean {
|
|
411
|
+
const db = getDatabase();
|
|
412
|
+
const result = db.prepare("DELETE FROM clauses WHERE id = ?").run(id);
|
|
413
|
+
return result.changes > 0;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// --- Reminder operations ---
|
|
417
|
+
|
|
418
|
+
export interface Reminder {
|
|
419
|
+
id: string;
|
|
420
|
+
contract_id: string;
|
|
421
|
+
remind_at: string;
|
|
422
|
+
message: string;
|
|
423
|
+
sent: boolean;
|
|
424
|
+
created_at: string;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
interface ReminderRow {
|
|
428
|
+
id: string;
|
|
429
|
+
contract_id: string;
|
|
430
|
+
remind_at: string;
|
|
431
|
+
message: string;
|
|
432
|
+
sent: number;
|
|
433
|
+
created_at: string;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function rowToReminder(row: ReminderRow): Reminder {
|
|
437
|
+
return {
|
|
438
|
+
...row,
|
|
439
|
+
sent: row.sent === 1,
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export interface CreateReminderInput {
|
|
444
|
+
contract_id: string;
|
|
445
|
+
remind_at: string;
|
|
446
|
+
message: string;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export function createReminder(input: CreateReminderInput): Reminder {
|
|
450
|
+
const db = getDatabase();
|
|
451
|
+
const id = crypto.randomUUID();
|
|
452
|
+
|
|
453
|
+
db.prepare(
|
|
454
|
+
`INSERT INTO reminders (id, contract_id, remind_at, message)
|
|
455
|
+
VALUES (?, ?, ?, ?)`
|
|
456
|
+
).run(id, input.contract_id, input.remind_at, input.message);
|
|
457
|
+
|
|
458
|
+
return getReminder(id)!;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export function getReminder(id: string): Reminder | null {
|
|
462
|
+
const db = getDatabase();
|
|
463
|
+
const row = db.prepare("SELECT * FROM reminders WHERE id = ?").get(id) as ReminderRow | null;
|
|
464
|
+
return row ? rowToReminder(row) : null;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export function listReminders(contractId: string): Reminder[] {
|
|
468
|
+
const db = getDatabase();
|
|
469
|
+
const rows = db
|
|
470
|
+
.prepare("SELECT * FROM reminders WHERE contract_id = ? ORDER BY remind_at ASC")
|
|
471
|
+
.all(contractId) as ReminderRow[];
|
|
472
|
+
return rows.map(rowToReminder);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export function deleteReminder(id: string): boolean {
|
|
476
|
+
const db = getDatabase();
|
|
477
|
+
const result = db.prepare("DELETE FROM reminders WHERE id = ?").run(id);
|
|
478
|
+
return result.changes > 0;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export function listPendingReminders(): Reminder[] {
|
|
482
|
+
const db = getDatabase();
|
|
483
|
+
const rows = db
|
|
484
|
+
.prepare(
|
|
485
|
+
`SELECT * FROM reminders
|
|
486
|
+
WHERE sent = 0 AND datetime(remind_at) <= datetime('now')
|
|
487
|
+
ORDER BY remind_at ASC`
|
|
488
|
+
)
|
|
489
|
+
.all() as ReminderRow[];
|
|
490
|
+
return rows.map(rowToReminder);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export function markReminderSent(id: string): boolean {
|
|
494
|
+
const db = getDatabase();
|
|
495
|
+
const result = db
|
|
496
|
+
.prepare("UPDATE reminders SET sent = 1 WHERE id = ?")
|
|
497
|
+
.run(id);
|
|
498
|
+
return result.changes > 0;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// --- Obligation operations ---
|
|
502
|
+
|
|
503
|
+
export type ObligationStatus = "pending" | "completed" | "overdue";
|
|
504
|
+
|
|
505
|
+
export interface Obligation {
|
|
506
|
+
id: string;
|
|
507
|
+
clause_id: string;
|
|
508
|
+
description: string;
|
|
509
|
+
due_date: string | null;
|
|
510
|
+
status: ObligationStatus;
|
|
511
|
+
assigned_to: string | null;
|
|
512
|
+
created_at: string;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export interface CreateObligationInput {
|
|
516
|
+
clause_id: string;
|
|
517
|
+
description: string;
|
|
518
|
+
due_date?: string;
|
|
519
|
+
assigned_to?: string;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
export function createObligation(input: CreateObligationInput): Obligation {
|
|
523
|
+
const db = getDatabase();
|
|
524
|
+
const id = crypto.randomUUID();
|
|
525
|
+
|
|
526
|
+
db.prepare(
|
|
527
|
+
`INSERT INTO obligations (id, clause_id, description, due_date, assigned_to)
|
|
528
|
+
VALUES (?, ?, ?, ?, ?)`
|
|
529
|
+
).run(id, input.clause_id, input.description, input.due_date || null, input.assigned_to || null);
|
|
530
|
+
|
|
531
|
+
return getObligation(id)!;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export function getObligation(id: string): Obligation | null {
|
|
535
|
+
const db = getDatabase();
|
|
536
|
+
const row = db.prepare("SELECT * FROM obligations WHERE id = ?").get(id) as Obligation | null;
|
|
537
|
+
return row || null;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export function listObligations(clauseId: string): Obligation[] {
|
|
541
|
+
const db = getDatabase();
|
|
542
|
+
return db
|
|
543
|
+
.prepare("SELECT * FROM obligations WHERE clause_id = ? ORDER BY created_at ASC")
|
|
544
|
+
.all(clauseId) as Obligation[];
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
export function completeObligation(id: string): Obligation | null {
|
|
548
|
+
const db = getDatabase();
|
|
549
|
+
const result = db
|
|
550
|
+
.prepare("UPDATE obligations SET status = 'completed' WHERE id = ?")
|
|
551
|
+
.run(id);
|
|
552
|
+
if (result.changes === 0) return null;
|
|
553
|
+
return getObligation(id);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export function listOverdueObligations(): Obligation[] {
|
|
557
|
+
const db = getDatabase();
|
|
558
|
+
// Mark obligations past due_date as overdue, then return them
|
|
559
|
+
db.prepare(
|
|
560
|
+
`UPDATE obligations SET status = 'overdue'
|
|
561
|
+
WHERE status = 'pending' AND due_date IS NOT NULL AND date(due_date) < date('now')`
|
|
562
|
+
).run();
|
|
563
|
+
|
|
564
|
+
return db
|
|
565
|
+
.prepare(
|
|
566
|
+
`SELECT * FROM obligations
|
|
567
|
+
WHERE status = 'overdue'
|
|
568
|
+
ORDER BY due_date ASC`
|
|
569
|
+
)
|
|
570
|
+
.all() as Obligation[];
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// --- Approval workflow ---
|
|
574
|
+
|
|
575
|
+
const APPROVAL_FLOW: Record<string, string> = {
|
|
576
|
+
draft: "pending_review",
|
|
577
|
+
pending_review: "pending_signature",
|
|
578
|
+
pending_signature: "active",
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Submit a draft contract for review: draft -> pending_review
|
|
583
|
+
*/
|
|
584
|
+
export function submitForReview(id: string): Contract | null {
|
|
585
|
+
const contract = getContract(id);
|
|
586
|
+
if (!contract) return null;
|
|
587
|
+
if (contract.status !== "draft") {
|
|
588
|
+
throw new Error(`Cannot submit for review: contract status is '${contract.status}', expected 'draft'`);
|
|
589
|
+
}
|
|
590
|
+
return updateContract(id, { status: "pending_review" });
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Approve a contract: pending_review -> pending_signature -> active
|
|
595
|
+
* Advances the contract one step in the approval flow.
|
|
596
|
+
*/
|
|
597
|
+
export function approveContract(id: string): Contract | null {
|
|
598
|
+
const contract = getContract(id);
|
|
599
|
+
if (!contract) return null;
|
|
600
|
+
const nextStatus = APPROVAL_FLOW[contract.status];
|
|
601
|
+
if (!nextStatus) {
|
|
602
|
+
throw new Error(
|
|
603
|
+
`Cannot approve: contract status is '${contract.status}'. Approval flow: draft -> pending_review -> pending_signature -> active`
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
return updateContract(id, { status: nextStatus as ContractStatus });
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// --- Version history ---
|
|
610
|
+
|
|
611
|
+
export interface ContractVersion {
|
|
612
|
+
id: string;
|
|
613
|
+
contract_id: string;
|
|
614
|
+
title: string;
|
|
615
|
+
status: string;
|
|
616
|
+
value: number | null;
|
|
617
|
+
metadata_snapshot: Record<string, unknown>;
|
|
618
|
+
changed_at: string;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
interface ContractVersionRow {
|
|
622
|
+
id: string;
|
|
623
|
+
contract_id: string;
|
|
624
|
+
title: string;
|
|
625
|
+
status: string;
|
|
626
|
+
value: number | null;
|
|
627
|
+
metadata_snapshot: string;
|
|
628
|
+
changed_at: string;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function rowToVersion(row: ContractVersionRow): ContractVersion {
|
|
632
|
+
return {
|
|
633
|
+
...row,
|
|
634
|
+
metadata_snapshot: JSON.parse(row.metadata_snapshot || "{}"),
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function saveContractVersion(contract: Contract): void {
|
|
639
|
+
const db = getDatabase();
|
|
640
|
+
const id = crypto.randomUUID();
|
|
641
|
+
db.prepare(
|
|
642
|
+
`INSERT INTO contract_versions (id, contract_id, title, status, value, metadata_snapshot)
|
|
643
|
+
VALUES (?, ?, ?, ?, ?, ?)`
|
|
644
|
+
).run(
|
|
645
|
+
id,
|
|
646
|
+
contract.id,
|
|
647
|
+
contract.title,
|
|
648
|
+
contract.status,
|
|
649
|
+
contract.value,
|
|
650
|
+
JSON.stringify(contract.metadata)
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
export function getContractHistory(contractId: string): ContractVersion[] {
|
|
655
|
+
const db = getDatabase();
|
|
656
|
+
const rows = db
|
|
657
|
+
.prepare("SELECT * FROM contract_versions WHERE contract_id = ? ORDER BY changed_at ASC")
|
|
658
|
+
.all(contractId) as ContractVersionRow[];
|
|
659
|
+
return rows.map(rowToVersion);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// --- Signature logging ---
|
|
663
|
+
|
|
664
|
+
export type SignatureMethod = "digital" | "wet" | "docusign";
|
|
665
|
+
|
|
666
|
+
export interface Signature {
|
|
667
|
+
id: string;
|
|
668
|
+
contract_id: string;
|
|
669
|
+
signer_name: string;
|
|
670
|
+
signer_email: string | null;
|
|
671
|
+
signed_at: string;
|
|
672
|
+
method: SignatureMethod;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export interface RecordSignatureInput {
|
|
676
|
+
contract_id: string;
|
|
677
|
+
signer_name: string;
|
|
678
|
+
signer_email?: string;
|
|
679
|
+
method?: SignatureMethod;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
export function recordSignature(input: RecordSignatureInput): Signature {
|
|
683
|
+
const db = getDatabase();
|
|
684
|
+
const id = crypto.randomUUID();
|
|
685
|
+
|
|
686
|
+
db.prepare(
|
|
687
|
+
`INSERT INTO signatures (id, contract_id, signer_name, signer_email, method)
|
|
688
|
+
VALUES (?, ?, ?, ?, ?)`
|
|
689
|
+
).run(id, input.contract_id, input.signer_name, input.signer_email || null, input.method || "digital");
|
|
690
|
+
|
|
691
|
+
return getSignature(id)!;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
export function getSignature(id: string): Signature | null {
|
|
695
|
+
const db = getDatabase();
|
|
696
|
+
const row = db.prepare("SELECT * FROM signatures WHERE id = ?").get(id) as Signature | null;
|
|
697
|
+
return row || null;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
export function listSignatures(contractId: string): Signature[] {
|
|
701
|
+
const db = getDatabase();
|
|
702
|
+
return db
|
|
703
|
+
.prepare("SELECT * FROM signatures WHERE contract_id = ? ORDER BY signed_at ASC")
|
|
704
|
+
.all(contractId) as Signature[];
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// --- Clause templates (library) ---
|
|
708
|
+
|
|
709
|
+
export interface ClauseTemplate {
|
|
710
|
+
id: string;
|
|
711
|
+
name: string;
|
|
712
|
+
text: string;
|
|
713
|
+
type: "standard" | "custom" | "negotiated";
|
|
714
|
+
created_at: string;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
export interface SaveClauseTemplateInput {
|
|
718
|
+
name: string;
|
|
719
|
+
text: string;
|
|
720
|
+
type?: "standard" | "custom" | "negotiated";
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
export function saveClauseTemplate(input: SaveClauseTemplateInput): ClauseTemplate {
|
|
724
|
+
const db = getDatabase();
|
|
725
|
+
const id = crypto.randomUUID();
|
|
726
|
+
|
|
727
|
+
db.prepare(
|
|
728
|
+
`INSERT INTO clause_templates (id, name, text, type)
|
|
729
|
+
VALUES (?, ?, ?, ?)`
|
|
730
|
+
).run(id, input.name, input.text, input.type || "standard");
|
|
731
|
+
|
|
732
|
+
return getClauseTemplate(id)!;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
export function getClauseTemplate(id: string): ClauseTemplate | null {
|
|
736
|
+
const db = getDatabase();
|
|
737
|
+
const row = db.prepare("SELECT * FROM clause_templates WHERE id = ?").get(id) as ClauseTemplate | null;
|
|
738
|
+
return row || null;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
export function getClauseTemplateByName(name: string): ClauseTemplate | null {
|
|
742
|
+
const db = getDatabase();
|
|
743
|
+
const row = db.prepare("SELECT * FROM clause_templates WHERE name = ?").get(name) as ClauseTemplate | null;
|
|
744
|
+
return row || null;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
export function listClauseTemplates(): ClauseTemplate[] {
|
|
748
|
+
const db = getDatabase();
|
|
749
|
+
return db
|
|
750
|
+
.prepare("SELECT * FROM clause_templates ORDER BY name ASC")
|
|
751
|
+
.all() as ClauseTemplate[];
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
export function addClauseFromTemplate(contractId: string, templateName: string): Clause {
|
|
755
|
+
const template = getClauseTemplateByName(templateName);
|
|
756
|
+
if (!template) {
|
|
757
|
+
throw new Error(`Clause template '${templateName}' not found`);
|
|
758
|
+
}
|
|
759
|
+
return createClause({
|
|
760
|
+
contract_id: contractId,
|
|
761
|
+
name: template.name,
|
|
762
|
+
text: template.text,
|
|
763
|
+
type: template.type,
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// --- Multi-stage reminders ---
|
|
768
|
+
|
|
769
|
+
export function setMultiReminders(
|
|
770
|
+
contractId: string,
|
|
771
|
+
daysBefore: number[]
|
|
772
|
+
): Reminder[] {
|
|
773
|
+
const contract = getContract(contractId);
|
|
774
|
+
if (!contract) {
|
|
775
|
+
throw new Error(`Contract '${contractId}' not found`);
|
|
776
|
+
}
|
|
777
|
+
if (!contract.end_date) {
|
|
778
|
+
throw new Error(`Contract '${contractId}' has no end_date set`);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
const endDate = new Date(contract.end_date);
|
|
782
|
+
const reminders: Reminder[] = [];
|
|
783
|
+
|
|
784
|
+
for (const days of daysBefore) {
|
|
785
|
+
const remindDate = new Date(endDate);
|
|
786
|
+
remindDate.setDate(remindDate.getDate() - days);
|
|
787
|
+
const remindAt = remindDate.toISOString().split("T")[0] + "T09:00:00";
|
|
788
|
+
|
|
789
|
+
const reminder = createReminder({
|
|
790
|
+
contract_id: contractId,
|
|
791
|
+
remind_at: remindAt,
|
|
792
|
+
message: `Contract "${contract.title}" expires in ${days} day(s)`,
|
|
793
|
+
});
|
|
794
|
+
reminders.push(reminder);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
return reminders;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// --- Contract comparison ---
|
|
801
|
+
|
|
802
|
+
export interface ContractComparison {
|
|
803
|
+
contract1: { id: string; title: string };
|
|
804
|
+
contract2: { id: string; title: string };
|
|
805
|
+
field_differences: { field: string; contract1_value: unknown; contract2_value: unknown }[];
|
|
806
|
+
clause_only_in_1: Clause[];
|
|
807
|
+
clause_only_in_2: Clause[];
|
|
808
|
+
clause_differences: { name: string; contract1_text: string; contract2_text: string }[];
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
export function compareContracts(id1: string, id2: string): ContractComparison {
|
|
812
|
+
const c1 = getContract(id1);
|
|
813
|
+
const c2 = getContract(id2);
|
|
814
|
+
if (!c1) throw new Error(`Contract '${id1}' not found`);
|
|
815
|
+
if (!c2) throw new Error(`Contract '${id2}' not found`);
|
|
816
|
+
|
|
817
|
+
// Compare fields
|
|
818
|
+
const fieldsToCompare: (keyof Contract)[] = [
|
|
819
|
+
"title", "type", "status", "counterparty", "counterparty_email",
|
|
820
|
+
"start_date", "end_date", "auto_renew", "renewal_period",
|
|
821
|
+
"value", "currency",
|
|
822
|
+
];
|
|
823
|
+
const field_differences: { field: string; contract1_value: unknown; contract2_value: unknown }[] = [];
|
|
824
|
+
for (const field of fieldsToCompare) {
|
|
825
|
+
const v1 = c1[field];
|
|
826
|
+
const v2 = c2[field];
|
|
827
|
+
if (JSON.stringify(v1) !== JSON.stringify(v2)) {
|
|
828
|
+
field_differences.push({ field, contract1_value: v1, contract2_value: v2 });
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// Compare clauses by name
|
|
833
|
+
const clauses1 = listClauses(id1);
|
|
834
|
+
const clauses2 = listClauses(id2);
|
|
835
|
+
const names1 = new Set(clauses1.map((c) => c.name));
|
|
836
|
+
const names2 = new Set(clauses2.map((c) => c.name));
|
|
837
|
+
|
|
838
|
+
const clause_only_in_1 = clauses1.filter((c) => !names2.has(c.name));
|
|
839
|
+
const clause_only_in_2 = clauses2.filter((c) => !names1.has(c.name));
|
|
840
|
+
|
|
841
|
+
const clause_differences: { name: string; contract1_text: string; contract2_text: string }[] = [];
|
|
842
|
+
for (const cl1 of clauses1) {
|
|
843
|
+
const cl2 = clauses2.find((c) => c.name === cl1.name);
|
|
844
|
+
if (cl2 && cl1.text !== cl2.text) {
|
|
845
|
+
clause_differences.push({ name: cl1.name, contract1_text: cl1.text, contract2_text: cl2.text });
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
return {
|
|
850
|
+
contract1: { id: c1.id, title: c1.title },
|
|
851
|
+
contract2: { id: c2.id, title: c2.title },
|
|
852
|
+
field_differences,
|
|
853
|
+
clause_only_in_1,
|
|
854
|
+
clause_only_in_2,
|
|
855
|
+
clause_differences,
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// --- Markdown export ---
|
|
860
|
+
|
|
861
|
+
export function exportContract(id: string, format: "md" | "json" = "md"): string {
|
|
862
|
+
const contract = getContract(id);
|
|
863
|
+
if (!contract) throw new Error(`Contract '${id}' not found`);
|
|
864
|
+
|
|
865
|
+
if (format === "json") {
|
|
866
|
+
const clauses = listClauses(id);
|
|
867
|
+
const sigs = listSignatures(id);
|
|
868
|
+
const reminders = listReminders(id);
|
|
869
|
+
return JSON.stringify({ contract, clauses, signatures: sigs, reminders }, null, 2);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// Markdown export
|
|
873
|
+
const lines: string[] = [];
|
|
874
|
+
lines.push(`# ${contract.title}`);
|
|
875
|
+
lines.push("");
|
|
876
|
+
lines.push(`| Field | Value |`);
|
|
877
|
+
lines.push(`|-------|-------|`);
|
|
878
|
+
lines.push(`| Type | ${contract.type} |`);
|
|
879
|
+
lines.push(`| Status | ${contract.status} |`);
|
|
880
|
+
if (contract.counterparty) lines.push(`| Counterparty | ${contract.counterparty} |`);
|
|
881
|
+
if (contract.counterparty_email) lines.push(`| Email | ${contract.counterparty_email} |`);
|
|
882
|
+
if (contract.start_date) lines.push(`| Start Date | ${contract.start_date} |`);
|
|
883
|
+
if (contract.end_date) lines.push(`| End Date | ${contract.end_date} |`);
|
|
884
|
+
if (contract.value !== null) lines.push(`| Value | ${contract.value} ${contract.currency} |`);
|
|
885
|
+
if (contract.auto_renew) lines.push(`| Auto-Renew | ${contract.renewal_period || "1 year"} |`);
|
|
886
|
+
lines.push(`| Created | ${contract.created_at} |`);
|
|
887
|
+
lines.push(`| Updated | ${contract.updated_at} |`);
|
|
888
|
+
|
|
889
|
+
const clauses = listClauses(id);
|
|
890
|
+
if (clauses.length > 0) {
|
|
891
|
+
lines.push("");
|
|
892
|
+
lines.push("## Clauses");
|
|
893
|
+
lines.push("");
|
|
894
|
+
for (const clause of clauses) {
|
|
895
|
+
lines.push(`### ${clause.name} (${clause.type})`);
|
|
896
|
+
lines.push("");
|
|
897
|
+
lines.push(clause.text);
|
|
898
|
+
lines.push("");
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
const sigs = listSignatures(id);
|
|
903
|
+
if (sigs.length > 0) {
|
|
904
|
+
lines.push("## Signatures");
|
|
905
|
+
lines.push("");
|
|
906
|
+
for (const sig of sigs) {
|
|
907
|
+
const email = sig.signer_email ? ` (${sig.signer_email})` : "";
|
|
908
|
+
lines.push(`- **${sig.signer_name}**${email} — ${sig.method} — ${sig.signed_at}`);
|
|
909
|
+
}
|
|
910
|
+
lines.push("");
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
const reminders = listReminders(id);
|
|
914
|
+
if (reminders.length > 0) {
|
|
915
|
+
lines.push("## Reminders");
|
|
916
|
+
lines.push("");
|
|
917
|
+
for (const r of reminders) {
|
|
918
|
+
const sent = r.sent ? " (sent)" : "";
|
|
919
|
+
lines.push(`- ${r.remind_at} — ${r.message}${sent}`);
|
|
920
|
+
}
|
|
921
|
+
lines.push("");
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
return lines.join("\n");
|
|
925
|
+
}
|