businessapi-mcp 0.1.0__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.
- businessapi_mcp/__init__.py +3 -0
- businessapi_mcp/__main__.py +6 -0
- businessapi_mcp/cli.py +208 -0
- businessapi_mcp/config.py +180 -0
- businessapi_mcp/examples/abn_registration_sole_trader.json +87 -0
- businessapi_mcp/examples/business_name_registration_ib.json +41 -0
- businessapi_mcp/examples/company_registration.json +97 -0
- businessapi_mcp/models.py +1858 -0
- businessapi_mcp/server.py +1714 -0
- businessapi_mcp/smoke.py +193 -0
- businessapi_mcp-0.1.0.dist-info/METADATA +215 -0
- businessapi_mcp-0.1.0.dist-info/RECORD +15 -0
- businessapi_mcp-0.1.0.dist-info/WHEEL +4 -0
- businessapi_mcp-0.1.0.dist-info/entry_points.txt +2 -0
- businessapi_mcp-0.1.0.dist-info/licenses/LICENSE +21 -0
businessapi_mcp/cli.py
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"""
|
|
2
|
+
`businessapi-mcp` command line.
|
|
3
|
+
|
|
4
|
+
businessapi-mcp run the MCP server on stdio (what MCP clients launch)
|
|
5
|
+
businessapi-mcp run --transport http --port 8000
|
|
6
|
+
businessapi-mcp setup store your API key (prompted, hidden) and verify it against the API
|
|
7
|
+
businessapi-mcp status show where the key comes from and which environment is active
|
|
8
|
+
businessapi-mcp doctor [--lodge] sandbox self-test through the real MCP tools (test keys only)
|
|
9
|
+
businessapi-mcp install <client> register the server with claude-code | claude-desktop | cursor | vscode | mcp-json
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import shutil
|
|
17
|
+
import subprocess
|
|
18
|
+
import sys
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
from . import __version__
|
|
22
|
+
from . import config
|
|
23
|
+
from .config import SETUP_HINT, key_environment, load_settings, write_key
|
|
24
|
+
|
|
25
|
+
PUBLISHED_COMMAND = {"command": "uvx", "args": ["businessapi-mcp"]}
|
|
26
|
+
GIT_COMMAND = {"command": "uvx", "args": ["--from", "git+https://github.com/JoeFu/businessapi-mcp", "businessapi-mcp"]}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _dev_command(repo: Path) -> dict[str, object]:
|
|
30
|
+
return {"command": "uv", "args": ["run", "--directory", str(repo), "businessapi-mcp"]}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# ---------------------------------------------------------------------------------------------
|
|
34
|
+
# run / status
|
|
35
|
+
# ---------------------------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
def cmd_run(args: argparse.Namespace) -> None:
|
|
38
|
+
from .server import mcp # imported late: loading the server builds 40+ tools
|
|
39
|
+
|
|
40
|
+
if args.transport == "http":
|
|
41
|
+
mcp.run(transport="http", host=args.host, port=args.port)
|
|
42
|
+
else:
|
|
43
|
+
mcp.run()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def cmd_status(args: argparse.Namespace) -> None:
|
|
47
|
+
print(load_settings().describe())
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# ---------------------------------------------------------------------------------------------
|
|
51
|
+
# setup
|
|
52
|
+
# ---------------------------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
def _prompt_key() -> str:
|
|
55
|
+
import getpass
|
|
56
|
+
|
|
57
|
+
print("Paste your Business API key (input is hidden). Sandbox keys start with bapi_sk_test_ and are free:")
|
|
58
|
+
print(" https://businessapi.com.au/user/api-keys")
|
|
59
|
+
return getpass.getpass("Key: ")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _verify_key(key: str, env: str) -> bool:
|
|
63
|
+
import httpx2 as httpx
|
|
64
|
+
|
|
65
|
+
base = "https://businessapi.com.au/api/v2" if env == "live" else "https://businessapi.com.au/api/test/v2"
|
|
66
|
+
try:
|
|
67
|
+
r = httpx.get(f"{base}/account-status", headers={"Authorization": f"Bearer {key}", "Accept": "application/json"}, timeout=20)
|
|
68
|
+
except Exception as exc: # network down, proxy, ...
|
|
69
|
+
print(f"Could not reach the API to verify the key ({exc}). The key was saved anyway.")
|
|
70
|
+
return False
|
|
71
|
+
if r.status_code == 200:
|
|
72
|
+
data = r.json()
|
|
73
|
+
print(f"Key verified against the {env} environment (account: {data.get('accountName') or data.get('companyName') or 'ok'}).")
|
|
74
|
+
return True
|
|
75
|
+
if r.status_code == 401:
|
|
76
|
+
print("The API rejected this key (401). Check it in the dashboard and run `businessapi-mcp setup` again.")
|
|
77
|
+
return False
|
|
78
|
+
print(f"Unexpected answer while verifying ({r.status_code}): {r.text[:200]}")
|
|
79
|
+
return False
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def cmd_setup(args: argparse.Namespace) -> None:
|
|
83
|
+
key = (args.key or _prompt_key()).strip()
|
|
84
|
+
env = key_environment(key)
|
|
85
|
+
if env is None:
|
|
86
|
+
sys.exit("That does not look like a Business API key (expected bapi_sk_test_... or bapi_sk_live_...). Nothing saved.")
|
|
87
|
+
target = Path.cwd() / ".env" if args.local else config.user_env_file()
|
|
88
|
+
path = write_key(key, env_file=target)
|
|
89
|
+
print(f"Saved to {path} -> {env} environment (inferred from the key prefix).")
|
|
90
|
+
if env == "live":
|
|
91
|
+
print("Live key: lodgements stay blocked until the server runs with BAPI_ALLOW_LIVE=true. Keep it off until you need it.")
|
|
92
|
+
if not args.no_verify:
|
|
93
|
+
_verify_key(key, env)
|
|
94
|
+
print("Next: `businessapi-mcp install claude-code` (or claude-desktop / cursor), then `businessapi-mcp doctor`.")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# ---------------------------------------------------------------------------------------------
|
|
98
|
+
# doctor
|
|
99
|
+
# ---------------------------------------------------------------------------------------------
|
|
100
|
+
|
|
101
|
+
def cmd_doctor(args: argparse.Namespace) -> None:
|
|
102
|
+
from .smoke import run
|
|
103
|
+
|
|
104
|
+
sys.exit(run(lodge=args.lodge, monitoring=not args.no_monitoring))
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# ---------------------------------------------------------------------------------------------
|
|
108
|
+
# install
|
|
109
|
+
# ---------------------------------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
def _claude_desktop_config() -> Path:
|
|
112
|
+
if sys.platform == "win32":
|
|
113
|
+
return Path(os.environ.get("APPDATA") or Path.home() / "AppData" / "Roaming") / "Claude" / "claude_desktop_config.json"
|
|
114
|
+
if sys.platform == "darwin":
|
|
115
|
+
return Path.home() / "Library" / "Application Support" / "Claude" / "claude_desktop_config.json"
|
|
116
|
+
return Path.home() / ".config" / "Claude" / "claude_desktop_config.json"
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _merge_json(path: Path, section: str, name: str, entry: dict[str, object], dry_run: bool) -> None:
|
|
120
|
+
data: dict[str, object] = {}
|
|
121
|
+
if path.exists():
|
|
122
|
+
try:
|
|
123
|
+
data = json.loads(path.read_text(encoding="utf-8") or "{}")
|
|
124
|
+
except json.JSONDecodeError:
|
|
125
|
+
sys.exit(f"{path} is not valid JSON - fix it by hand first.")
|
|
126
|
+
servers = data.setdefault(section, {})
|
|
127
|
+
assert isinstance(servers, dict)
|
|
128
|
+
servers[name] = entry
|
|
129
|
+
text = json.dumps(data, indent=2) + "\n"
|
|
130
|
+
if dry_run:
|
|
131
|
+
print(f"Would write {path}:\n{text}")
|
|
132
|
+
return
|
|
133
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
134
|
+
if path.exists():
|
|
135
|
+
backup = path.with_name(path.name + ".bak")
|
|
136
|
+
shutil.copy2(path, backup)
|
|
137
|
+
print(f"Backed up the previous file to {backup}")
|
|
138
|
+
path.write_text(text, encoding="utf-8")
|
|
139
|
+
print(f"Wrote {path}")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def cmd_install(args: argparse.Namespace) -> None:
|
|
143
|
+
entry = _dev_command(Path(args.dev).resolve()) if args.dev else dict(GIT_COMMAND if args.git else PUBLISHED_COMMAND)
|
|
144
|
+
name = args.name
|
|
145
|
+
if args.client == "claude-code":
|
|
146
|
+
cmd = ["claude", "mcp", "add", "--scope", args.scope, name, "--", str(entry["command"]), *map(str, entry["args"])] # type: ignore[arg-type]
|
|
147
|
+
if args.dry_run or not shutil.which("claude"):
|
|
148
|
+
print(("Claude Code CLI not found on PATH. " if not args.dry_run else "") + "Run:\n " + " ".join(cmd))
|
|
149
|
+
else:
|
|
150
|
+
subprocess.run(cmd, check=False)
|
|
151
|
+
print("Registered. Open a new Claude Code session and type /mcp to confirm the 'bapi' server is connected.")
|
|
152
|
+
elif args.client == "claude-desktop":
|
|
153
|
+
_merge_json(_claude_desktop_config(), "mcpServers", name, entry, args.dry_run)
|
|
154
|
+
print("Restart Claude Desktop to load the server.")
|
|
155
|
+
elif args.client == "cursor":
|
|
156
|
+
_merge_json(Path.home() / ".cursor" / "mcp.json", "mcpServers", name, entry, args.dry_run)
|
|
157
|
+
print("Cursor picks the server up from Settings -> MCP (reload the window if needed).")
|
|
158
|
+
elif args.client == "vscode":
|
|
159
|
+
print("Add this to .vscode/mcp.json in your workspace (or your user-level mcp.json):")
|
|
160
|
+
print(json.dumps({"servers": {name: {"type": "stdio", **entry}}}, indent=2))
|
|
161
|
+
else: # mcp-json
|
|
162
|
+
print(json.dumps({"mcpServers": {name: entry}}, indent=2))
|
|
163
|
+
if not args.dev and not shutil.which("uvx"):
|
|
164
|
+
print("Note: `uvx` is not on PATH. Install uv (https://docs.astral.sh/uv/) so the client can start the server.")
|
|
165
|
+
if not load_settings().has_key:
|
|
166
|
+
print("No API key configured yet. " + SETUP_HINT)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
# ---------------------------------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
172
|
+
p = argparse.ArgumentParser(prog="businessapi-mcp", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
173
|
+
p.add_argument("--version", action="version", version=f"businessapi-mcp {__version__}")
|
|
174
|
+
sub = p.add_subparsers(dest="cmd")
|
|
175
|
+
|
|
176
|
+
run = sub.add_parser("run", help="run the MCP server (default when no subcommand is given)")
|
|
177
|
+
run.add_argument("--transport", choices=["stdio", "http"], default="stdio")
|
|
178
|
+
run.add_argument("--host", default="127.0.0.1")
|
|
179
|
+
run.add_argument("--port", type=int, default=8000)
|
|
180
|
+
|
|
181
|
+
sub.add_parser("status", help="show the active key source, environment and options")
|
|
182
|
+
|
|
183
|
+
setup = sub.add_parser("setup", help="store your API key (prompted, hidden) and verify it")
|
|
184
|
+
setup.add_argument("--key", help="pass the key instead of being prompted (prefer the prompt: it keeps the key out of shell history)")
|
|
185
|
+
setup.add_argument("--local", action="store_true", help="write ./.env in the current directory instead of the user config file")
|
|
186
|
+
setup.add_argument("--no-verify", action="store_true", help="do not call the API to verify the key")
|
|
187
|
+
|
|
188
|
+
doctor = sub.add_parser("doctor", help="sandbox self-test through the real MCP tools (refuses live keys)")
|
|
189
|
+
doctor.add_argument("--lodge", action="store_true", help="also lodge the example payloads in the sandbox and poll them")
|
|
190
|
+
doctor.add_argument("--no-monitoring", action="store_true", help="skip entity-monitoring steps")
|
|
191
|
+
|
|
192
|
+
install = sub.add_parser("install", help="register the server with an MCP client")
|
|
193
|
+
install.add_argument("client", choices=["claude-code", "claude-desktop", "cursor", "vscode", "mcp-json"])
|
|
194
|
+
install.add_argument("--name", default="bapi", help="server name inside the client (default: bapi)")
|
|
195
|
+
install.add_argument("--scope", default="user", choices=["user", "project", "local"], help="claude-code only (default: user)")
|
|
196
|
+
install.add_argument("--dev", metavar="REPO", help="use `uv run --directory REPO businessapi-mcp` (local checkout) instead of `uvx businessapi-mcp`")
|
|
197
|
+
install.add_argument("--git", action="store_true", help="run straight from GitHub (uvx --from git+https://...) instead of the PyPI package")
|
|
198
|
+
install.add_argument("--dry-run", action="store_true", help="print what would be written without touching any file")
|
|
199
|
+
return p
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def main(argv: list[str] | None = None) -> None:
|
|
203
|
+
args = build_parser().parse_args(argv)
|
|
204
|
+
if args.cmd is None:
|
|
205
|
+
args.transport, args.host, args.port = "stdio", "127.0.0.1", 8000
|
|
206
|
+
cmd_run(args)
|
|
207
|
+
return
|
|
208
|
+
{"run": cmd_run, "status": cmd_status, "setup": cmd_setup, "doctor": cmd_doctor, "install": cmd_install}[args.cmd](args)
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Where the API key comes from and what it implies - the "zero configuration" layer.
|
|
3
|
+
|
|
4
|
+
Lookup order (first hit wins for each variable):
|
|
5
|
+
1. environment variables BAPI_API_KEY, BAPI_ENV, BAPI_ALLOW_LIVE, BAPI_INLINE_SCHEMAS, BAPI_TOOLSETS
|
|
6
|
+
2. ./.env in the current directory (project-local override)
|
|
7
|
+
3. the user config file written by `businessapi-mcp setup`:
|
|
8
|
+
Windows %APPDATA%\\businessapi-mcp\\.env
|
|
9
|
+
macOS ~/Library/Application Support/businessapi-mcp/.env
|
|
10
|
+
Linux $XDG_CONFIG_HOME/businessapi-mcp/.env (default ~/.config/businessapi-mcp/.env)
|
|
11
|
+
|
|
12
|
+
The environment (sandbox vs live) is inferred from the key prefix - bapi_sk_test_... is the sandbox, bapi_sk_live_... is
|
|
13
|
+
live - so BAPI_ENV is optional and only acts as a cross-check. With no key at all the server still starts; every API call
|
|
14
|
+
then fails with a message that says how to configure one.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import os
|
|
19
|
+
import sys
|
|
20
|
+
from collections.abc import Mapping
|
|
21
|
+
from dataclasses import dataclass
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
APP_NAME = "businessapi-mcp"
|
|
25
|
+
ENV_FILE_NAME = ".env"
|
|
26
|
+
SETUP_HINT = "Run `businessapi-mcp setup` to store your key (sandbox keys are free: https://businessapi.com.au/user/api-keys), or set BAPI_API_KEY."
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def user_config_dir() -> Path:
|
|
30
|
+
if sys.platform == "win32":
|
|
31
|
+
base = Path(os.environ.get("APPDATA") or Path.home() / "AppData" / "Roaming")
|
|
32
|
+
elif sys.platform == "darwin":
|
|
33
|
+
base = Path.home() / "Library" / "Application Support"
|
|
34
|
+
else:
|
|
35
|
+
base = Path(os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config")
|
|
36
|
+
return base / APP_NAME
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def user_env_file() -> Path:
|
|
40
|
+
return user_config_dir() / ENV_FILE_NAME
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def parse_env_file(path: Path) -> dict[str, str]:
|
|
44
|
+
"""Minimal KEY=VALUE parser (comments, `export`, quotes) - no python-dotenv dependency needed."""
|
|
45
|
+
values: dict[str, str] = {}
|
|
46
|
+
try:
|
|
47
|
+
text = path.read_text(encoding="utf-8")
|
|
48
|
+
except OSError:
|
|
49
|
+
return values
|
|
50
|
+
for raw in text.splitlines():
|
|
51
|
+
line = raw.strip()
|
|
52
|
+
if not line or line.startswith("#"):
|
|
53
|
+
continue
|
|
54
|
+
if line.startswith("export "):
|
|
55
|
+
line = line[len("export "):].strip()
|
|
56
|
+
if "=" not in line:
|
|
57
|
+
continue
|
|
58
|
+
key, value = line.split("=", 1)
|
|
59
|
+
key, value = key.strip(), value.strip()
|
|
60
|
+
if value and value[0] in "\"'": # quoted value, possibly followed by a comment
|
|
61
|
+
quote = value[0]
|
|
62
|
+
end = value.find(quote, 1)
|
|
63
|
+
value = value[1:end] if end > 0 else value[1:]
|
|
64
|
+
else:
|
|
65
|
+
value = value.split(" #", 1)[0].strip()
|
|
66
|
+
if key:
|
|
67
|
+
values[key] = value
|
|
68
|
+
return values
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def key_environment(key: str) -> str | None:
|
|
72
|
+
"""'test' or 'live' from the key prefix (bapi_sk_test_... / bapi_sk_live_...), else None."""
|
|
73
|
+
if not key.startswith("bapi_"):
|
|
74
|
+
return None
|
|
75
|
+
if "_live_" in key:
|
|
76
|
+
return "live"
|
|
77
|
+
if "_test_" in key:
|
|
78
|
+
return "test"
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass(frozen=True)
|
|
83
|
+
class Settings:
|
|
84
|
+
api_key: str
|
|
85
|
+
env: str # "test" | "live"
|
|
86
|
+
allow_live: bool
|
|
87
|
+
inline_schemas: bool
|
|
88
|
+
toolsets_raw: str
|
|
89
|
+
key_source: str # "environment variable BAPI_API_KEY", a file path, or "none"
|
|
90
|
+
env_source: str # "BAPI_ENV", "key prefix" or "default"
|
|
91
|
+
problems: tuple[str, ...] # configuration errors worth surfacing (e.g. BAPI_ENV contradicts the key)
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def has_key(self) -> bool:
|
|
95
|
+
return bool(self.api_key)
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def base_url(self) -> str:
|
|
99
|
+
return "https://businessapi.com.au/api/v2" if self.env == "live" else "https://businessapi.com.au/api/test/v2"
|
|
100
|
+
|
|
101
|
+
def describe(self) -> str:
|
|
102
|
+
lines = [
|
|
103
|
+
f"API key: {'configured (' + self.api_key[:13] + '...)' if self.has_key else 'NOT configured'} [source: {self.key_source}]",
|
|
104
|
+
f"Environment: {self.env} [from {self.env_source}] -> {self.base_url}",
|
|
105
|
+
f"Live writes allowed: {self.allow_live}",
|
|
106
|
+
f"Inline schemas: {self.inline_schemas} Toolsets: {self.toolsets_raw or 'all'}",
|
|
107
|
+
f"User config file: {user_env_file()}",
|
|
108
|
+
]
|
|
109
|
+
lines.extend(f"PROBLEM: {p}" for p in self.problems)
|
|
110
|
+
if not self.has_key:
|
|
111
|
+
lines.append(SETUP_HINT)
|
|
112
|
+
return "\n".join(lines)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _truthy(value: str | None) -> bool:
|
|
116
|
+
return (value or "").strip().lower() in ("1", "true", "yes", "on")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def load_settings(environ: Mapping[str, str] | None = None, cwd: Path | None = None) -> Settings:
|
|
120
|
+
environ = dict(os.environ if environ is None else environ)
|
|
121
|
+
cwd = cwd or Path.cwd()
|
|
122
|
+
merged: dict[str, str] = {}
|
|
123
|
+
key_source = "none"
|
|
124
|
+
for path in (user_env_file(), cwd / ENV_FILE_NAME): # lowest precedence first
|
|
125
|
+
values = parse_env_file(path)
|
|
126
|
+
for name, value in values.items():
|
|
127
|
+
if name.startswith("BAPI_"):
|
|
128
|
+
merged[name] = value
|
|
129
|
+
if values.get("BAPI_API_KEY", "").strip():
|
|
130
|
+
key_source = str(path)
|
|
131
|
+
for name, value in environ.items():
|
|
132
|
+
if name.startswith("BAPI_"):
|
|
133
|
+
merged[name] = value
|
|
134
|
+
if environ.get("BAPI_API_KEY", "").strip():
|
|
135
|
+
key_source = "environment variable BAPI_API_KEY"
|
|
136
|
+
|
|
137
|
+
api_key = merged.get("BAPI_API_KEY", "").strip()
|
|
138
|
+
inferred = key_environment(api_key) if api_key else None
|
|
139
|
+
problems: list[str] = []
|
|
140
|
+
env_raw = merged.get("BAPI_ENV", "").strip().lower()
|
|
141
|
+
if env_raw:
|
|
142
|
+
env, env_source = env_raw, "BAPI_ENV"
|
|
143
|
+
if env not in ("test", "live"):
|
|
144
|
+
problems.append(f"BAPI_ENV must be 'test' or 'live', not '{env_raw}'")
|
|
145
|
+
env = "test"
|
|
146
|
+
elif inferred and inferred != env:
|
|
147
|
+
problems.append(f"BAPI_ENV={env} but the API key is a {inferred} key (bapi_sk_{inferred}_...)")
|
|
148
|
+
elif inferred:
|
|
149
|
+
env, env_source = inferred, "key prefix"
|
|
150
|
+
else:
|
|
151
|
+
env, env_source = "test", "default"
|
|
152
|
+
if api_key and not inferred:
|
|
153
|
+
problems.append("BAPI_API_KEY does not look like a Business API key (expected bapi_sk_test_... or bapi_sk_live_...)")
|
|
154
|
+
|
|
155
|
+
return Settings(
|
|
156
|
+
api_key=api_key,
|
|
157
|
+
env=env,
|
|
158
|
+
allow_live=_truthy(merged.get("BAPI_ALLOW_LIVE")),
|
|
159
|
+
inline_schemas=_truthy(merged.get("BAPI_INLINE_SCHEMAS")),
|
|
160
|
+
toolsets_raw=merged.get("BAPI_TOOLSETS", "all").strip().lower(),
|
|
161
|
+
key_source=key_source,
|
|
162
|
+
env_source=env_source,
|
|
163
|
+
problems=tuple(problems),
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def write_key(key: str, env_file: Path | None = None) -> Path:
|
|
168
|
+
"""Store the key in the user config file (or the given .env), owner-readable only where the OS supports it."""
|
|
169
|
+
path = env_file or user_env_file()
|
|
170
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
171
|
+
existing = parse_env_file(path) if path.exists() else {}
|
|
172
|
+
existing["BAPI_API_KEY"] = key.strip()
|
|
173
|
+
existing.pop("BAPI_ENV", None) # the environment is inferred from the key prefix
|
|
174
|
+
body = "\n".join(f"{k}={v}" for k, v in existing.items())
|
|
175
|
+
path.write_text(f"# Business API configuration (written by `{APP_NAME} setup`). Keep this file private.\n{body}\n", encoding="utf-8")
|
|
176
|
+
try:
|
|
177
|
+
os.chmod(path, 0o600)
|
|
178
|
+
except OSError: # Windows: ACLs, not mode bits
|
|
179
|
+
pass
|
|
180
|
+
return path
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"entityType": "117",
|
|
3
|
+
"entitySubType": "006",
|
|
4
|
+
"entitlement": {
|
|
5
|
+
"firstQuestion": 152,
|
|
6
|
+
"outcomeId": 7,
|
|
7
|
+
"outcome": true,
|
|
8
|
+
"questionnaire": [
|
|
9
|
+
{ "questionId": 152, "answerId": 336, "nextQuestionId": 139 },
|
|
10
|
+
{ "questionId": 139, "answerId": 310, "nextQuestionId": 3 },
|
|
11
|
+
{ "questionId": 3, "answerId": 339, "nextQuestionId": 143 },
|
|
12
|
+
{ "questionId": 143, "answerId": 318, "nextQuestionId": 0 }
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"applicant": {
|
|
16
|
+
"individual": {
|
|
17
|
+
"title": "Mr",
|
|
18
|
+
"familyName": "SMITH",
|
|
19
|
+
"givenName": "JOHN",
|
|
20
|
+
"dateOfBirth": "1985-06-15",
|
|
21
|
+
"genderCode": "1"
|
|
22
|
+
},
|
|
23
|
+
"tfn": "123456782"
|
|
24
|
+
},
|
|
25
|
+
"applicationDetail": {
|
|
26
|
+
"tfnIndicator": true,
|
|
27
|
+
"abnApplicationIndicator": true,
|
|
28
|
+
"tfnApplicationIndicator": false
|
|
29
|
+
},
|
|
30
|
+
"applicationReason": {
|
|
31
|
+
"code": "NEW",
|
|
32
|
+
"firstTimeDirectorIndicator": true
|
|
33
|
+
},
|
|
34
|
+
"businessActivity": {
|
|
35
|
+
"code": "7749",
|
|
36
|
+
"description": "Cleaning - commercial (offices, shops, exterior and interior building cleaning, except sand blasting or steam cleaning)",
|
|
37
|
+
"abnStartDate": "2026-11-18",
|
|
38
|
+
"governmentIndicator": false,
|
|
39
|
+
"agriculturalIndicator": false
|
|
40
|
+
},
|
|
41
|
+
"mainAddresses": {
|
|
42
|
+
"business": {
|
|
43
|
+
"street": "1 Example Street",
|
|
44
|
+
"locality": "Sample Suburb",
|
|
45
|
+
"state": "QLD",
|
|
46
|
+
"postcode": "4000",
|
|
47
|
+
"countryCode": "AU"
|
|
48
|
+
},
|
|
49
|
+
"postal": {
|
|
50
|
+
"street": "1 Example Street",
|
|
51
|
+
"locality": "Sample Suburb",
|
|
52
|
+
"state": "QLD",
|
|
53
|
+
"postcode": "4000",
|
|
54
|
+
"countryCode": "AU"
|
|
55
|
+
},
|
|
56
|
+
"businessEmail": "smoke@example.com",
|
|
57
|
+
"businessPhone": "0400000000",
|
|
58
|
+
"sameMainBusinessActivityIndicator": true,
|
|
59
|
+
"businessActivityCode": "7749",
|
|
60
|
+
"businessActivityDescription": "Cleaning - commercial (offices, shops, exterior and interior building cleaning, except sand blasting or steam cleaning)",
|
|
61
|
+
"additionalBusinessLocationsIndicator": false
|
|
62
|
+
},
|
|
63
|
+
"taxationInformation": {
|
|
64
|
+
"nonprofitIndicator": false,
|
|
65
|
+
"incomeTaxExemptionIndicator": false,
|
|
66
|
+
"australianResidentIndicator": true
|
|
67
|
+
},
|
|
68
|
+
"declaration": {
|
|
69
|
+
"fullName": "Mr JOHN SMITH",
|
|
70
|
+
"positionHeld": "Owner",
|
|
71
|
+
"phone": "0400000000",
|
|
72
|
+
"date": "2026-11-18",
|
|
73
|
+
"signatureAcceptanceIndicator": true,
|
|
74
|
+
"signatureText": "Mr JOHN SMITH"
|
|
75
|
+
},
|
|
76
|
+
"authorisedContacts": [
|
|
77
|
+
{
|
|
78
|
+
"title": "Mr",
|
|
79
|
+
"familyName": "SMITH",
|
|
80
|
+
"givenName": "JOHN",
|
|
81
|
+
"positionHeld": "Owner",
|
|
82
|
+
"email": "smoke@example.com",
|
|
83
|
+
"phone": "0400000000",
|
|
84
|
+
"preferredLanguageCode": "ENG"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"generalInformation": {
|
|
3
|
+
"businessName": "BAPI SMOKE TRADING CO",
|
|
4
|
+
"term": 3,
|
|
5
|
+
"paymentMethod": "card",
|
|
6
|
+
"email": "smoke@example.com"
|
|
7
|
+
},
|
|
8
|
+
"businessAddress": {
|
|
9
|
+
"unitOrOfficeNumber": "1",
|
|
10
|
+
"streetNumber": "1",
|
|
11
|
+
"streetName": "EXAMPLE",
|
|
12
|
+
"streetType": "ST",
|
|
13
|
+
"locality": "SAMPLE SUBURB",
|
|
14
|
+
"state": "QLD",
|
|
15
|
+
"postCode": "4000",
|
|
16
|
+
"country": "AU"
|
|
17
|
+
},
|
|
18
|
+
"serviceAddress": {
|
|
19
|
+
"unitOrOfficeNumber": "1",
|
|
20
|
+
"streetNumber": "1",
|
|
21
|
+
"streetName": "EXAMPLE",
|
|
22
|
+
"streetType": "ST",
|
|
23
|
+
"locality": "SAMPLE SUBURB",
|
|
24
|
+
"state": "QLD",
|
|
25
|
+
"postCode": "4000",
|
|
26
|
+
"country": "AU"
|
|
27
|
+
},
|
|
28
|
+
"entity": {
|
|
29
|
+
"type": "IB",
|
|
30
|
+
"subType": "PRV",
|
|
31
|
+
"abn": "51824753556",
|
|
32
|
+
"organisation": {
|
|
33
|
+
"name": "SAMPLE COMPANY PTY LTD",
|
|
34
|
+
"acn": "000000019"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"signatory": {
|
|
38
|
+
"name": { "givenNames": "John", "familyName": "Smith" },
|
|
39
|
+
"declaresTrueAndCorrectIndicator": true
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"generalInformation": {
|
|
3
|
+
"companyName": "BAPI SMOKE TEST PTY LTD",
|
|
4
|
+
"acnNameIndicator": false,
|
|
5
|
+
"companyType": "APTY",
|
|
6
|
+
"companyClass": "LMSH",
|
|
7
|
+
"companySubClass": "PROP",
|
|
8
|
+
"jurisdiction": "NSW",
|
|
9
|
+
"residentialOfficeholders": true
|
|
10
|
+
},
|
|
11
|
+
"registeredOffice": {
|
|
12
|
+
"address": {
|
|
13
|
+
"line2": "UNIT 4",
|
|
14
|
+
"street": "9 KENT STREET",
|
|
15
|
+
"locality": "SYDNEY",
|
|
16
|
+
"state": "NSW",
|
|
17
|
+
"postcode": "2000"
|
|
18
|
+
},
|
|
19
|
+
"occupyIndicator": false,
|
|
20
|
+
"occupierName": "ANOTHER COMPANY PTY LTD",
|
|
21
|
+
"occupierConsent": true
|
|
22
|
+
},
|
|
23
|
+
"principalPlaceOfBusiness": {
|
|
24
|
+
"address": {
|
|
25
|
+
"line2": "UNIT 4",
|
|
26
|
+
"street": "9 KENT STREET",
|
|
27
|
+
"locality": "SYDNEY",
|
|
28
|
+
"state": "NSW",
|
|
29
|
+
"postcode": "2000"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"officeHolders": [
|
|
33
|
+
{
|
|
34
|
+
"name": { "familyName": "DOE", "givenName1": "JOHN" },
|
|
35
|
+
"birthDetails": {
|
|
36
|
+
"date": "1980-12-31",
|
|
37
|
+
"locality": "SYDNEY",
|
|
38
|
+
"localityQualifier": "NSW",
|
|
39
|
+
"intlIndicator": false
|
|
40
|
+
},
|
|
41
|
+
"address": {
|
|
42
|
+
"street": "9 KENT STREET",
|
|
43
|
+
"locality": "SYDNEY",
|
|
44
|
+
"state": "NSW",
|
|
45
|
+
"postcode": "2000",
|
|
46
|
+
"country": "AU"
|
|
47
|
+
},
|
|
48
|
+
"roles": ["DIR"]
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"shareStructure": [
|
|
52
|
+
{
|
|
53
|
+
"classCode": "ORD",
|
|
54
|
+
"classTitle": "ORDINARY",
|
|
55
|
+
"numberIssued": 100,
|
|
56
|
+
"totalAmountPaid": 100,
|
|
57
|
+
"totalAmountUnpaid": 0
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
"shareAllocation": [
|
|
61
|
+
{
|
|
62
|
+
"classCode": "ORD",
|
|
63
|
+
"numberIssued": 100,
|
|
64
|
+
"fullyPaidIndicator": true,
|
|
65
|
+
"totalAmountPaid": 100,
|
|
66
|
+
"totalAmountUnpaid": 0,
|
|
67
|
+
"amountPaidPerShare": 1,
|
|
68
|
+
"amountUnpaidPerShare": 0,
|
|
69
|
+
"beneficialOwnerIndicator": true,
|
|
70
|
+
"holdingOwners": [
|
|
71
|
+
{
|
|
72
|
+
"individual": { "familyName": "DOE", "givenName1": "JOHN" },
|
|
73
|
+
"address": {
|
|
74
|
+
"street": "9 KENT STREET",
|
|
75
|
+
"locality": "SYDNEY",
|
|
76
|
+
"state": "NSW",
|
|
77
|
+
"postcode": "2000",
|
|
78
|
+
"country": "AU"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"applicant": {
|
|
85
|
+
"individual": { "familyName": "DOE", "givenName1": "JOHN" },
|
|
86
|
+
"address": {
|
|
87
|
+
"street": "9 KENT STREET",
|
|
88
|
+
"locality": "SYDNEY",
|
|
89
|
+
"state": "NSW",
|
|
90
|
+
"postcode": "2000",
|
|
91
|
+
"country": "AU"
|
|
92
|
+
},
|
|
93
|
+
"dateSigned": "2026-11-18",
|
|
94
|
+
"declaresTrueAndCorrectIndicator": true
|
|
95
|
+
},
|
|
96
|
+
"admin": { "manualReviewIndicator": false }
|
|
97
|
+
}
|