@nestica/cli 0.1.0

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -0
  3. package/dist/cli.js +19113 -0
  4. package/package.json +32 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gary Ascuy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # nestica-cli
2
+
3
+ Command-line client for the Nestica REST API (`nestica-api`): full CRUD
4
+ over `profiles`, `accounts`, `contacts`, `transactions` and `yields`,
5
+ plus session management (`login`, `logout`, `whoami`, `set-profile`).
6
+
7
+ ## Install
8
+
9
+ Published package: `npm install -g @nestica/cli` (zero runtime
10
+ dependencies — everything is bundled into the `nestica` binary).
11
+
12
+ From this repository:
13
+
14
+ ```sh
15
+ pnpm install
16
+ pnpm --filter @nestica/cli build
17
+ pnpm exec nestica --help
18
+ ```
19
+
20
+ The CLI talks to the deployed API by default
21
+ (`https://api-tjnuhxmzkq-uc.a.run.app/api/v1.0`); point it elsewhere
22
+ with `--base-url` or `NESTICA_BASE_URL`.
23
+
24
+ ## Sessions
25
+
26
+ State lives in one JSON file with owner-only permissions:
27
+ `${XDG_CONFIG_HOME:-~/.config}/nestica/config.json` (override the whole
28
+ path with `NESTICA_CONFIG`). It stores the connection settings, the
29
+ Firebase tokens and the default profile. Precedence for every setting:
30
+ **flag > environment > session file > default**.
31
+
32
+ | Setting | Flag | Environment | Default |
33
+ | --- | --- | --- | --- |
34
+ | API base URL | `-H, --base-url` | `NESTICA_BASE_URL` | deployed API |
35
+ | Firebase web API key | `--api-key` | `FIREBASE_API_KEY` | — |
36
+ | Google OAuth client id | `--google-client-id` | `GOOGLE_CLIENT_ID` | — |
37
+ | Google OAuth client secret | `--google-client-secret` | `GOOGLE_CLIENT_SECRET` | — |
38
+ | Auth emulator | — | `FIREBASE_AUTH_EMULATOR_HOST` | inferred from a localhost base URL |
39
+
40
+ Expired ID tokens refresh automatically before requests; when the
41
+ refresh token itself is rejected the CLI says so and asks for a new
42
+ `login`.
43
+
44
+ ## Commands
45
+
46
+ ```
47
+ nestica login [--email <email>] [--password <pw>] [--google] ...
48
+ nestica logout
49
+ nestica whoami
50
+ nestica set-profile [<id>] [--clear]
51
+
52
+ nestica <resource> list [--page <n>] [--page-size <n>] [--profile <uuid>]
53
+ nestica <resource> get <id>
54
+ nestica <resource> create [field flags] [--data <json|->]
55
+ nestica <resource> update <id> [field flags] [--data <json|->]
56
+ nestica <resource> delete <id>
57
+ ```
58
+
59
+ `<resource>` is `profiles | accounts | contacts | transactions |
60
+ yields`. Scoped resources send the stored default profile (or an
61
+ explicit `--profile`) as the `profileId` query parameter; `transactions
62
+ list` also takes `--type expense|income`.
63
+
64
+ Global flags: `-H/--base-url`, `--api-key`, `--profile`,
65
+ `-F/--format pretty|json|table` (default `pretty`), `--no-color`
66
+ (or `NO_COLOR`; color is also off when stdout is not a TTY).
67
+
68
+ ### login
69
+
70
+ - Email/password (prompted when omitted; the password is not echoed):
71
+ `nestica login --api-key <web-key> --email dev@example.com`
72
+ - Google, in the browser (OAuth + PKCE against a loopback redirect;
73
+ needs the Firebase project's web OAuth client id):
74
+ `nestica login --google --google-client-id <id> --api-key <key>`
75
+
76
+ `logout` deletes the session file.
77
+
78
+ ### set-profile
79
+
80
+ `nestica set-profile` lists the profiles and asks which one to make the
81
+ default; `nestica set-profile <uuid>` stores a specific one and
82
+ `--clear` removes it. The API would otherwise default to the first
83
+ profile created.
84
+
85
+ ### Field flags
86
+
87
+ Create/update bodies come from typed flags — identical rules to the
88
+ API, validated locally with `@nestica/models` — plus `--data` (or
89
+ `--json`) to merge a raw JSON body over them (`-` reads stdin):
90
+
91
+ ```sh
92
+ nestica profiles create --name Gary --country CO --timezone America/Bogota \
93
+ --currency COP --currency USD --default-currency COP
94
+
95
+ nestica accounts create --name Bancolombia --label bank
96
+
97
+ nestica transactions create --type expense --amount 42.5 --currency COP \
98
+ --date 2026-08-22T12:00:00Z --status settled --label groceries \
99
+ --foreign-amount '{"amount": 10, "currency": "USD"}'
100
+
101
+ nestica transactions update <id> --amount 50
102
+ ```
103
+
104
+ See `nestica <resource> create --help` for every flag; `--label`,
105
+ `--currency` (profiles) and other list flags are repeatable
106
+ (`--label a --label b`).
107
+
108
+ ### Output
109
+
110
+ - `--format pretty` (default): colorized, indented JSON.
111
+ - `--format json`: compact single-line JSON for shell pipelines
112
+ (`nestica accounts list --format json | jq -r '.data[0].id'`).
113
+ - `--format table`: column table for lists, key/value listing for
114
+ single records; the list summary goes to stderr so stdout stays
115
+ parseable.
116
+
117
+ Delete confirmations also go to stderr; with `--format json` deletes
118
+ print nothing at all.
119
+
120
+ ### Exit codes
121
+
122
+ `0` success · `1` API/runtime errors · `2` usage errors.
123
+
124
+ ## Smoke test against the emulators
125
+
126
+ ```sh
127
+ pnpm --filter nestica-api serve # functions :5001, firestore :8080, auth :9099
128
+ # create a user once in the Auth UI at http://localhost:4000
129
+
130
+ export FIREBASE_AUTH_EMULATOR_HOST=localhost:9099
131
+ pnpm exec nestica login \
132
+ --base-url http://localhost:5001/nestica-finances/us-central1/api/api/v1.0 \
133
+ --api-key demo --email dev@example.com
134
+
135
+ pnpm exec nestica profiles create --name Gary --country CO \
136
+ --timezone America/Bogota --currency COP --default-currency COP
137
+ pnpm exec nestica set-profile
138
+ pnpm exec nestica accounts create --name Bancolombia --label bank
139
+ pnpm exec nestica transactions create --type expense --amount 42.5 \
140
+ --currency COP --date 2026-08-22T12:00:00Z --status settled --label groceries
141
+ pnpm exec nestica transactions list --type expense --format table
142
+ pnpm exec nestica whoami
143
+ pnpm exec nestica logout
144
+ ```
145
+
146
+ Note: the Google flow always talks to the real Google endpoints — use
147
+ email/password with the emulators.
148
+
149
+ ## Tests
150
+
151
+ ```sh
152
+ pnpm --filter @nestica/cli test
153
+ ```
154
+
155
+ Unit tests only (mocked `fetch`, temporary session files); the
156
+ repository-wide `pnpm test` runs them through Nx.