makea-cli 0.1.1__py3-none-any.whl
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.
- makea_cli/__init__.py +1 -0
- makea_cli/__main__.py +6 -0
- makea_cli/api_client.py +376 -0
- makea_cli/auth_pkce.py +251 -0
- makea_cli/commands/__init__.py +23 -0
- makea_cli/commands/_util.py +16 -0
- makea_cli/commands/auth/__init__.py +3 -0
- makea_cli/commands/auth/cmd.py +41 -0
- makea_cli/commands/directory/__init__.py +3 -0
- makea_cli/commands/directory/cmd.py +39 -0
- makea_cli/commands/document/__init__.py +3 -0
- makea_cli/commands/document/cmd.py +182 -0
- makea_cli/commands/email/__init__.py +3 -0
- makea_cli/commands/email/cmd.py +122 -0
- makea_cli/commands/metrics/__init__.py +0 -0
- makea_cli/commands/metrics/cmd.py +98 -0
- makea_cli/commands/orders/__init__.py +3 -0
- makea_cli/commands/orders/cmd.py +202 -0
- makea_cli/commands/product/__init__.py +3 -0
- makea_cli/commands/product/cmd.py +160 -0
- makea_cli/commands/supplier/__init__.py +3 -0
- makea_cli/commands/supplier/cmd.py +305 -0
- makea_cli/config.py +74 -0
- makea_cli/main.py +29 -0
- makea_cli-0.1.1.dist-info/METADATA +98 -0
- makea_cli-0.1.1.dist-info/RECORD +28 -0
- makea_cli-0.1.1.dist-info/WHEEL +4 -0
- makea_cli-0.1.1.dist-info/entry_points.txt +2 -0
makea_cli/config.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from platformdirs import user_config_dir
|
|
7
|
+
|
|
8
|
+
CONFIG_DIR = Path(user_config_dir("makea-cli", appauthor=False))
|
|
9
|
+
CREDENTIALS_PATH = CONFIG_DIR / "credentials.json"
|
|
10
|
+
|
|
11
|
+
# Production Makea API endpoints — built in so everyday users need no config.
|
|
12
|
+
# Optional MAKEA_* environment variables override these (e.g. staging); see README.
|
|
13
|
+
DEFAULT_API_BASE_URL = "https://api.makea.co"
|
|
14
|
+
DEFAULT_COGNITO_DOMAIN = "eu-west-1r9ghlpgky.auth.eu-west-1.amazoncognito.com"
|
|
15
|
+
DEFAULT_COGNITO_CLIENT_ID = "3nfj8g3et4o85kd6essas16vh0"
|
|
16
|
+
DEFAULT_REDIRECT_URI = "http://127.0.0.1:8250/callback"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _env(name: str, default: str | None = None) -> str | None:
|
|
20
|
+
v = os.environ.get(name)
|
|
21
|
+
if v is not None and v.strip() != "":
|
|
22
|
+
return v.strip()
|
|
23
|
+
return default
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def api_base_url() -> str:
|
|
27
|
+
base = _env("MAKEA_API_BASE_URL", DEFAULT_API_BASE_URL) or DEFAULT_API_BASE_URL
|
|
28
|
+
return base.rstrip("/")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def cognito_domain_host() -> str:
|
|
32
|
+
"""
|
|
33
|
+
Host only, e.g. my-pool.auth.us-east-1.amazoncognito.com
|
|
34
|
+
(no https://).
|
|
35
|
+
"""
|
|
36
|
+
d = _env("MAKEA_COGNITO_DOMAIN", DEFAULT_COGNITO_DOMAIN) or DEFAULT_COGNITO_DOMAIN
|
|
37
|
+
d = d.removeprefix("https://").removeprefix("http://").split("/")[0]
|
|
38
|
+
return d
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def cognito_client_id() -> str:
|
|
42
|
+
return (
|
|
43
|
+
_env("MAKEA_COGNITO_CLIENT_ID", DEFAULT_COGNITO_CLIENT_ID)
|
|
44
|
+
or DEFAULT_COGNITO_CLIENT_ID
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def redirect_uri() -> str:
|
|
49
|
+
return _env("MAKEA_REDIRECT_URI", DEFAULT_REDIRECT_URI) or DEFAULT_REDIRECT_URI
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def load_credentials() -> dict[str, Any] | None:
|
|
53
|
+
if not CREDENTIALS_PATH.is_file():
|
|
54
|
+
return None
|
|
55
|
+
try:
|
|
56
|
+
return json.loads(CREDENTIALS_PATH.read_text(encoding="utf-8"))
|
|
57
|
+
except (json.JSONDecodeError, OSError):
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def save_credentials(data: dict[str, Any]) -> None:
|
|
62
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
63
|
+
CREDENTIALS_PATH.write_text(json.dumps(data, indent=2), encoding="utf-8")
|
|
64
|
+
try:
|
|
65
|
+
CREDENTIALS_PATH.chmod(0o600)
|
|
66
|
+
except OSError:
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def clear_credentials() -> None:
|
|
71
|
+
try:
|
|
72
|
+
CREDENTIALS_PATH.unlink(missing_ok=True)
|
|
73
|
+
except OSError:
|
|
74
|
+
pass
|
makea_cli/main.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
from rich.console import Console
|
|
5
|
+
|
|
6
|
+
from makea_cli import __version__
|
|
7
|
+
from makea_cli.commands import register_all
|
|
8
|
+
|
|
9
|
+
console = Console()
|
|
10
|
+
app = typer.Typer(
|
|
11
|
+
name="makea-cli",
|
|
12
|
+
help=(
|
|
13
|
+
"Makea admin CLI: sign in once in the browser, then run commands. "
|
|
14
|
+
"No URL or API keys to configure. Most commands require an admin Makea account."
|
|
15
|
+
),
|
|
16
|
+
no_args_is_help=True,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
register_all(app)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@app.command("version", help="Print this CLI package version string.")
|
|
23
|
+
def version_cmd() -> None:
|
|
24
|
+
"""Print CLI version."""
|
|
25
|
+
console.print(__version__)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
app()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: makea-cli
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Makea admin CLI (browser login + Makea admin HTTP API)
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: httpx>=0.27
|
|
7
|
+
Requires-Dist: platformdirs>=4.2
|
|
8
|
+
Requires-Dist: rich>=13.7
|
|
9
|
+
Requires-Dist: typer>=0.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# makea-cli
|
|
13
|
+
|
|
14
|
+
给 **Makea** 内部同事用的命令行小工具:连的是线上正式环境,**装好就能用,不用配环境变量、不用改配置文件**。
|
|
15
|
+
|
|
16
|
+
第一次用时在浏览器里登录一次公司账号,之后在本机保存登录状态,即可查询用户、供应商等(具体能执行哪些命令取决于你的账号权限)。
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 怎么用(三步)
|
|
21
|
+
|
|
22
|
+
1. **安装**(本机需要已安装 [Python 3.10 或以上](https://www.python.org/downloads/))
|
|
23
|
+
- **从本仓库安装(开发 / 内网 clone):** 在 `makea-cli/` 目录执行
|
|
24
|
+
`python3 -m pip install -e .`
|
|
25
|
+
若提示找不到 `python3`,可改用 `python`。
|
|
26
|
+
- **不经过 GitHub:** 把本包的 **Python** 发行版发布到公司私有 PyPI / Artifact Registry 等,同事执行
|
|
27
|
+
`python3 -m pip install makea-cli`(或 `pipx install makea-cli`)即可;无需 clone 仓库。
|
|
28
|
+
- **可选 — 用 npm 只占一个全局命令名:** 仓库里 `npm/makea-cli/` 是一个 **薄封装**,`npm install -g` 后会把 `makea-cli` 指到 `python3 -m makea_cli`;**仍需**在同一台机器上先用 `pip` 装好同名 Python 包(npm 不会替你安装 Python 依赖)。适合已经用 npm 管理全局工具的团队。
|
|
29
|
+
2. **登录(只需做一次,或过期后再做)**
|
|
30
|
+
```bash
|
|
31
|
+
makea-cli auth
|
|
32
|
+
```
|
|
33
|
+
会自动打开浏览器,按公司流程登录即可。完成后可以关掉浏览器标签页。
|
|
34
|
+
3. **执行功能**(示例)
|
|
35
|
+
```bash
|
|
36
|
+
makea-cli list-users
|
|
37
|
+
makea-cli list-suppliers
|
|
38
|
+
makea-cli list-product-orders
|
|
39
|
+
makea-cli list-sampling-orders-by-product <product_reference_id>
|
|
40
|
+
makea-cli list-production-orders-by-product <product_reference_id>
|
|
41
|
+
```
|
|
42
|
+
**从「产品订单」JSON 下载附件:** `list-product-orders` 返回的每条 `result` 里已有 `user_id` 和 `available_documents`(含 `document_id`、`admin_user_id` 等),一般 **不必再调单独的 document metadata API**。可直接:
|
|
43
|
+
若只有 `product_reference_id`,可用(建议加上设计师 `user_id` 避免扫全库):
|
|
44
|
+
更多子命令与参数:
|
|
45
|
+
|
|
46
|
+
退出登录(清除本机保存的令牌):
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
makea-cli auth --logout
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 登录信息保存在哪
|
|
55
|
+
|
|
56
|
+
保存在本机当前用户下的应用数据目录里(例如 macOS 常见为 `~/Library/Application Support/makea-cli/`,Linux 常见为 `~/.config/makea-cli/`),文件名类似 `credentials.json`。一般不用手动打开。
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 给技术同事:可选环境变量
|
|
61
|
+
|
|
62
|
+
日常同事 **不需要** 看本节。只有要连 **非线上** 或 **自建环境** 时,才用环境变量覆盖内置地址(默认值在 `makea_cli/config.py` 里):
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
| 变量 | 说明 |
|
|
66
|
+
| ------------------------- | ---------------------------------------------- |
|
|
67
|
+
| `MAKEA_API_BASE_URL` | API 根地址(无末尾 `/`) |
|
|
68
|
+
| `MAKEA_COGNITO_DOMAIN` | Cognito Hosted UI 的**主机名**(不要写 `https://`) |
|
|
69
|
+
| `MAKEA_COGNITO_CLIENT_ID` | Cognito 应用客户端 ID |
|
|
70
|
+
| `MAKEA_REDIRECT_URI` | OAuth 回调地址,默认 `http://127.0.0.1:8250/callback` |
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 命令一览
|
|
76
|
+
|
|
77
|
+
- `makea-cli auth` — 浏览器登录并保存令牌
|
|
78
|
+
- `makea-cli auth --logout` — 清除本机令牌
|
|
79
|
+
- `makea-cli list-users` — 列出用户(需管理员权限)
|
|
80
|
+
- `makea-cli list-suppliers` — 列出供应商(需管理员权限)
|
|
81
|
+
- `makea-cli get-quote-requests-by-supplier-id <supplier_id> [--status <status>] [-n <limit>]` — 直连后端按 supplier_id 查询 quote requests
|
|
82
|
+
- `makea-cli get-supplier-links-by-supplier-id <supplier_id> [--link-type SAMPLING|PRODUCTION]` — 直连后端按 supplier_id 查询 supplier links
|
|
83
|
+
- `makea-cli list-product-orders` — 列出所有设计师产品订单(GET `/admin/designer/get_all_product_orders`)
|
|
84
|
+
- `makea-cli list-sampling-orders-by-product <id>` — 按产品 reference id 列打样单
|
|
85
|
+
- `makea-cli list-production-orders-by-product <id>` — 按产品 reference id 列大货单
|
|
86
|
+
- `makea-cli download-document <document_id> -u <user_id>` — 下载单个文件(GET `/admin/document/download`)
|
|
87
|
+
- `makea-cli download-product-document <product_reference_id> <document_id> -d <designer_user_id>` — 按产品行 + 文档 id 下载(内部用订单列表 JSON,不额外查 metadata)
|
|
88
|
+
- `makea-cli backfill-supplier-id --user-id <cognito_sub> --old-supplier-id <wrong_uuid>` — 供应商 `supplier_id` 迁到 Cognito `sub`(默认 dry-run,加 `--apply` 才写入;详见 `makea-cli backfill-supplier-id --help`)
|
|
89
|
+
- `makea-cli version` — 打印版本号
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Claude / Cursor skills(可选)
|
|
94
|
+
|
|
95
|
+
仓库内 `.claude/skills/` 下放有面向 agent 的操作说明,例如:
|
|
96
|
+
|
|
97
|
+
- `supplier-user-id-migration` — 供应商 ID 与 Cognito sub 对齐、与 `backfill-supplier-id` 配套
|
|
98
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
makea_cli/__init__.py,sha256=rnObPjuBcEStqSO0S6gsdS_ot8ITOQjVj_-P1LUUYpg,22
|
|
2
|
+
makea_cli/__main__.py,sha256=7BdV0s4m5cc7C-JcxJKPM2amGV37EIVIXu1pDSUpp7E,142
|
|
3
|
+
makea_cli/api_client.py,sha256=1wABEVsg-b6T0vPMpAFSO3cP3YKAwXEWCn3xJFLQaCQ,12059
|
|
4
|
+
makea_cli/auth_pkce.py,sha256=6Uf1K0ic4sw2pAl6LP2tCobKblsC1L3xhIxACEBOGYY,7479
|
|
5
|
+
makea_cli/config.py,sha256=YvxLyWsUxVYRsuS2vFHTO6ZWJBep1EjyepCVVm-DB4s,2171
|
|
6
|
+
makea_cli/main.py,sha256=JIOy07OedCKVV_PEZFFJfc3DQbzxzKXYVrVUVZca3E4,652
|
|
7
|
+
makea_cli/commands/__init__.py,sha256=bKkeZucsvdm1QEDei0dYcbgi-alpZHNl8B0Eo2rnRUw,874
|
|
8
|
+
makea_cli/commands/_util.py,sha256=FAGGKMpizb267j8Dpwj8Q_IyFxVQUdh-n3n7PzBSmq8,390
|
|
9
|
+
makea_cli/commands/auth/__init__.py,sha256=NXoKGfkY2X_hb8GnAyzhoI_qDXfpwKZPqt4HnOrXW3Y,73
|
|
10
|
+
makea_cli/commands/auth/cmd.py,sha256=G9ZeiaJwzUUTptIyynr0V-82wI7eV0qVX0pD6rdPSXg,1321
|
|
11
|
+
makea_cli/commands/directory/__init__.py,sha256=rQHBc0JOFXynlzrBm_YfqoRuNsS-JOl-OOvPjgDbnIA,78
|
|
12
|
+
makea_cli/commands/directory/cmd.py,sha256=kK3u4m3mEJiC7B62f7ibeveQ4Tvfx3mblpmrqZdVsis,1117
|
|
13
|
+
makea_cli/commands/document/__init__.py,sha256=7u8jLBGeryD7ocqX17DCf0eCkyjcrpzXcwc2wEEOXw8,77
|
|
14
|
+
makea_cli/commands/document/cmd.py,sha256=HeWs3hN06NmFzM6wHnQwkBg8RbmW4ZH21tJ56pSUp34,6019
|
|
15
|
+
makea_cli/commands/email/__init__.py,sha256=EWMqMTgZK1GQDW7-9RGVSGU-CvaHTARjXZL18Hdj80I,74
|
|
16
|
+
makea_cli/commands/email/cmd.py,sha256=Ct1oi94gdsydV9foRx_kyvQG0XOaZ0PjNUGMeIx61JM,3942
|
|
17
|
+
makea_cli/commands/metrics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
makea_cli/commands/metrics/cmd.py,sha256=PvNMcGRLUWoXq7_io4JahK_BuQeK5BTVjx5R9SFijTY,3536
|
|
19
|
+
makea_cli/commands/orders/__init__.py,sha256=6WKPqX02e0RRPmItPIBJ0TA4_yDI2PVvBDkAiMQu9rU,75
|
|
20
|
+
makea_cli/commands/orders/cmd.py,sha256=y9SbyAevrCO_iwntNArRHpemrTNeaerAcHMqjf3eNy8,6924
|
|
21
|
+
makea_cli/commands/product/__init__.py,sha256=mfdonFmpbddDSlJq6JWNWgNpM6aOpKtZr-3FJ6scrwg,76
|
|
22
|
+
makea_cli/commands/product/cmd.py,sha256=mrtLsyYsQpKLJ5bg0sjkLOXg_BUC6zZDiG7OjJEUeaY,5683
|
|
23
|
+
makea_cli/commands/supplier/__init__.py,sha256=qfQDeQdQ-B7I_uwFVfcp1vXFUTL4fAcNLu3ipsZ7dfs,77
|
|
24
|
+
makea_cli/commands/supplier/cmd.py,sha256=z2RKcgSr9mFgO6kK3zulM5n6lmgSF4fSv6K0s1st2Fg,12399
|
|
25
|
+
makea_cli-0.1.1.dist-info/METADATA,sha256=9iIPTmNFmhyFDlvKg02lHN1fPPbNdfnRg-BiEUBcLZ8,5232
|
|
26
|
+
makea_cli-0.1.1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
27
|
+
makea_cli-0.1.1.dist-info/entry_points.txt,sha256=roop5-ZvEsGz60WfivSkuhTobja8wVlls9RBylHO6QY,49
|
|
28
|
+
makea_cli-0.1.1.dist-info/RECORD,,
|