@dooer/dooer-test-env 1.0.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 (60) hide show
  1. package/bin/index.js +7 -0
  2. package/discovery-router/Dockerfile +18 -0
  3. package/discovery-router/README.md +99 -0
  4. package/discovery-router/package.json +13 -0
  5. package/discovery-router/registry.example.json +5 -0
  6. package/discovery-router/server.js +272 -0
  7. package/lib/account.js +120 -0
  8. package/lib/auth-dev-keys.js +12 -0
  9. package/lib/bankid.js +130 -0
  10. package/lib/cli.js +27 -0
  11. package/lib/command/bankid.js +45 -0
  12. package/lib/command/customer.js +108 -0
  13. package/lib/command/db.js +156 -0
  14. package/lib/command/env.js +114 -0
  15. package/lib/command/logs.js +143 -0
  16. package/lib/command/measure.js +81 -0
  17. package/lib/command/service.js +166 -0
  18. package/lib/command/setup.js +92 -0
  19. package/lib/command/shred.js +60 -0
  20. package/lib/compose/README.md +98 -0
  21. package/lib/compose/generate.js +375 -0
  22. package/lib/compose/manifests.js +108 -0
  23. package/lib/db/roles.js +118 -0
  24. package/lib/discovery/client.js +40 -0
  25. package/lib/engine/GUIDE.md +176 -0
  26. package/lib/engine/PROCESS.md +571 -0
  27. package/lib/engine/dbbuild.js +325 -0
  28. package/lib/engine/gen-schema-map.js +479 -0
  29. package/lib/engine/purge.js +137 -0
  30. package/lib/engine/schema-map.json +11016 -0
  31. package/lib/engine/seed.js +1045 -0
  32. package/lib/obc.js +72 -0
  33. package/lib/registry.js +123 -0
  34. package/lib/runtime.js +101 -0
  35. package/lib/service-token.js +40 -0
  36. package/lib/shred/README.md +118 -0
  37. package/lib/shred/audit.js +128 -0
  38. package/lib/shred/faker.js +545 -0
  39. package/lib/shred/index.js +126 -0
  40. package/lib/shred/scripts/base-partner-emails.sql +9 -0
  41. package/lib/shred/scripts/dev-accounts.sql +195 -0
  42. package/lib/shred/scripts/emails.sql +48 -0
  43. package/lib/shred/scripts/institution-browser.sql +3 -0
  44. package/lib/shred/scripts/notification-targets.sql +5 -0
  45. package/lib/shred/scripts/partners.sql +2 -0
  46. package/lib/shred/scripts/passwords.sql +8 -0
  47. package/lib/shred/scripts/personal-numbers.sql +177 -0
  48. package/lib/shred/scripts/phone-numbers.sql +22 -0
  49. package/lib/shred/scripts/salary-spec-reports.sql +5 -0
  50. package/lib/shred/scripts/service-activity-tracker-data.sql +4 -0
  51. package/lib/shred/scripts/service-core-objects.sql +19 -0
  52. package/lib/shred/scripts/service-event-stream.sql +2 -0
  53. package/lib/shred/scripts/service-integrations.sql +4 -0
  54. package/lib/shred/scripts/template.sql +4 -0
  55. package/lib/shred/scripts/x-service-billing.sql +34 -0
  56. package/lib/shred/scripts/xxx-history-tables.sql +25 -0
  57. package/lib/stub.js +8 -0
  58. package/local-postgres/Dockerfile +11 -0
  59. package/package.json +46 -0
  60. package/readme.md +92 -0
