@dooer/dooer-test-env 1.13.0 → 1.15.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.
package/readme.md CHANGED
@@ -53,6 +53,9 @@ db roles (re)create per-service DB role
53
53
  db snapshot <name> | db rollback <name> local restore points
54
54
  customer new "<name>" --owner <userId> --execute empty functional account: company + Owner + subscriptions + partner dooer
55
55
  customer copy | customer purge copy / delete one org between environments (emails anonymized)
56
+ remote-environment login|become|status|logout|list sign in to an environment; session → keychain
57
+ user search | get | create | partners find/inspect/create users (local env unless --env)
58
+ partner list | users | assign | unassign partners and who belongs to them, at which level
56
59
  shred anonymize the LOCAL db (localhost only)
57
60
  bankid pull | status | clear BankID cert (staging → keychain), used by service-accounts
58
61
  validation on | off | status output-schema validation (default OFF, like staging/live)
@@ -109,13 +112,113 @@ reads (`fiscalYear`, `hasVatRegistration`, `hasCompanyTax`, `hasEmployeeRegistra
109
112
  `vatPeriod`/`vatDue`). `--no-fiscal-year` leaves all of that blank.
110
113
 
111
114
  The owner must be a **`customer`** user — a `hi`/admin owner cannot accept Terms of Service and the command
112
- warns you. Find one with:
115
+ warns you. Find one:
113
116
 
114
- ```sql
115
- SELECT users_pk, email FROM service_accounts.users
116
- WHERE fk_user_roles_at_dooer_pk = 'customer' AND inactivated_at IS NULL LIMIT 5;
117
+ ```bash
118
+ npx @dooer/dooer-test-env@latest user search --role customer
117
119
  ```
118
120
 
121
+ ### Create a user you can actually log in as
122
+
123
+ ```bash
124
+ # an accounting professional (role `hi`) in the local env, password generated and printed once
125
+ npx @dooer/dooer-test-env@latest user create --email anna@dooer.com --execute
126
+
127
+ # …a customer instead, with your own password and a personnummer
128
+ npx @dooer/dooer-test-env@latest user create --email kim@example.com \
129
+ --role customer --password 'hunter2hunter2' --personnummer 19900101-1239 --execute
130
+
131
+ # …or an `hi` user placed straight into a partner
132
+ npx @dooer/dooer-test-env@latest user create --email anna@dooer.com \
133
+ --partner "Dooer Devteam" --level admin --execute
134
+ ```
135
+
136
+ This goes through `users.create` — the same mutation back-office's `/users/new` calls — so the service
137
+ hashes the password itself and applies its own input validation. The password works on the ordinary
138
+ email+password login, no BankID needed, and is shown **once**; there is no way to read it back. `--role`
139
+ defaults to `hi` (other choices: `customer`, `admin`) and names default to something derived from the
140
+ address.
141
+
142
+ The personnummer must be a **real** one: the API checks the Luhn digit, so an invented number is rejected
143
+ (the CLI checks it first and tells you which rule failed). Creating a user needs an **admin** session in a
144
+ remote environment — see below.
145
+
146
+ Look users up by email **or** id, and see where they belong:
147
+
148
+ ```bash
149
+ npx @dooer/dooer-test-env@latest user search anna # email, name, personnummer or id
150
+ npx @dooer/dooer-test-env@latest user get anna@dooer.com # details + partner memberships
151
+ ```
152
+
153
+ ### Partners and who belongs to them
154
+
155
+ ```bash
156
+ npx @dooer/dooer-test-env@latest partner list # every partner in the environment
157
+ npx @dooer/dooer-test-env@latest partner users "Dooer Devteam" # its users and their level
158
+
159
+ # add / promote / remove (a partner is addressable by id, name or domain)
160
+ npx @dooer/dooer-test-env@latest partner assign anna@dooer.com "Dooer Devteam" --level admin --execute
161
+ npx @dooer/dooer-test-env@latest partner unassign anna@dooer.com "Dooer Devteam" --execute
162
+ ```
163
+
164
+ `--level` is the membership level inside the partner (`member` or `admin`) — not the same thing as the
165
+ user's `--role` at Dooer. Only **`hi`** users can belong to a partner; the CLI applies the same
166
+ `invalid-user-type` check the service-accounts API does rather than writing a row HQ would choke on.
167
+
168
+ ### Look at (or fix) users in a real environment
169
+
170
+ The `user` and `partner` commands talk to an environment's **public GraphQL endpoint** — the same one the
171
+ frontends use — so reaching staging or live needs no VPN, no kubectl and no cluster credentials. It does
172
+ need a session. Sign in once per environment; the token is kept in your keychain:
173
+
174
+ ```bash
175
+ # BankID — exactly what HQ does, so you get your professional (hi) account
176
+ npx @dooer/dooer-test-env@latest remote-environment login --env staging
177
+
178
+ # email + password (prompted, hidden) — the only way to reach an ADMIN account
179
+ npx @dooer/dooer-test-env@latest remote-environment login --env staging --email you+admin@dooer.com
180
+
181
+ npx @dooer/dooer-test-env@latest remote-environment status --all # who you are, in every environment
182
+ npx @dooer/dooer-test-env@latest remote-environment logout --env staging
183
+ ```
184
+
185
+ Then point any command at it with `--env` (`local` is the default; `staging`, `production`, and aliases
186
+ like `dooer-staging` / `live` all resolve):
187
+
188
+ ```bash
189
+ npx @dooer/dooer-test-env@latest user search someone@dooer.com --env staging
190
+ npx @dooer/dooer-test-env@latest partner list --env production
191
+ ```
192
+
193
+ **Which account you sign in as decides what you can do**, because one person has several user rows:
194
+
195
+ | operation | needs | how to get it |
196
+ | --- | --- | --- |
197
+ | reads (`user search`, `user get`) | any session | either login |
198
+ | `partner assign` / `unassign` | a **partner** session | BankID login, or `become` from an admin session |
199
+ | `user create` | an **admin** session | password login as your admin account |
200
+
201
+ BankID cannot reach an admin account at all: `loginWithBankIdV2` is pinned to `user_type: 'customer'`
202
+ server-side, and HQ's partner flow resolves your `hi` user. When a session lacks the level, the CLI says
203
+ which one is required and who you are currently signed in as, rather than surfacing a raw `Forbidden`.
204
+
205
+ Signed in as an admin, you can assume a partner user without BankID — the same thing back-office's
206
+ **“Become user in X”** button does (`partner.user.become`, itself admin-gated):
207
+
208
+ ```bash
209
+ npx @dooer/dooer-test-env@latest remote-environment become someone@dooer.com --env staging
210
+ # …--partner "Dooer Devteam" if they belong to more than one
211
+
212
+ npx @dooer/dooer-test-env@latest remote-environment become --revert --env staging
213
+ ```
214
+
215
+ Becoming replaces the stored session, so the admin token that authorised it is stashed first and
216
+ `--revert` puts it back — otherwise you would have to log in again just to get where you were.
217
+
218
+ The local env needs no login — it is signed with the shared dev keypair this CLI already holds.
219
+
220
+ Writes are dry-run until `--execute`.
221
+
119
222
  ### Copy a real customer into the local env
120
223
 
121
224
  `--target-local` addresses this stack (Postgres on 55432 + MinIO); the source can be any k8s namespace