@hasna/microservices 0.0.16 → 0.0.18
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/README.md +143 -23
- package/bin/index.js +784 -13987
- package/bin/mcp.js +298 -10973
- package/dist/index.js +251 -10056
- package/package.json +36 -26
- package/microservices/microservice-ads/package.json +0 -28
- package/microservices/microservice-ads/src/cli/index.ts +0 -605
- package/microservices/microservice-ads/src/db/campaigns.ts +0 -797
- package/microservices/microservice-ads/src/db/database.ts +0 -91
- package/microservices/microservice-ads/src/db/migrations.ts +0 -60
- package/microservices/microservice-ads/src/index.ts +0 -39
- package/microservices/microservice-ads/src/mcp/index.ts +0 -480
- package/microservices/microservice-analytics/package.json +0 -28
- package/microservices/microservice-analytics/src/cli/index.ts +0 -373
- package/microservices/microservice-analytics/src/db/analytics.ts +0 -564
- package/microservices/microservice-analytics/src/db/database.ts +0 -91
- package/microservices/microservice-analytics/src/db/migrations.ts +0 -50
- package/microservices/microservice-analytics/src/index.ts +0 -37
- package/microservices/microservice-analytics/src/mcp/index.ts +0 -334
- package/microservices/microservice-assets/package.json +0 -28
- package/microservices/microservice-assets/src/cli/index.ts +0 -375
- package/microservices/microservice-assets/src/db/assets.ts +0 -370
- package/microservices/microservice-assets/src/db/database.ts +0 -91
- package/microservices/microservice-assets/src/db/migrations.ts +0 -51
- package/microservices/microservice-assets/src/index.ts +0 -32
- package/microservices/microservice-assets/src/mcp/index.ts +0 -346
- package/microservices/microservice-bookkeeping/package.json +0 -28
- package/microservices/microservice-bookkeeping/src/cli/index.ts +0 -386
- package/microservices/microservice-bookkeeping/src/db/bookkeeping.ts +0 -591
- package/microservices/microservice-bookkeeping/src/db/database.ts +0 -91
- package/microservices/microservice-bookkeeping/src/db/migrations.ts +0 -52
- package/microservices/microservice-bookkeeping/src/index.ts +0 -32
- package/microservices/microservice-bookkeeping/src/mcp/index.ts +0 -284
- package/microservices/microservice-calendar/package.json +0 -28
- package/microservices/microservice-calendar/src/cli/index.ts +0 -287
- package/microservices/microservice-calendar/src/db/calendar.ts +0 -328
- package/microservices/microservice-calendar/src/db/database.ts +0 -91
- package/microservices/microservice-calendar/src/db/migrations.ts +0 -47
- package/microservices/microservice-calendar/src/index.ts +0 -24
- package/microservices/microservice-calendar/src/mcp/index.ts +0 -226
- package/microservices/microservice-company/package.json +0 -28
- package/microservices/microservice-company/src/cli/index.ts +0 -1126
- package/microservices/microservice-company/src/db/company.ts +0 -854
- package/microservices/microservice-company/src/db/database.ts +0 -91
- package/microservices/microservice-company/src/db/migrations.ts +0 -214
- package/microservices/microservice-company/src/db/workflow-migrations.ts +0 -44
- package/microservices/microservice-company/src/index.ts +0 -60
- package/microservices/microservice-company/src/lib/audit.ts +0 -168
- package/microservices/microservice-company/src/lib/finance.ts +0 -299
- package/microservices/microservice-company/src/lib/settings.ts +0 -85
- package/microservices/microservice-company/src/lib/workflows.ts +0 -698
- package/microservices/microservice-company/src/mcp/index.ts +0 -991
- package/microservices/microservice-compliance/package.json +0 -28
- package/microservices/microservice-compliance/src/cli/index.ts +0 -467
- package/microservices/microservice-compliance/src/db/compliance.ts +0 -633
- package/microservices/microservice-compliance/src/db/database.ts +0 -91
- package/microservices/microservice-compliance/src/db/migrations.ts +0 -63
- package/microservices/microservice-compliance/src/index.ts +0 -46
- package/microservices/microservice-compliance/src/mcp/index.ts +0 -438
- package/microservices/microservice-contacts/package.json +0 -28
- package/microservices/microservice-contacts/src/cli/index.ts +0 -393
- package/microservices/microservice-contacts/src/db/companies.ts +0 -167
- package/microservices/microservice-contacts/src/db/contacts.ts +0 -249
- package/microservices/microservice-contacts/src/db/database.ts +0 -91
- package/microservices/microservice-contacts/src/db/migrations.ts +0 -71
- package/microservices/microservice-contacts/src/db/relationships.ts +0 -53
- package/microservices/microservice-contacts/src/index.ts +0 -42
- package/microservices/microservice-contacts/src/mcp/index.ts +0 -303
- package/microservices/microservice-contracts/package.json +0 -28
- package/microservices/microservice-contracts/src/cli/index.ts +0 -770
- package/microservices/microservice-contracts/src/db/contracts.ts +0 -925
- package/microservices/microservice-contracts/src/db/database.ts +0 -91
- package/microservices/microservice-contracts/src/db/migrations.ts +0 -141
- package/microservices/microservice-contracts/src/index.ts +0 -43
- package/microservices/microservice-contracts/src/mcp/index.ts +0 -617
- package/microservices/microservice-crm/package.json +0 -28
- package/microservices/microservice-crm/src/cli/index.ts +0 -396
- package/microservices/microservice-crm/src/db/database.ts +0 -91
- package/microservices/microservice-crm/src/db/migrations.ts +0 -66
- package/microservices/microservice-crm/src/db/pipeline.ts +0 -397
- package/microservices/microservice-crm/src/index.ts +0 -34
- package/microservices/microservice-crm/src/mcp/index.ts +0 -294
- package/microservices/microservice-documents/package.json +0 -28
- package/microservices/microservice-documents/src/cli/index.ts +0 -246
- package/microservices/microservice-documents/src/db/database.ts +0 -91
- package/microservices/microservice-documents/src/db/documents.ts +0 -316
- package/microservices/microservice-documents/src/db/migrations.ts +0 -49
- package/microservices/microservice-documents/src/index.ts +0 -24
- package/microservices/microservice-documents/src/mcp/index.ts +0 -202
- package/microservices/microservice-domains/package.json +0 -28
- package/microservices/microservice-domains/src/cli/index.ts +0 -1111
- package/microservices/microservice-domains/src/db/database.ts +0 -91
- package/microservices/microservice-domains/src/db/domains.ts +0 -1164
- package/microservices/microservice-domains/src/db/migrations.ts +0 -60
- package/microservices/microservice-domains/src/index.ts +0 -65
- package/microservices/microservice-domains/src/lib/brandsight.ts +0 -350
- package/microservices/microservice-domains/src/lib/godaddy.ts +0 -338
- package/microservices/microservice-domains/src/lib/namecheap.ts +0 -262
- package/microservices/microservice-domains/src/lib/registrar.ts +0 -355
- package/microservices/microservice-domains/src/mcp/index.ts +0 -781
- package/microservices/microservice-expenses/package.json +0 -28
- package/microservices/microservice-expenses/src/cli/index.ts +0 -267
- package/microservices/microservice-expenses/src/db/database.ts +0 -91
- package/microservices/microservice-expenses/src/db/expenses.ts +0 -345
- package/microservices/microservice-expenses/src/db/migrations.ts +0 -45
- package/microservices/microservice-expenses/src/index.ts +0 -25
- package/microservices/microservice-expenses/src/mcp/index.ts +0 -196
- package/microservices/microservice-habits/package.json +0 -28
- package/microservices/microservice-habits/src/cli/index.ts +0 -315
- package/microservices/microservice-habits/src/db/database.ts +0 -91
- package/microservices/microservice-habits/src/db/habits.ts +0 -451
- package/microservices/microservice-habits/src/db/migrations.ts +0 -46
- package/microservices/microservice-habits/src/index.ts +0 -31
- package/microservices/microservice-habits/src/mcp/index.ts +0 -313
- package/microservices/microservice-health/package.json +0 -28
- package/microservices/microservice-health/src/cli/index.ts +0 -484
- package/microservices/microservice-health/src/db/database.ts +0 -91
- package/microservices/microservice-health/src/db/health.ts +0 -708
- package/microservices/microservice-health/src/db/migrations.ts +0 -70
- package/microservices/microservice-health/src/index.ts +0 -63
- package/microservices/microservice-health/src/mcp/index.ts +0 -437
- package/microservices/microservice-hiring/package.json +0 -28
- package/microservices/microservice-hiring/src/cli/index.ts +0 -741
- package/microservices/microservice-hiring/src/db/database.ts +0 -91
- package/microservices/microservice-hiring/src/db/hiring.ts +0 -1085
- package/microservices/microservice-hiring/src/db/migrations.ts +0 -89
- package/microservices/microservice-hiring/src/index.ts +0 -80
- package/microservices/microservice-hiring/src/lib/scoring.ts +0 -206
- package/microservices/microservice-hiring/src/mcp/index.ts +0 -709
- package/microservices/microservice-inventory/package.json +0 -28
- package/microservices/microservice-inventory/src/cli/index.ts +0 -365
- package/microservices/microservice-inventory/src/db/database.ts +0 -91
- package/microservices/microservice-inventory/src/db/inventory.ts +0 -393
- package/microservices/microservice-inventory/src/db/migrations.ts +0 -54
- package/microservices/microservice-inventory/src/index.ts +0 -28
- package/microservices/microservice-inventory/src/mcp/index.ts +0 -250
- package/microservices/microservice-invoices/dashboard/index.html +0 -12
- package/microservices/microservice-invoices/dashboard/package.json +0 -29
- package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
- package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
- package/microservices/microservice-invoices/package.json +0 -31
- package/microservices/microservice-invoices/src/cli/index.ts +0 -308
- package/microservices/microservice-invoices/src/db/business.ts +0 -241
- package/microservices/microservice-invoices/src/db/clients.ts +0 -127
- package/microservices/microservice-invoices/src/db/database.ts +0 -91
- package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
- package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
- package/microservices/microservice-invoices/src/index.ts +0 -56
- package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
- package/microservices/microservice-invoices/src/server/index.ts +0 -162
- package/microservices/microservice-leads/package.json +0 -28
- package/microservices/microservice-leads/src/cli/index.ts +0 -596
- package/microservices/microservice-leads/src/db/database.ts +0 -91
- package/microservices/microservice-leads/src/db/leads.ts +0 -520
- package/microservices/microservice-leads/src/db/lists.ts +0 -151
- package/microservices/microservice-leads/src/db/migrations.ts +0 -93
- package/microservices/microservice-leads/src/index.ts +0 -65
- package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
- package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
- package/microservices/microservice-leads/src/mcp/index.ts +0 -533
- package/microservices/microservice-notes/package.json +0 -28
- package/microservices/microservice-notes/src/cli/index.ts +0 -63
- package/microservices/microservice-notes/src/db/database.ts +0 -91
- package/microservices/microservice-notes/src/db/migrations.ts +0 -40
- package/microservices/microservice-notes/src/db/notes.ts +0 -114
- package/microservices/microservice-notes/src/index.ts +0 -2
- package/microservices/microservice-notes/src/mcp/index.ts +0 -37
- package/microservices/microservice-notifications/package.json +0 -28
- package/microservices/microservice-notifications/src/cli/index.ts +0 -349
- package/microservices/microservice-notifications/src/db/database.ts +0 -91
- package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
- package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
- package/microservices/microservice-notifications/src/index.ts +0 -41
- package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
- package/microservices/microservice-payments/package.json +0 -28
- package/microservices/microservice-payments/src/cli/index.ts +0 -609
- package/microservices/microservice-payments/src/db/database.ts +0 -91
- package/microservices/microservice-payments/src/db/migrations.ts +0 -81
- package/microservices/microservice-payments/src/db/payments.ts +0 -1204
- package/microservices/microservice-payments/src/index.ts +0 -51
- package/microservices/microservice-payments/src/mcp/index.ts +0 -683
- package/microservices/microservice-payroll/package.json +0 -28
- package/microservices/microservice-payroll/src/cli/index.ts +0 -643
- package/microservices/microservice-payroll/src/db/database.ts +0 -91
- package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
- package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
- package/microservices/microservice-payroll/src/index.ts +0 -48
- package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
- package/microservices/microservice-products/package.json +0 -28
- package/microservices/microservice-products/src/cli/index.ts +0 -416
- package/microservices/microservice-products/src/db/categories.ts +0 -154
- package/microservices/microservice-products/src/db/database.ts +0 -91
- package/microservices/microservice-products/src/db/migrations.ts +0 -58
- package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
- package/microservices/microservice-products/src/db/products.ts +0 -452
- package/microservices/microservice-products/src/index.ts +0 -53
- package/microservices/microservice-products/src/mcp/index.ts +0 -453
- package/microservices/microservice-projects/package.json +0 -28
- package/microservices/microservice-projects/src/cli/index.ts +0 -480
- package/microservices/microservice-projects/src/db/database.ts +0 -91
- package/microservices/microservice-projects/src/db/migrations.ts +0 -65
- package/microservices/microservice-projects/src/db/projects.ts +0 -715
- package/microservices/microservice-projects/src/index.ts +0 -57
- package/microservices/microservice-projects/src/mcp/index.ts +0 -501
- package/microservices/microservice-proposals/package.json +0 -28
- package/microservices/microservice-proposals/src/cli/index.ts +0 -400
- package/microservices/microservice-proposals/src/db/database.ts +0 -91
- package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
- package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
- package/microservices/microservice-proposals/src/index.ts +0 -37
- package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
- package/microservices/microservice-reading/package.json +0 -28
- package/microservices/microservice-reading/src/cli/index.ts +0 -464
- package/microservices/microservice-reading/src/db/database.ts +0 -91
- package/microservices/microservice-reading/src/db/migrations.ts +0 -59
- package/microservices/microservice-reading/src/db/reading.ts +0 -524
- package/microservices/microservice-reading/src/index.ts +0 -51
- package/microservices/microservice-reading/src/mcp/index.ts +0 -368
- package/microservices/microservice-shipping/package.json +0 -28
- package/microservices/microservice-shipping/src/cli/index.ts +0 -606
- package/microservices/microservice-shipping/src/db/database.ts +0 -91
- package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
- package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
- package/microservices/microservice-shipping/src/index.ts +0 -53
- package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
- package/microservices/microservice-social/package.json +0 -29
- package/microservices/microservice-social/src/cli/index.ts +0 -1583
- package/microservices/microservice-social/src/db/database.ts +0 -91
- package/microservices/microservice-social/src/db/migrations.ts +0 -160
- package/microservices/microservice-social/src/db/social.ts +0 -1076
- package/microservices/microservice-social/src/index.ts +0 -46
- package/microservices/microservice-social/src/lib/audience.ts +0 -353
- package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
- package/microservices/microservice-social/src/lib/media.ts +0 -311
- package/microservices/microservice-social/src/lib/mentions.ts +0 -434
- package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
- package/microservices/microservice-social/src/lib/publisher.ts +0 -377
- package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
- package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
- package/microservices/microservice-social/src/lib/threads.ts +0 -291
- package/microservices/microservice-social/src/mcp/index.ts +0 -1425
- package/microservices/microservice-social/src/server/index.ts +0 -441
- package/microservices/microservice-subscriptions/package.json +0 -28
- package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
- package/microservices/microservice-subscriptions/src/db/database.ts +0 -91
- package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
- package/microservices/microservice-subscriptions/src/index.ts +0 -41
- package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
- package/microservices/microservice-timesheets/package.json +0 -28
- package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
- package/microservices/microservice-timesheets/src/db/database.ts +0 -91
- package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
- package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
- package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
- package/microservices/microservice-timesheets/src/index.ts +0 -44
- package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
- package/microservices/microservice-transcriber/package.json +0 -29
- package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
- package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
- package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
- package/microservices/microservice-transcriber/src/db/database.ts +0 -91
- package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
- package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
- package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
- package/microservices/microservice-transcriber/src/index.ts +0 -43
- package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
- package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
- package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
- package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
- package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
- package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
- package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
- package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
- package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
- package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
- package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
- package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
- package/microservices/microservice-transcriber/src/server/index.ts +0 -199
- package/microservices/microservice-travel/package.json +0 -28
- package/microservices/microservice-travel/src/cli/index.ts +0 -505
- package/microservices/microservice-travel/src/db/database.ts +0 -91
- package/microservices/microservice-travel/src/db/migrations.ts +0 -77
- package/microservices/microservice-travel/src/db/travel.ts +0 -802
- package/microservices/microservice-travel/src/index.ts +0 -60
- package/microservices/microservice-travel/src/mcp/index.ts +0 -495
- package/microservices/microservice-wiki/package.json +0 -28
- package/microservices/microservice-wiki/src/cli/index.ts +0 -345
- package/microservices/microservice-wiki/src/db/database.ts +0 -91
- package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
- package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
- package/microservices/microservice-wiki/src/index.ts +0 -32
- package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Contact CRUD operations
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { getDatabase } from "./database.js";
|
|
6
|
-
|
|
7
|
-
export interface Contact {
|
|
8
|
-
id: string;
|
|
9
|
-
first_name: string;
|
|
10
|
-
last_name: string | null;
|
|
11
|
-
email: string | null;
|
|
12
|
-
phone: string | null;
|
|
13
|
-
company_id: string | null;
|
|
14
|
-
title: string | null;
|
|
15
|
-
notes: string | null;
|
|
16
|
-
tags: string[];
|
|
17
|
-
metadata: Record<string, unknown>;
|
|
18
|
-
created_at: string;
|
|
19
|
-
updated_at: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface ContactRow {
|
|
23
|
-
id: string;
|
|
24
|
-
first_name: string;
|
|
25
|
-
last_name: string | null;
|
|
26
|
-
email: string | null;
|
|
27
|
-
phone: string | null;
|
|
28
|
-
company_id: string | null;
|
|
29
|
-
title: string | null;
|
|
30
|
-
notes: string | null;
|
|
31
|
-
tags: string;
|
|
32
|
-
metadata: string;
|
|
33
|
-
created_at: string;
|
|
34
|
-
updated_at: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function rowToContact(row: ContactRow): Contact {
|
|
38
|
-
return {
|
|
39
|
-
...row,
|
|
40
|
-
tags: JSON.parse(row.tags || "[]"),
|
|
41
|
-
metadata: JSON.parse(row.metadata || "{}"),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface CreateContactInput {
|
|
46
|
-
first_name: string;
|
|
47
|
-
last_name?: string;
|
|
48
|
-
email?: string;
|
|
49
|
-
phone?: string;
|
|
50
|
-
company_id?: string;
|
|
51
|
-
title?: string;
|
|
52
|
-
notes?: string;
|
|
53
|
-
tags?: string[];
|
|
54
|
-
metadata?: Record<string, unknown>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function createContact(input: CreateContactInput): Contact {
|
|
58
|
-
const db = getDatabase();
|
|
59
|
-
const id = crypto.randomUUID();
|
|
60
|
-
const tags = JSON.stringify(input.tags || []);
|
|
61
|
-
const metadata = JSON.stringify(input.metadata || {});
|
|
62
|
-
|
|
63
|
-
db.prepare(
|
|
64
|
-
`INSERT INTO contacts (id, first_name, last_name, email, phone, company_id, title, notes, tags, metadata)
|
|
65
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
66
|
-
).run(
|
|
67
|
-
id,
|
|
68
|
-
input.first_name,
|
|
69
|
-
input.last_name || null,
|
|
70
|
-
input.email || null,
|
|
71
|
-
input.phone || null,
|
|
72
|
-
input.company_id || null,
|
|
73
|
-
input.title || null,
|
|
74
|
-
input.notes || null,
|
|
75
|
-
tags,
|
|
76
|
-
metadata
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// Insert tags into junction table
|
|
80
|
-
if (input.tags?.length) {
|
|
81
|
-
const insertTag = db.prepare(
|
|
82
|
-
"INSERT OR IGNORE INTO contact_tags (contact_id, tag) VALUES (?, ?)"
|
|
83
|
-
);
|
|
84
|
-
for (const tag of input.tags) {
|
|
85
|
-
insertTag.run(id, tag);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return getContact(id)!;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function getContact(id: string): Contact | null {
|
|
93
|
-
const db = getDatabase();
|
|
94
|
-
const row = db.prepare("SELECT * FROM contacts WHERE id = ?").get(id) as ContactRow | null;
|
|
95
|
-
return row ? rowToContact(row) : null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface ListContactsOptions {
|
|
99
|
-
search?: string;
|
|
100
|
-
tag?: string;
|
|
101
|
-
company_id?: string;
|
|
102
|
-
limit?: number;
|
|
103
|
-
offset?: number;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function listContacts(options: ListContactsOptions = {}): Contact[] {
|
|
107
|
-
const db = getDatabase();
|
|
108
|
-
const conditions: string[] = [];
|
|
109
|
-
const params: unknown[] = [];
|
|
110
|
-
|
|
111
|
-
if (options.search) {
|
|
112
|
-
conditions.push(
|
|
113
|
-
"(first_name LIKE ? OR last_name LIKE ? OR email LIKE ? OR phone LIKE ?)"
|
|
114
|
-
);
|
|
115
|
-
const q = `%${options.search}%`;
|
|
116
|
-
params.push(q, q, q, q);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (options.tag) {
|
|
120
|
-
conditions.push(
|
|
121
|
-
"id IN (SELECT contact_id FROM contact_tags WHERE tag = ?)"
|
|
122
|
-
);
|
|
123
|
-
params.push(options.tag);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (options.company_id) {
|
|
127
|
-
conditions.push("company_id = ?");
|
|
128
|
-
params.push(options.company_id);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
let sql = "SELECT * FROM contacts";
|
|
132
|
-
if (conditions.length > 0) {
|
|
133
|
-
sql += " WHERE " + conditions.join(" AND ");
|
|
134
|
-
}
|
|
135
|
-
sql += " ORDER BY last_name, first_name";
|
|
136
|
-
|
|
137
|
-
if (options.limit) {
|
|
138
|
-
sql += " LIMIT ?";
|
|
139
|
-
params.push(options.limit);
|
|
140
|
-
}
|
|
141
|
-
if (options.offset) {
|
|
142
|
-
sql += " OFFSET ?";
|
|
143
|
-
params.push(options.offset);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const rows = db.prepare(sql).all(...params) as ContactRow[];
|
|
147
|
-
return rows.map(rowToContact);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface UpdateContactInput {
|
|
151
|
-
first_name?: string;
|
|
152
|
-
last_name?: string;
|
|
153
|
-
email?: string;
|
|
154
|
-
phone?: string;
|
|
155
|
-
company_id?: string | null;
|
|
156
|
-
title?: string;
|
|
157
|
-
notes?: string;
|
|
158
|
-
tags?: string[];
|
|
159
|
-
metadata?: Record<string, unknown>;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function updateContact(
|
|
163
|
-
id: string,
|
|
164
|
-
input: UpdateContactInput
|
|
165
|
-
): Contact | null {
|
|
166
|
-
const db = getDatabase();
|
|
167
|
-
const existing = getContact(id);
|
|
168
|
-
if (!existing) return null;
|
|
169
|
-
|
|
170
|
-
const sets: string[] = [];
|
|
171
|
-
const params: unknown[] = [];
|
|
172
|
-
|
|
173
|
-
if (input.first_name !== undefined) {
|
|
174
|
-
sets.push("first_name = ?");
|
|
175
|
-
params.push(input.first_name);
|
|
176
|
-
}
|
|
177
|
-
if (input.last_name !== undefined) {
|
|
178
|
-
sets.push("last_name = ?");
|
|
179
|
-
params.push(input.last_name);
|
|
180
|
-
}
|
|
181
|
-
if (input.email !== undefined) {
|
|
182
|
-
sets.push("email = ?");
|
|
183
|
-
params.push(input.email);
|
|
184
|
-
}
|
|
185
|
-
if (input.phone !== undefined) {
|
|
186
|
-
sets.push("phone = ?");
|
|
187
|
-
params.push(input.phone);
|
|
188
|
-
}
|
|
189
|
-
if (input.company_id !== undefined) {
|
|
190
|
-
sets.push("company_id = ?");
|
|
191
|
-
params.push(input.company_id);
|
|
192
|
-
}
|
|
193
|
-
if (input.title !== undefined) {
|
|
194
|
-
sets.push("title = ?");
|
|
195
|
-
params.push(input.title);
|
|
196
|
-
}
|
|
197
|
-
if (input.notes !== undefined) {
|
|
198
|
-
sets.push("notes = ?");
|
|
199
|
-
params.push(input.notes);
|
|
200
|
-
}
|
|
201
|
-
if (input.tags !== undefined) {
|
|
202
|
-
sets.push("tags = ?");
|
|
203
|
-
params.push(JSON.stringify(input.tags));
|
|
204
|
-
|
|
205
|
-
// Update junction table
|
|
206
|
-
db.prepare("DELETE FROM contact_tags WHERE contact_id = ?").run(id);
|
|
207
|
-
const insertTag = db.prepare(
|
|
208
|
-
"INSERT OR IGNORE INTO contact_tags (contact_id, tag) VALUES (?, ?)"
|
|
209
|
-
);
|
|
210
|
-
for (const tag of input.tags) {
|
|
211
|
-
insertTag.run(id, tag);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (input.metadata !== undefined) {
|
|
215
|
-
sets.push("metadata = ?");
|
|
216
|
-
params.push(JSON.stringify(input.metadata));
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (sets.length === 0) return existing;
|
|
220
|
-
|
|
221
|
-
sets.push("updated_at = datetime('now')");
|
|
222
|
-
params.push(id);
|
|
223
|
-
|
|
224
|
-
db.prepare(
|
|
225
|
-
`UPDATE contacts SET ${sets.join(", ")} WHERE id = ?`
|
|
226
|
-
).run(...params);
|
|
227
|
-
|
|
228
|
-
return getContact(id);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export function deleteContact(id: string): boolean {
|
|
232
|
-
const db = getDatabase();
|
|
233
|
-
const result = db.prepare("DELETE FROM contacts WHERE id = ?").run(id);
|
|
234
|
-
return result.changes > 0;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export function countContacts(): number {
|
|
238
|
-
const db = getDatabase();
|
|
239
|
-
const row = db.prepare("SELECT COUNT(*) as count FROM contacts").get() as { count: number };
|
|
240
|
-
return row.count;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function searchContacts(query: string): Contact[] {
|
|
244
|
-
return listContacts({ search: query });
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export function getContactsByTag(tag: string): Contact[] {
|
|
248
|
-
return listContacts({ tag });
|
|
249
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database connection for microservice-contacts
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { SqliteAdapter } from "@hasna/cloud";
|
|
6
|
-
import type { Database } from "bun:sqlite";
|
|
7
|
-
import { existsSync, mkdirSync, cpSync } from "node:fs";
|
|
8
|
-
import { dirname, join, resolve } from "node:path";
|
|
9
|
-
import { MIGRATIONS } from "./migrations.js";
|
|
10
|
-
|
|
11
|
-
let _db: Database | null = null;
|
|
12
|
-
|
|
13
|
-
function getDbPath(): string {
|
|
14
|
-
const explicit = process.env["HASNA_MICROSERVICES_DIR"] ?? process.env["MICROSERVICES_DIR"];
|
|
15
|
-
if (explicit) {
|
|
16
|
-
return join(explicit, "microservice-contacts", "data.db");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let dir = resolve(process.cwd());
|
|
20
|
-
while (true) {
|
|
21
|
-
const msDir = join(dir, ".microservices");
|
|
22
|
-
if (existsSync(msDir)) return join(msDir, "microservice-contacts", "data.db");
|
|
23
|
-
const parent = dirname(dir);
|
|
24
|
-
if (parent === dir) break;
|
|
25
|
-
dir = parent;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
29
|
-
const newDir = join(home, ".hasna", "microservices");
|
|
30
|
-
const oldDir = join(home, ".microservices");
|
|
31
|
-
if (!existsSync(newDir) && existsSync(oldDir)) {
|
|
32
|
-
mkdirSync(join(home, ".hasna"), { recursive: true });
|
|
33
|
-
cpSync(oldDir, newDir, { recursive: true });
|
|
34
|
-
}
|
|
35
|
-
return join(newDir, "microservice-contacts", "data.db");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function getDatabase(): Database {
|
|
39
|
-
if (_db) return _db;
|
|
40
|
-
|
|
41
|
-
const dbPath = getDbPath();
|
|
42
|
-
const dir = dirname(resolve(dbPath));
|
|
43
|
-
if (!existsSync(dir)) {
|
|
44
|
-
mkdirSync(dir, { recursive: true });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const adapter = new SqliteAdapter(dbPath);
|
|
48
|
-
_db = adapter.raw;
|
|
49
|
-
// SqliteAdapter already sets WAL and foreign_keys
|
|
50
|
-
|
|
51
|
-
_db.exec(`
|
|
52
|
-
CREATE TABLE IF NOT EXISTS _migrations (
|
|
53
|
-
id INTEGER PRIMARY KEY,
|
|
54
|
-
name TEXT NOT NULL,
|
|
55
|
-
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
56
|
-
)
|
|
57
|
-
`);
|
|
58
|
-
|
|
59
|
-
const applied = _db
|
|
60
|
-
.query("SELECT id FROM _migrations ORDER BY id")
|
|
61
|
-
.all() as { id: number }[];
|
|
62
|
-
const appliedIds = new Set(applied.map((r) => r.id));
|
|
63
|
-
|
|
64
|
-
for (const migration of MIGRATIONS) {
|
|
65
|
-
if (appliedIds.has(migration.id)) continue;
|
|
66
|
-
|
|
67
|
-
_db.exec("BEGIN");
|
|
68
|
-
try {
|
|
69
|
-
_db.exec(migration.sql);
|
|
70
|
-
_db.prepare("INSERT INTO _migrations (id, name) VALUES (?, ?)").run(
|
|
71
|
-
migration.id,
|
|
72
|
-
migration.name
|
|
73
|
-
);
|
|
74
|
-
_db.exec("COMMIT");
|
|
75
|
-
} catch (error) {
|
|
76
|
-
_db.exec("ROLLBACK");
|
|
77
|
-
throw new Error(
|
|
78
|
-
`Migration ${migration.id} (${migration.name}) failed: ${error instanceof Error ? error.message : String(error)}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return _db;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function closeDatabase(): void {
|
|
87
|
-
if (_db) {
|
|
88
|
-
_db.close();
|
|
89
|
-
_db = null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
export interface MigrationEntry {
|
|
2
|
-
id: number;
|
|
3
|
-
name: string;
|
|
4
|
-
sql: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const MIGRATIONS: MigrationEntry[] = [
|
|
8
|
-
{
|
|
9
|
-
id: 1,
|
|
10
|
-
name: "initial_schema",
|
|
11
|
-
sql: `
|
|
12
|
-
CREATE TABLE IF NOT EXISTS companies (
|
|
13
|
-
id TEXT PRIMARY KEY,
|
|
14
|
-
name TEXT NOT NULL,
|
|
15
|
-
domain TEXT,
|
|
16
|
-
industry TEXT,
|
|
17
|
-
notes TEXT,
|
|
18
|
-
metadata TEXT NOT NULL DEFAULT '{}',
|
|
19
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
20
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
CREATE TABLE IF NOT EXISTS contacts (
|
|
24
|
-
id TEXT PRIMARY KEY,
|
|
25
|
-
first_name TEXT NOT NULL,
|
|
26
|
-
last_name TEXT,
|
|
27
|
-
email TEXT,
|
|
28
|
-
phone TEXT,
|
|
29
|
-
company_id TEXT REFERENCES companies(id) ON DELETE SET NULL,
|
|
30
|
-
title TEXT,
|
|
31
|
-
notes TEXT,
|
|
32
|
-
tags TEXT NOT NULL DEFAULT '[]',
|
|
33
|
-
metadata TEXT NOT NULL DEFAULT '{}',
|
|
34
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
35
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
CREATE TABLE IF NOT EXISTS contact_tags (
|
|
39
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
40
|
-
tag TEXT NOT NULL,
|
|
41
|
-
PRIMARY KEY (contact_id, tag)
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
CREATE INDEX IF NOT EXISTS idx_contacts_email ON contacts(email);
|
|
45
|
-
CREATE INDEX IF NOT EXISTS idx_contacts_company ON contacts(company_id);
|
|
46
|
-
CREATE INDEX IF NOT EXISTS idx_contacts_name ON contacts(last_name, first_name);
|
|
47
|
-
CREATE INDEX IF NOT EXISTS idx_contact_tags_tag ON contact_tags(tag);
|
|
48
|
-
CREATE INDEX IF NOT EXISTS idx_companies_name ON companies(name);
|
|
49
|
-
CREATE INDEX IF NOT EXISTS idx_companies_domain ON companies(domain);
|
|
50
|
-
`,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: 2,
|
|
54
|
-
name: "add_relationships",
|
|
55
|
-
sql: `
|
|
56
|
-
CREATE TABLE IF NOT EXISTS relationships (
|
|
57
|
-
id TEXT PRIMARY KEY,
|
|
58
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
59
|
-
related_contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
60
|
-
type TEXT NOT NULL DEFAULT 'knows',
|
|
61
|
-
notes TEXT,
|
|
62
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
63
|
-
CHECK (contact_id != related_contact_id),
|
|
64
|
-
UNIQUE(contact_id, related_contact_id, type)
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
CREATE INDEX IF NOT EXISTS idx_relationships_contact ON relationships(contact_id);
|
|
68
|
-
CREATE INDEX IF NOT EXISTS idx_relationships_related ON relationships(related_contact_id);
|
|
69
|
-
`,
|
|
70
|
-
},
|
|
71
|
-
];
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Contact relationship operations
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { getDatabase } from "./database.js";
|
|
6
|
-
|
|
7
|
-
export interface Relationship {
|
|
8
|
-
id: string;
|
|
9
|
-
contact_id: string;
|
|
10
|
-
related_contact_id: string;
|
|
11
|
-
type: string;
|
|
12
|
-
notes: string | null;
|
|
13
|
-
created_at: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface CreateRelationshipInput {
|
|
17
|
-
contact_id: string;
|
|
18
|
-
related_contact_id: string;
|
|
19
|
-
type?: string;
|
|
20
|
-
notes?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function createRelationship(input: CreateRelationshipInput): Relationship {
|
|
24
|
-
const db = getDatabase();
|
|
25
|
-
const id = crypto.randomUUID();
|
|
26
|
-
|
|
27
|
-
db.prepare(
|
|
28
|
-
`INSERT INTO relationships (id, contact_id, related_contact_id, type, notes)
|
|
29
|
-
VALUES (?, ?, ?, ?, ?)`
|
|
30
|
-
).run(id, input.contact_id, input.related_contact_id, input.type || "knows", input.notes || null);
|
|
31
|
-
|
|
32
|
-
return getRelationship(id)!;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function getRelationship(id: string): Relationship | null {
|
|
36
|
-
const db = getDatabase();
|
|
37
|
-
return db.prepare("SELECT * FROM relationships WHERE id = ?").get(id) as Relationship | null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function getContactRelationships(contactId: string): Relationship[] {
|
|
41
|
-
const db = getDatabase();
|
|
42
|
-
return db
|
|
43
|
-
.prepare(
|
|
44
|
-
"SELECT * FROM relationships WHERE contact_id = ? OR related_contact_id = ? ORDER BY created_at"
|
|
45
|
-
)
|
|
46
|
-
.all(contactId, contactId) as Relationship[];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function deleteRelationship(id: string): boolean {
|
|
50
|
-
const db = getDatabase();
|
|
51
|
-
const result = db.prepare("DELETE FROM relationships WHERE id = ?").run(id);
|
|
52
|
-
return result.changes > 0;
|
|
53
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* microservice-contacts — Contact management microservice
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
createContact,
|
|
7
|
-
getContact,
|
|
8
|
-
listContacts,
|
|
9
|
-
updateContact,
|
|
10
|
-
deleteContact,
|
|
11
|
-
countContacts,
|
|
12
|
-
searchContacts,
|
|
13
|
-
getContactsByTag,
|
|
14
|
-
type Contact,
|
|
15
|
-
type CreateContactInput,
|
|
16
|
-
type UpdateContactInput,
|
|
17
|
-
type ListContactsOptions,
|
|
18
|
-
} from "./db/contacts.js";
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
createCompany,
|
|
22
|
-
getCompany,
|
|
23
|
-
listCompanies,
|
|
24
|
-
updateCompany,
|
|
25
|
-
deleteCompany,
|
|
26
|
-
countCompanies,
|
|
27
|
-
type Company,
|
|
28
|
-
type CreateCompanyInput,
|
|
29
|
-
type UpdateCompanyInput,
|
|
30
|
-
type ListCompaniesOptions,
|
|
31
|
-
} from "./db/companies.js";
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
createRelationship,
|
|
35
|
-
getRelationship,
|
|
36
|
-
getContactRelationships,
|
|
37
|
-
deleteRelationship,
|
|
38
|
-
type Relationship,
|
|
39
|
-
type CreateRelationshipInput,
|
|
40
|
-
} from "./db/relationships.js";
|
|
41
|
-
|
|
42
|
-
export { getDatabase, closeDatabase } from "./db/database.js";
|