@hasna/invoices 0.1.0 → 0.1.1

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.
Files changed (44) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +109 -62
  3. package/dashboard/dist/assets/index-BhR1BMmj.js +139 -0
  4. package/dashboard/dist/assets/index-khzrvnCp.css +1 -0
  5. package/dashboard/dist/index.html +13 -0
  6. package/dashboard/dist/logo.jpg +0 -0
  7. package/dist/cli/index.js +10111 -9633
  8. package/dist/cli/tui.d.ts +2 -0
  9. package/dist/cli/tui.d.ts.map +1 -0
  10. package/dist/db/agents.d.ts +19 -0
  11. package/dist/db/agents.d.ts.map +1 -0
  12. package/dist/db/cloud.d.ts +20 -0
  13. package/dist/db/cloud.d.ts.map +1 -0
  14. package/dist/db/core.test.d.ts +2 -0
  15. package/dist/db/core.test.d.ts.map +1 -0
  16. package/dist/db/database.d.ts +7 -8
  17. package/dist/db/database.d.ts.map +1 -1
  18. package/dist/db/invoices.d.ts +77 -90
  19. package/dist/db/invoices.d.ts.map +1 -1
  20. package/dist/db/migrate.d.ts +4 -0
  21. package/dist/db/migrate.d.ts.map +1 -0
  22. package/dist/db/pg.d.ts +3 -0
  23. package/dist/db/pg.d.ts.map +1 -0
  24. package/dist/db/schema.d.ts +6 -0
  25. package/dist/db/schema.d.ts.map +1 -0
  26. package/dist/index.d.ts +8 -7
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +1061 -510
  29. package/dist/lib/version.d.ts +2 -0
  30. package/dist/lib/version.d.ts.map +1 -0
  31. package/dist/mcp/index.d.ts +1 -1
  32. package/dist/mcp/index.js +1320 -766
  33. package/dist/server/index.d.ts +3 -0
  34. package/dist/server/index.d.ts.map +1 -0
  35. package/dist/server/index.js +14919 -0
  36. package/dist/types/index.d.ts +18 -0
  37. package/dist/types/index.d.ts.map +1 -0
  38. package/package.json +21 -14
  39. package/dist/db/business.d.ts +0 -93
  40. package/dist/db/business.d.ts.map +0 -1
  41. package/dist/db/clients.d.ts +0 -45
  42. package/dist/db/clients.d.ts.map +0 -1
  43. package/dist/db/migrations.d.ts +0 -7
  44. package/dist/db/migrations.d.ts.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 hasna
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,97 +1,144 @@
1
1
  # @hasna/invoices
2
2
 
3
- Invoice management for AI agents — CLI + MCP server with SQLite storage.
3
+ Invoice generation and management for AI agents.
4
4
 
5
- Supports multi-country tax rules, EU reverse charge, business profiles, client management, line items, and payment tracking.
5
+ `@hasna/invoices` ships four surfaces in one repo:
6
+ - CLI (`invoices`)
7
+ - MCP server (`invoices-mcp`)
8
+ - REST API server (`invoices-serve`)
9
+ - Web dashboard (`dashboard/`)
10
+ - Typed Web/Node SDK (`sdk/` as `@hasna/invoices-sdk`)
11
+
12
+ ## Features
13
+
14
+ - Local SQLite storage with WAL mode + migrations
15
+ - PostgreSQL migration support via `@hasna/cloud`
16
+ - Cloud sync push/pull between local SQLite and PostgreSQL
17
+ - Feedback delivery with remote send + local fallback persistence
18
+ - Invoice + line item CRUD with computed totals
19
+ - FTS5 search over invoice number, parties, and notes
20
+ - Agent registry (`register_agent`, `heartbeat`, `set_focus`, `list_agents`)
21
+ - MCP tools for invoice workflows
22
+ - Shadcn-based dashboard structure aligned with open-todos
6
23
 
7
24
  ## Install
8
25
 
9
26
  ```bash
10
- bun install -g @hasna/invoices
11
- # or
12
- npm install -g @hasna/invoices
27
+ bun add @hasna/invoices
13
28
  ```
14
29
 
15
- Data is stored at `~/.hasna/invoices/invoices.db`.
16
-
17
- Override with `HASNA_INVOICES_DIR` or `INVOICES_DIR` env variables.
18
-
19
30
  ## CLI
20
31
 
21
32
  ```bash
22
- # Create an invoice
23
- invoices create --client <id> --due 2026-04-30 --currency EUR
24
-
25
- # Add line items
26
- invoices add-item --invoice <id> --description "Consulting" --price 150 --quantity 8
33
+ # initialize local SQLite schema
34
+ invoices db:migrate
35
+
36
+ # initialize PostgreSQL schema translated from local migrations
37
+ invoices db:migrate:pg
38
+
39
+ # cloud sync (all tables by default)
40
+ invoices cloud:push
41
+ invoices cloud:pull
42
+
43
+ # optional subset
44
+ invoices cloud:push --tables parties,invoices,invoice_lines
45
+
46
+ # feedback
47
+ invoices feedback:send --message "SDK auth flow failed on staging"
48
+
49
+ # create parties
50
+ invoices party:create --kind issuer --name "Hasna SRL"
51
+ invoices party:create --kind customer --name "ACME GmbH"
52
+
53
+ # create invoice
54
+ invoices invoice:create \
55
+ --number INV-1001 \
56
+ --issuer-id <ISSUER_ID> \
57
+ --customer-id <CUSTOMER_ID> \
58
+ --currency EUR \
59
+ --line "Implementation:10:5000:1900"
60
+
61
+ # list/search/update
62
+ invoices invoice:list
63
+ invoices invoice:search "INV-1001"
64
+ invoices invoice:status <INVOICE_ID> sent
65
+
66
+ # agent lifecycle
67
+ invoices agent:register --name octavian
68
+ invoices agent:list
69
+ ```
27
70
 
