pati-cli
v0.3.0
Published
Command-line interface for the PATI master app — disputes, sync, CS metrics.
Maintainers
Readme
pati-cli
Command-line interface cho PATI master app — xem số liệu business
(revenue, PnL, disputes, CS metrics, sync health) từ terminal. Đọc
data trực tiếp từ pnl.patigroup.com qua REST API.
Install
bun install -g pati-cli
# hoặc dùng bunx một lần:
bunx pati-cli dispute listSau khi publish lên npm. Trong lúc dev local:
cd cli
bun run dev dispute listAuth
pati auth loginCLI mở browser, anh login Lark như bình thường trên pnl.patigroup.com.
Sau khi login xong, browser tự bounce token về CLI qua localhost:<random-port>
và CLI lưu vào ~/.pati/config.json.
Nếu browser không mở tự động, copy URL CLI in ra và paste vào browser thủ công.
pati auth status # show config hiện tại
pati auth logout # xoá tokenEnv override khi cần (CI, debug):
export PATI_TOKEN=<jwt>
pati dispute listCommands
# Auth
pati auth login # browser Lark OAuth
pati auth status
pati auth logout
# Active store (multi-store)
pati shop list # ● = đang chọn
pati shop switch wellness-nest
pati shop active
pati shop clear
# Analytics (xem số doanh thu / PnL / ROAS)
pati analytics summary # 7 ngày: sales, orders, AOV, profit, ROAS, MER…
pati analytics summary --days 30
pati analytics summary --from 2026-05-01 --to 2026-05-28
pati analytics pnl # PnL line items + summary
pati analytics pnl --days 1 # hôm nay
pati analytics summary --json | jq
# Disputes (PayPal + Shopify Payments + Stripe)
pati dispute stats # tổng + per-gateway + win rate + dispute rate
pati dispute stats --days 30
pati dispute list # 15 mới nhất gộp 3 cổng
pati dispute list --status needs_response
pati dispute list --gateway paypal
pati dispute list --days 90 --limit 50
pati dispute list --json | jq
pati dispute show <id>
# CS metrics
pati cs metrics # 6 North-Star metrics
pati cs overdue # email backlog + overdue counts
# Cron / sync health
pati cron status # per-shop per-provider snapshot
pati cron status --shop wellness
pati sync-logs --limit 50
pati sync-logs --status error
pati sync-logs --type shopify --status error
pati --help # full reference
pati dispute --help # subcommand helpConfig
- File:
~/.pati/config.json(mode 0600) - Env override:
PATI_TOKEN,PATI_BASE_URL,PATI_SHOP_ID - Env wins over file. File wins over defaults.
Debug
PATI_DEBUG=1 pati dispute list # in stack trace khi errorBuild & ship
bun run build # node bundle dist/index.mjs
bun run build:binary # standalone executable dist/pati (~50MB)
bun run typecheckRoadmap
- [x] Phase 1: dispute list/show, auth scaffolding
- [x] Phase 2: OAuth login flow (
pati auth loginmở browser, Lark OAuth, localhost callback) - [x] Phase 3: shop · cs metrics/overdue · cron status · sync-logs
- [x] Phase 3.5: analytics summary/pnl · dispute stats · window flags (--from/--to/--days)
- [ ] Phase 4:
pati dispute upload-evidence,pati cron run <pipeline>,pati order get - [ ] Phase 5: single-binary GitHub Releases, Authorization Bearer native
Auth architecture
CLI Backend
─── ───────
pati auth login
├─ start HTTP server on random :PORT
├─ generate state token (16 bytes hex)
└─ open browser → /cli/auth?port=PORT&state=STATE
│
├─ has pati_session cookie?
│ ├─ yes → emit HTML redirecting to
│ │ http://localhost:PORT/callback?token=JWT&state=STATE
│ └─ no → 302 /api/auth/lark/start?next=/cli/auth?...
│ (after Lark login, callback restores `next` cookie
│ and redirects back to /cli/auth)
│
├─ receive callback ←─────────┘
├─ verify state matches
├─ save token to ~/.pati/config.json
└─ HTTP 200 "✓ Logged in, close this tab"Token forwarded only to localhost (browser controls destination). Random port
- state token + localhost binding prevent LAN snoop / CSRF / open redirect.