package/readme.md ADDED
@@ -0,0 +1,92 @@
1
+ # @dooer/dooer-test-env
2
+
3
+ One CLI to run the **entire Dooer backend locally** in Docker — every staging service + frontend, wired
4
+ together, backed by a **customer-free copy of the staging database** (reference data + anonymized users, no
5
+ organizations). Copy specific customers in when you need them, spin up empty test accounts, search logs
6
+ across the whole stack, and measure resource usage.
7
+
8
+ Runs on an Apple-Silicon Mac (images run under emulation) — 32 GB RAM / ~150 GB free disk is comfortable.
9
+ See **[ENVIRONMENT-PLAN.md](./ENVIRONMENT-PLAN.md)** for the full design and rationale.
10
+
11
+ ```bash
12
+ npx @dooer/dooer-test-env <command>
13
+ ```
14
+
15
+ ## Quick start
16
+
17
+ ```bash
18
+ # 1. One-time: prereq checks, registry login, compose generation, BankID cert → keychain.
19
+ # Needs the VPN + kubectl access to dooer-staging.
20
+ npx @dooer/dooer-test-env setup
21
+
22
+ # 2. Bring the whole stack up (all staging services + frontends)
23
+ npx @dooer/dooer-test-env up
24
+
25
+ # 3. Load the customer-free base DB (anonymized users + reference data, zero orgs)
26
+ npx @dooer/dooer-test-env db pull --execute
27
+
28
+ # 4. Status. HQ → http://localhost:8080, GraphQL gateway → http://localhost:4000
29
+ npx @dooer/dooer-test-env status
30
+ ```
31
+
32
+ ## Commands
33
+
34
+ ```
35
+ setup prereqs + registry login + compose + BankID cert → keychain
36
+ up [--profile full|booking|hq] create + start the stack (default full = everything staging runs)
37
+ stop | start | down [--volumes] stop / restart / tear down (optionally wipe the local DB)
38
+ status list services (and which are served from local code)
39
+ db pull --execute restore the newest customer-free base DB, then provision roles
40
+ db roles (re)create per-service DB roles + search_path (db pull runs it)
41
+ db snapshot <name> | db rollback <name> local restore points
42
+ customer new "<name>" --owner <userId> --execute empty functional account: company + Owner + subscriptions + partner dooer
43
+ customer copy | customer purge copy / delete one org between environments (emails anonymized)
44
+ shred anonymize the LOCAL db (localhost only)
45
+ bankid pull | status | clear BankID cert (staging → keychain), used by service-accounts
46
+ logs <pattern> [--since 5m] [--service x] [-i] search logs across ALL services (e.g. a transactionId). alias: search
47
+ measure sample docker stats → resource-usage report
48
+ service <start|stop|restart|deploy|local|unlocal|version> <name> per-service control
49
+ ```
50
+
51
+ Everything that writes is **dry-run by default**; add `--execute`. Run any command with `--help`.
52
+
53
+ ### Examples
54
+
55
+ ```bash
56
+ # an empty test account owned by a user, subscriptions like Ghost Inspector, under partner dooer
57
+ npx @dooer/dooer-test-env customer new "Test Bolag AB" --owner 203b9010-abb9-4f7c-9a5e-8bbf6f75ca7b --execute
58
+
59
+ # find where a transactionId showed up across the whole stack
60
+ npx @dooer/dooer-test-env logs 1374f61b-5b42-48e6-9b28-ac086b55ea53
61
+
62
+ # run one service from your checked-out code; peers follow via the discovery router
63
+ npx @dooer/dooer-test-env service local service-ledger
64
+ ```
65
+
66
+ ## How it works
67
+
68
+ - **Compose generator** (`lib/compose/`): translates the s-e032 k8s manifests → a docker-compose spec —
69
+ images verbatim from the two registries; DB/Redis/Kafka/S3 and secrets repointed at local infra.
70
+ - **Discovery router** (`discovery-router/`): answers the Consul health + session/KV API (single-node leader
71
+ election), so `@dooer/service` discovery and doode leadership work with no Consul. `service local`/`deploy`
72
+ repoint entries so peers pick up changes with no restarts.
73
+ - **Auth is self-contained**: the shared local dev keypair is forced on every verifier; service-accounts
74
+ signs with the matching key; per-service tokens are freshly minted with it (the baked config ones expired).
75
+ - **Per-service DB roles**: `db pull` recreates each service's role + schema `search_path` (mirroring
76
+ cli-cowboy's setup) so unqualified queries resolve — the base dump carries no cluster-global roles.
77
+ - **BankID**: `setup`/`bankid pull` copy the PFX from the staging secret into the macOS keychain; `up`
78
+ injects it so local login runs production BankID like staging.
79
+ - **Base DB**: built in-cluster (a k8s Job with its own scratch Postgres) — the 685 GB staging DB never
80
+ leaves the cluster. It schema-restores, full-copies only non-org reference tables + users, shreds +
81
+ PII-audits, and uploads the artifact to an OBC bucket; devs only `db pull`. The CronJob + OBC manifests
82
+ live with the other staging yaml in `new-infrastructure/kubernetes/environments/s-e032-onprem/`.
83
+
84
+ ## Safety
85
+
86
+ - `shred` from a dev machine is **localhost-only**.
87
+ - `customer copy`/`purge` and `db build` writing to `dooer-production` require `--confirm-production`.
88
+ - Customer emails are always anonymized (`testcustomer+<id>@dooer.com`).
89
+
90
+ ## Prerequisites
91
+
92
+ Docker (Desktop), `kubectl` with access to the `dooer-staging` namespace (VPN), and Node 18+.