28
- # Mark as sent / paid
29
- invoices mark <id> sent
30
- invoices mark <id> paid
71
+ ## REST API
31
72
 
32
- # Record a payment
33
- invoices pay --invoice <id> --amount 1200 --method bank_transfer
73
+ Run server:
34
74
 
35
- # Summary
36
- invoices summary
75
+ ```bash
76
+ invoices-serve
77
+ ```
37
78
 
38
- # Clients
39
- invoices client add --name "Acme Corp" --email billing@acme.com --country US
40
- invoices client list
79
+ Key endpoints:
41
80
 
42
- # Business profiles
43
- invoices business add --name "My Company SRL" --country RO --vat RO12345678 --default
44
- invoices business list
81
+ - `GET /health`
82
+ - `POST /api/migrate`
83
+ - `POST /api/migrate/pg`
84
+ - `POST /api/cloud/push`
85
+ - `POST /api/cloud/pull`
86
+ - `POST /api/feedback`
87
+ - `GET|POST /api/parties`
88
+ - `GET|POST /api/invoices`
89
+ - `GET /api/invoices/search?q=...`
90
+ - `POST /api/invoices/:id/status`
91
+ - `GET /api/stats`
92
+ - `GET|POST /api/agents`
93
+ - `POST /api/agents/:id/heartbeat`
94
+ - `POST /api/agents/:id/focus`
45
95
 
46
- # Tax rules
47
- invoices tax list --country RO
48
- invoices tax determine --issuer RO --client DE --vat DE123456789
49
- ```
96
+ ## MCP
50
97
 
51
- ## MCP Server
98
+ Run MCP stdio server:
52
99
 
53
- Add to your MCP config:
54
-
55
- ```json
56
- {
57
- "mcpServers": {
58
- "invoices": {
59
- "command": "invoices-mcp"
60
- }
61
- }
62
- }
100
+ ```bash
101
+ invoices-mcp
63
102
  ```
64
103
 
65
- ### MCP Tools
104
+ Core tools:
66
105
 
67
- **Invoices:** `create_invoice`, `get_invoice`, `list_invoices`, `update_invoice_status`, `delete_invoice`
106
+ - `migrate_database`, `migrate_postgres`
107
+ - `cloud_push`, `cloud_pull`, `send_feedback`
108
+ - `create_party`, `list_parties`
109
+ - `create_invoice`, `get_invoice`, `list_invoices`, `search_invoices`, `update_invoice_status`, `delete_invoice`
110
+ - `register_agent`, `heartbeat`, `set_focus`, `list_agents`
68
111
 
69
- **Line Items:** `add_line_item`, `remove_line_item`
112
+ ## Dashboard
70
113
 
71
- **Payments:** `record_payment`, `invoice_summary`
114
+ ```bash
115
+ cd dashboard
116
+ bun install
117
+ bun run dev
118
+ ```
72
119
 
73
- **Clients:** `create_client`, `list_clients`, `update_client`, `delete_client`
120
+ Set API base if needed:
74
121
 
75
- **Business Profiles:** `create_business_profile`, `get_business_profile`, `get_default_business_profile`, `list_business_profiles`, `update_business_profile`, `delete_business_profile`
122
+ ```bash
123
+ export VITE_API_BASE_URL=http://localhost:3487
124
+ ```
76
125
 
77
- **Tax:** `list_tax_rules`, `get_default_tax_rule`, `create_tax_rule`, `delete_tax_rule`, `determine_tax`
126
+ ## Security
78
127
 
79
- ## Features
128
+ - Optional API auth via `INVOICES_API_KEY`
129
+ - Optional CORS allowlist via `INVOICES_ALLOWED_ORIGIN`
130
+ - Security reports are stored under `reports/`
80
131
 
81
- - Auto-incrementing invoice numbers (`INV-00001`, `INV-00002`, ...)
82
- - Automatic total recalculation when line items change
83
- - Auto-marks invoice as paid when payments cover the total
84
- - 27 pre-seeded tax rules for EU, US, UK
85
- - EU B2B reverse charge detection
86
- - Business profiles with bank details (IBAN, SWIFT)
87
- - SQLite in WAL mode for concurrent access
88
- - No server required — embedded database
132
+ ## Development
89
133
 
90
- ## Storage
134
+ ```bash
135
+ bun install
136
+ cd dashboard && bun install && cd ..
137
+ cd sdk && bun install && cd ..
91
138
 
92
- ```
93
- ~/.hasna/invoices/
94
- └── invoices.db # SQLite database (WAL mode)
139
+ bun run typecheck
140
+ bun run build
141
+ bun test
95
142
  ```
96
143
 
97
144
  ## License