sovaria-cli 0.7.0__tar.gz → 0.8.0__tar.gz

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 (105) hide show
  1. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/PKG-INFO +3 -3
  2. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/__init__.py +1 -1
  3. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/ai_credits.py +49 -5
  4. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/ai_data.py +7 -1
  5. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/auth_product.py +106 -0
  6. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/billing.py +6 -0
  7. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/connect.py +2 -5
  8. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/deploy.py +34 -3
  9. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/iam.py +48 -0
  10. sovaria_cli-0.8.0/apps/cli/src/commands/integrations.py +153 -0
  11. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/login.py +37 -0
  12. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/org.py +10 -0
  13. sovaria_cli-0.8.0/apps/cli/src/commands/wallet.py +165 -0
  14. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/main.py +3 -0
  15. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/api_client.py +26 -3
  16. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/auth_store.py +33 -0
  17. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/config.py +25 -1
  18. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/premium_display.py +13 -1
  19. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/project_context.py +18 -5
  20. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/schema_introspect.py +21 -7
  21. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/pyproject.toml +3 -3
  22. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/.gitignore +0 -0
  23. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/README.md +0 -0
  24. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/__init__.py +0 -0
  25. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/__init__.py +0 -0
  26. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/admin.py +0 -0
  27. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/alerts.py +0 -0
  28. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/analytics.py +0 -0
  29. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/api.py +0 -0
  30. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/api_versions.py +0 -0
  31. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/audit.py +0 -0
  32. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/auth_enterprise.py +0 -0
  33. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/auth_settings.py +0 -0
  34. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/branches.py +0 -0
  35. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/builds.py +0 -0
  36. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/chrono.py +0 -0
  37. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/collections.py +0 -0
  38. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/compliance.py +0 -0
  39. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/context.py +0 -0
  40. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/crashes.py +0 -0
  41. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/dashboard.py +0 -0
  42. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/data.py +0 -0
  43. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/db.py +0 -0
  44. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/distribute.py +0 -0
  45. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/env.py +0 -0
  46. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/experiments.py +0 -0
  47. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/fn_platform.py +0 -0
  48. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/frontends.py +0 -0
  49. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/gen.py +0 -0
  50. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/governance.py +0 -0
  51. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/hosting.py +0 -0
  52. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/import_cmd.py +0 -0
  53. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/init_cmd.py +0 -0
  54. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/inspect.py +0 -0
  55. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/keys.py +0 -0
  56. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/knowledge.py +0 -0
  57. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/link_cmd.py +0 -0
  58. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/local.py +0 -0
  59. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/logs.py +0 -0
  60. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/mcp.py +0 -0
  61. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/messaging.py +0 -0
  62. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/metrics.py +0 -0
  63. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/oidc_providers.py +0 -0
  64. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/org_key.py +0 -0
  65. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/orgs_projects.py +0 -0
  66. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/passkeys.py +0 -0
  67. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/perf.py +0 -0
  68. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/policy.py +0 -0
  69. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/project.py +0 -0
  70. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/push.py +0 -0
  71. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/queues.py +0 -0
  72. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/realtime.py +0 -0
  73. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/remote_config.py +0 -0
  74. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/rules.py +0 -0
  75. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/schema.py +0 -0
  76. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/scope.py +0 -0
  77. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/secrets.py +0 -0
  78. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/shell.py +0 -0
  79. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/sim.py +0 -0
  80. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/simulate.py +0 -0
  81. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/storage.py +0 -0
  82. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/templates.py +0 -0
  83. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/test_cmd.py +0 -0
  84. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/commands/vector.py +0 -0
  85. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/local/docker-compose.yml +0 -0
  86. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/local/initdb/001_axis_tables.sql +0 -0
  87. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/local/initdb/002_axis_base_schema.sql +0 -0
  88. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/local/initdb/003_guard_policies.sql +0 -0
  89. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/local/initdb/010_local_stack.sql +0 -0
  90. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/__init__.py +0 -0
  91. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/api_helpers.py +0 -0
  92. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/display.py +0 -0
  93. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/forge_local.py +0 -0
  94. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/importers.py +0 -0
  95. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/local_function_server.py +0 -0
  96. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/local_stack.py +0 -0
  97. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/log_tail.py +0 -0
  98. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/loopback_host.py +0 -0
  99. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/macho_symbols.py +0 -0
  100. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/migrations.py +0 -0
  101. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/mobile_types.py +0 -0
  102. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/output_mode.py +0 -0
  103. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/scope_picker.py +0 -0
  104. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/sim_offline.py +0 -0
  105. {sovaria_cli-0.7.0 → sovaria_cli-0.8.0}/apps/cli/src/utils/theme.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sovaria-cli
3
- Version: 0.7.0
3
+ Version: 0.8.0
4
4
  Summary: Sovaria BaaS command-line interface (sov)
5
5
  Project-URL: Homepage, https://sovaria.in
6
6
  Project-URL: Documentation, https://docs.sovaria.in/cli
@@ -12,7 +12,7 @@ Requires-Dist: httpx<1,>=0.28.1
12
12
  Requires-Dist: keyring<26,>=25.0
13
13
  Requires-Dist: pyyaml<7,>=6.0
14
14
  Requires-Dist: rich<16,>=13.7.0
15
- Requires-Dist: sovaria-sdk==0.9.0
15
+ Requires-Dist: sovaria-sdk==0.12.0
16
16
  Requires-Dist: tomli-w<2,>=1.2.0
17
17
  Requires-Dist: typer<1,>=0.17.4
18
18
  Provides-Extra: dev
@@ -22,7 +22,7 @@ Requires-Dist: pytest>=8.0; extra == 'dev'
22
22
  Requires-Dist: ruff>=0.9; extra == 'dev'
23
23
  Requires-Dist: twine>=6.0; extra == 'dev'
24
24
  Provides-Extra: mcp
25
- Requires-Dist: sovaria-sdk[mcp]==0.9.0; extra == 'mcp'
25
+ Requires-Dist: sovaria-sdk[mcp]==0.12.0; extra == 'mcp'
26
26
  Description-Content-Type: text/markdown
27
27
 
28
28
  # Sovaria CLI
@@ -1,3 +1,3 @@
1
1
  """Sovaria CLI — sov command."""
2
2
 
3
- __version__ = "0.7.0"
3
+ __version__ = "0.8.0"
@@ -53,7 +53,11 @@ def _org(profile, org_id) -> str:
53
53
 
54
54
 
55
55
  def _n(value) -> str:
56
- return "no limit" if value is None else f"{int(value):,}"
56
+ """Credits to a tenth (pricing v2: a quick chat turn is ~0.3 credit)."""
57
+ if value is None:
58
+ return "no limit"
59
+ v = float(value)
60
+ return f"{v:,.0f}" if v.is_integer() else f"{v:,.1f}"
57
61
 
58
62
 
59
63
  def meter(view: dict) -> str:
@@ -65,9 +69,9 @@ def meter(view: dict) -> str:
65
69
  return "Unlimited Sovariq credits"
66
70
  parts = []
67
71
  if today is not None:
68
- parts.append(f"{int(today):,} left today")
72
+ parts.append(f"{_n(today)} left today")
69
73
  if month is not None:
70
- parts.append(f"{int(month):,} this month")
74
+ parts.append(f"{_n(month)} this month")
71
75
  return " · ".join(parts)
72
76
 
73
77
 
@@ -87,11 +91,51 @@ def credits(as_json: bool = typer.Option(False, "--json"),
87
91
  for label, key in (("Granted credits", "grants"), ("Credit packs", "packs")):
88
92
  left = (out.get(key) or {}).get("left") or 0
89
93
  if left:
90
- typer.echo(f" {label}: {left:,} left")
94
+ typer.echo(f" {label}: {_n(left)} left")
91
95
  for line in out.get("caps_text") or []:
92
96
  typer.echo(f" {line}")
93
97
  if out.get("level") == "low":
94
- typer.echo("Running low: top up or ask your admin.", err=True)
98
+ typer.echo("Running low: buy a credit pack (sov ai packs) or ask your admin.", err=True)
99
+
100
+
101
+ @app.command("packs")
102
+ def packs(as_json: bool = typer.Option(False, "--json"), profile: str | None = _PROFILE, org_id: str | None = _ORG) -> None:
103
+ """Sovariq credit packs for sale (12-month credits, paid plans), your packs and the Sovariq wallet cap."""
104
+ org = _org(profile, org_id)
105
+ out = _call("GET", f"/api/v1/billing/orgs/{_seg(org)}/ai-credits/packs", profile=profile, org_id=org)
106
+ if as_json:
107
+ print_json(out)
108
+ return
109
+ if not out.get("allowed", True):
110
+ typer.echo(out.get("reason") or "Credit packs are part of paid plans.")
111
+ for pack in out.get("packs") or []:
112
+ price = pack.get("price") or {}
113
+ money = (f"₹{price.get('minor', 0) / 100:,.0f}" if price.get("currency") == "INR"
114
+ else f"${price.get('minor', 0) / 100:,.2f}")
115
+ typer.echo(f"{pack['id']:<10} {pack['credits']:>8,} credits {money:>10} {pack.get('months', 12)} months")
116
+ for grant in out.get("grants") or []:
117
+ typer.echo(f" yours: {_n(grant.get('credits_left'))} of {_n(grant.get('credits'))} left, until {str(grant.get('expires_at'))[:10]}")
118
+ if out.get("wallet_cap_cents") is not None:
119
+ typer.echo(f"Sovariq wallet cap: ${(out.get('wallet_room_cents') or 0) / 100:,.2f} left of "
120
+ f"${out['wallet_cap_cents'] / 100:,.2f} this month")
121
+
122
+
123
+ @app.command("buy-pack")
124
+ def buy_pack(pack_id: str = typer.Argument(..., help="starter, builder, studio (see sov ai packs)"),
125
+ from_wallet: bool = typer.Option(False, "--from-wallet", help="Pay from the wallet (otherwise prints the console link)"),
126
+ profile: str | None = _PROFILE, org_id: str | None = _ORG) -> None:
127
+ """Buy a credit pack: from the wallet here, or by card / UPI in the console (the CLI never takes a card)."""
128
+ org = _org(profile, org_id)
129
+ if not from_wallet:
130
+ from apps.cli.src.utils.config import get_console_url
131
+
132
+ typer.echo(f"Pay by card or UPI: {get_console_url(profile).rstrip('/')}/org/{_seg(org)}/billing?tab=spend-cap&pack={_seg(pack_id)}")
133
+ return
134
+ out = _call("POST", f"/api/v1/billing/orgs/{_seg(org)}/ai-credits/packs/from-balance", profile=profile, org_id=org,
135
+ body={"pack_id": pack_id})
136
+ grant = out.get("grant") or {}
137
+ typer.echo(f"Added {_n(grant.get('credits'))} Sovariq credits (until {str(grant.get('expires_at'))[:10]}). "
138
+ f"Wallet: ${(out.get('balance_cents') or 0) / 100:,.2f}")
95
139
 
96
140
 
97
141
  @limits_app.callback()
@@ -366,4 +366,10 @@ def register(main_app: typer.Typer) -> None:
366
366
  knowledge_mod.agents_app.command("rollback")(agent_rollback)
367
367
  knowledge_mod.agents_app.command("compare")(agent_compare)
368
368
  main_app.add_typer(gateway_app, name="gateway", help="Model gateway: routes, fallbacks, cache, usage per model")
369
- main_app.add_typer(sovariq_app, name="sovariq", help="Sovariq: usage (tokens, cache hits, credits per day)")
369
+ # Pricing v2: `sov sovariq credits|packs|buy-pack` (the same commands as `sov ai …`).
370
+ from apps.cli.src.commands import ai_credits as _ai_credits
371
+
372
+ sovariq_app.command("credits")(_ai_credits.credits)
373
+ sovariq_app.command("packs")(_ai_credits.packs)
374
+ sovariq_app.command("buy-pack")(_ai_credits.buy_pack)
375
+ main_app.add_typer(sovariq_app, name="sovariq", help="Sovariq: usage (tokens, cache hits, credits per day), credits and packs")
@@ -197,6 +197,52 @@ def set_roles(
197
197
  print_json(result)
198
198
 
199
199
 
200
+ def _change_roles(user_id: str, add: list[str], remove: list[str], profile, org_id, project_id, env_id) -> dict:
201
+ safe_user_id = quote(user_id, safe="")
202
+ path = _project_auth_path(profile, project_id, f"/users/{safe_user_id}/roles")
203
+ scope = _scope_args(org_id, project_id, env_id)
204
+ current = call_api(method="GET", path=path, profile=profile, require_scope=True, **scope) or {}
205
+ have = [str(r) for r in (current.get("roles") or [])]
206
+ drop = {r.lower() for r in remove}
207
+ lower = {h.lower() for h in have}
208
+ wanted = [r for r in have if r.lower() not in drop] + [r for r in add if r.lower() not in lower]
209
+ return call_api(method="PUT", path=path, profile=profile, body={"roles": wanted}, require_scope=True, **scope)
210
+
211
+
212
+ @app.command("roles-add")
213
+ def add_roles(
214
+ user_id: str = typer.Argument(..., help="Product user id"),
215
+ roles: list[str] = typer.Argument(..., help="Roles to give (the user keeps the ones they have)"),
216
+ profile: str | None = typer.Option(None, "--profile"),
217
+ org_id: str | None = typer.Option(None, "--org"),
218
+ project_id: str | None = typer.Option(None, "--project"),
219
+ env_id: str | None = typer.Option(None, "--env"),
220
+ ) -> None:
221
+ """Give a product user roles. They are signed out and get the roles in their next session."""
222
+ try:
223
+ result = _change_roles(user_id, roles, [], profile, org_id, project_id, env_id)
224
+ except CLIRequestError as exc:
225
+ handle_cli_error(exc)
226
+ print_json(result)
227
+
228
+
229
+ @app.command("roles-remove")
230
+ def remove_roles(
231
+ user_id: str = typer.Argument(..., help="Product user id"),
232
+ roles: list[str] = typer.Argument(..., help="Roles to take away"),
233
+ profile: str | None = typer.Option(None, "--profile"),
234
+ org_id: str | None = typer.Option(None, "--org"),
235
+ project_id: str | None = typer.Option(None, "--project"),
236
+ env_id: str | None = typer.Option(None, "--env"),
237
+ ) -> None:
238
+ """Take roles away from a product user (their current token keeps them until it is refreshed or expires)."""
239
+ try:
240
+ result = _change_roles(user_id, [], roles, profile, org_id, project_id, env_id)
241
+ except CLIRequestError as exc:
242
+ handle_cli_error(exc)
243
+ print_json(result)
244
+
245
+
200
246
  @app.command("update")
201
247
  def update_user(
202
248
  user_id: str = typer.Argument(..., help="The app user's id"),
@@ -268,6 +314,66 @@ def create_user(
268
314
  print_json(result)
269
315
 
270
316
 
317
+ _LINK_TYPES = ("magiclink", "recovery", "invite", "signup")
318
+
319
+
320
+ @app.command("link")
321
+ def generate_link(
322
+ email: str = typer.Option(..., "--email"),
323
+ link_type: str = typer.Option(
324
+ "magiclink", "--type",
325
+ help="magiclink (sign in), recovery (set a new password), invite (creates a passwordless user) or "
326
+ "signup (creates a password user with an unconfirmed address; password from the prompt or "
327
+ "SOVARIA_USER_PASSWORD)"),
328
+ redirect_to: str | None = typer.Option(None, "--redirect-to", help="Where the link lands (must be allowed)"),
329
+ data: str | None = typer.Option(None, "--data", help="invite/signup: the new user's user_metadata as JSON"),
330
+ profile: str | None = typer.Option(None, "--profile"),
331
+ org_id: str | None = typer.Option(None, "--org"),
332
+ project_id: str | None = typer.Option(None, "--project"),
333
+ env_id: str | None = typer.Option(None, "--env"),
334
+ ) -> None:
335
+ """The link a sign-in, recovery, invite or signup email would carry, printed instead of sent (supabase's
336
+ auth.admin.generateLink). Org owners and admins only; audited and limited to 60 an hour.
337
+
338
+ The link signs that user in (or confirms their address): treat the output as a secret."""
339
+ import json
340
+
341
+ kind = link_type.strip().lower()
342
+ if kind not in _LINK_TYPES:
343
+ handle_cli_error(CLIRequestError(f"--type must be one of: {', '.join(_LINK_TYPES)}"))
344
+ body: dict = {"type": kind, "email": email}
345
+ if redirect_to:
346
+ body["redirect_to"] = redirect_to
347
+ if data:
348
+ if kind not in ("invite", "signup"):
349
+ handle_cli_error(CLIRequestError("--data is only used by invite and signup links"))
350
+ try:
351
+ parsed = json.loads(data)
352
+ except ValueError:
353
+ parsed = None
354
+ if not isinstance(parsed, dict):
355
+ handle_cli_error(CLIRequestError("--data must be a JSON object, for example '{\"team\": \"blue\"}'"))
356
+ body["data"] = parsed
357
+ if kind == "signup":
358
+ body["password"] = _read_new_user_password()
359
+ try:
360
+ result = run_with_spinner(
361
+ f"Generating a {kind} link for {email}…",
362
+ lambda: call_api(
363
+ method="POST",
364
+ path=_project_auth_path(profile, project_id, "/generate-link"),
365
+ profile=profile,
366
+ require_scope=True,
367
+ **_scope_args(org_id, project_id, env_id),
368
+ body=body,
369
+ ),
370
+ success="Link generated",
371
+ )
372
+ except CLIRequestError as exc:
373
+ handle_cli_error(exc)
374
+ print_json(result)
375
+
376
+
271
377
  _EXPORT_FIELDS = ("id", "email", "phone", "name", "email_verified", "is_anonymous", "status", "roles",
272
378
  "created_at", "last_sign_in_at", "providers")
273
379
 
@@ -598,3 +598,9 @@ def autopay_status(
598
598
  from apps.cli.src.utils.display import print_json
599
599
 
600
600
  print_json((data or {}).get("autopay") or {"mandate": "none"}, title="Autopay")
601
+
602
+
603
+ # Pricing v2: wallet, top-up link, spend cap, forecast, auto-recharge (apps/cli/src/commands/wallet.py).
604
+ from apps.cli.src.commands import wallet as _wallet # noqa: E402
605
+
606
+ _wallet.register(app)
@@ -141,11 +141,8 @@ def show_connect(
141
141
  anon_val = anon or "YOUR_ANON_KEY"
142
142
  info["sdk_snippet"] = (
143
143
  f"import {{ createClient }} from '@sovaria/sdk';\n\n"
144
- f"const sov = createClient({{\n"
145
- f" apiUrl: '{info['project_url']}',\n"
146
- f" projectId: '{resolved_project}',\n"
147
- f" anonKey: '{anon_val}',\n"
148
- f"}});"
144
+ f"// The project URL and its anon (publishable) key, as the Connect panel shows them.\n"
145
+ f"const sov = createClient('{info['project_url']}', '{anon_val}');"
149
146
  )
150
147
  return info
151
148
 
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  import io
6
6
  import json
7
7
  import os
8
+ import re
8
9
  import subprocess
9
10
  import sys
10
11
  import time
@@ -30,6 +31,34 @@ from apps.cli.src.utils.premium_display import (
30
31
  )
31
32
  from apps.cli.src.utils.project_context import resolve_scope
32
33
 
34
+ _NOT_SLUG = re.compile(r"[^a-zA-Z0-9_-]+")
35
+
36
+
37
+ def function_slug(raw: str) -> str:
38
+ """The name Forge stores and calls a function by: lowercase letters, digits, '-' and '_' (same rule as Forge)."""
39
+ return _NOT_SLUG.sub("-", (raw or "").strip()).strip("-").lower()[:128]
40
+
41
+
42
+ def _function_name(name: str | None, directory: Path) -> str:
43
+ """``--name`` must already be a valid name (Forge refuses others with INVALID_FUNCTION_NAME); a name taken from
44
+ the folder is turned into one, and the CLI says so, so you know what to call."""
45
+ if name is not None:
46
+ if function_slug(name) != name:
47
+ hint = f" Use '{function_slug(name)}'." if function_slug(name) else ""
48
+ raise typer.BadParameter(
49
+ "use lowercase letters, digits, '-' and '_' (at most 128)." + hint, param_hint="--name")
50
+ return name
51
+ folder = directory.resolve().name
52
+ slug = function_slug(folder)
53
+ if not slug:
54
+ raise typer.BadParameter(f"the folder name {folder!r} has no usable characters; pass --name", param_hint="--name")
55
+ if slug != folder:
56
+ from apps.cli.src.utils.output_mode import wants_json
57
+
58
+ if not wants_json():
59
+ typer.echo(f"Deploying as '{slug}' (from the folder name '{folder}'); call it by that name.")
60
+ return slug
61
+
33
62
  app = typer.Typer()
34
63
 
35
64
  _POLL_INTERVAL = 2 # seconds
@@ -120,7 +149,7 @@ def deploy(
120
149
  readable=True,
121
150
  help="Path to the function directory to deploy",
122
151
  ),
123
- name: str | None = typer.Option(None, "--name", "-n", help="Function name"),
152
+ name: str | None = typer.Option(None, "--name", "-n", help="Function name: lowercase letters, digits, - and _ (at most 128). Default: the folder name, turned into one (the CLI says which)"),
124
153
  project_id: str | None = typer.Option(None, "--project", "-p", help="Target project node ID"),
125
154
  note: str = typer.Option("", "--note", help="Version change note for deployment history"),
126
155
  profile: str | None = typer.Option(None, "--profile"),
@@ -153,7 +182,7 @@ def deploy(
153
182
  require_scope=True,
154
183
  )
155
184
  effective_project = project_id or resolved_project
156
- fn_name = name or directory.resolve().name
185
+ fn_name = _function_name(name, directory)
157
186
 
158
187
  entry = entrypoint or _detect_entrypoint(directory)
159
188
  zip_bytes = run_with_spinner(
@@ -471,7 +500,9 @@ def call(
471
500
 
472
501
  path = f"/api/v1/fn/call/{_quote(function_name, safe='')}" + (f"/{sub_path.strip('/')}" if sub_path.strip("/") else "")
473
502
  try:
474
- resp = httpx.request(method.upper(), f"{api_url}{path}", headers={**headers, **extra}, params=params or None,
503
+ from apps.cli.src.utils.api_client import assert_safe_path
504
+
505
+ resp = httpx.request(method.upper(), f"{api_url}{assert_safe_path(path)}", headers={**headers, **extra}, params=params or None,
475
506
  content=body, timeout=960)
476
507
  except httpx.HTTPError as exc:
477
508
  print_error_panel(f"Request failed: {exc}")
@@ -387,6 +387,54 @@ def roles_matrix_set(
387
387
  )
388
388
 
389
389
 
390
+ def _matrix_lists(scope: dict) -> dict[str, list[str]]:
391
+ current = call_api(method="GET", path="/api/v1/roles/matrix", require_scope=True, **scope) or {}
392
+ return {name: sorted(p for p, on in (perms or {}).items() if on) for name, perms in dict(current).items()}
393
+
394
+
395
+ @roles_matrix_app.command("add")
396
+ def roles_matrix_add(
397
+ name: str = typer.Argument(..., help="Role name, e.g. MANAGER (letters, digits, - and _)"),
398
+ permission: list[str] = typer.Option([], "--perm", help="Permission to grant (repeatable), e.g. --perm read"),
399
+ profile: str | None = typer.Option(None, "--profile"),
400
+ org_id: str | None = typer.Option(None, "--org"),
401
+ project_id: str | None = typer.Option(None, "--project"),
402
+ env_id: str | None = typer.Option(None, "--env"),
403
+ ) -> None:
404
+ """Add an app role (row rules test it with auth.has_role('manager')), keeping every other role."""
405
+ scope = {"profile": profile, "org_id": org_id, "project_id": project_id, "env_id": env_id}
406
+ try:
407
+ roles = _matrix_lists(scope)
408
+ if any(r.lower() == name.strip().lower() for r in roles):
409
+ handle_cli_error(CLIRequestError(f"A role called {name} already exists. Change it with: sov iam roles-matrix set"))
410
+ roles[name.strip()] = sorted(set(permission))
411
+ call_api(method="PUT", path="/api/v1/roles/matrix", body={"matrix": roles}, require_scope=True, **scope)
412
+ except CLIRequestError as exc:
413
+ handle_cli_error(exc)
414
+ print_success(f"Role {name} added" + (f" with {', '.join(sorted(set(permission)))}" if permission else ""))
415
+
416
+
417
+ @roles_matrix_app.command("remove")
418
+ def roles_matrix_remove(
419
+ name: str = typer.Argument(..., help="Role to remove (users holding it lose it)"),
420
+ profile: str | None = typer.Option(None, "--profile"),
421
+ org_id: str | None = typer.Option(None, "--org"),
422
+ project_id: str | None = typer.Option(None, "--project"),
423
+ env_id: str | None = typer.Option(None, "--env"),
424
+ ) -> None:
425
+ """Remove one app role, keeping the others."""
426
+ scope = {"profile": profile, "org_id": org_id, "project_id": project_id, "env_id": env_id}
427
+ try:
428
+ roles = _matrix_lists(scope)
429
+ kept = {r: p for r, p in roles.items() if r.lower() != name.strip().lower()}
430
+ if len(kept) == len(roles):
431
+ handle_cli_error(CLIRequestError(f"No role called {name}. See them with: sov iam roles-matrix get"))
432
+ call_api(method="PUT", path="/api/v1/roles/matrix", body={"matrix": kept}, require_scope=True, **scope)
433
+ except CLIRequestError as exc:
434
+ handle_cli_error(exc)
435
+ print_success(f"Role {name} removed")
436
+
437
+
390
438
  @app.command("roles-catalog")
391
439
  def roles_catalog(
392
440
  profile: str | None = typer.Option(None, "--profile"),
@@ -0,0 +1,153 @@
1
+ """`sov integrations`: one-click integrations (Slack, Discord alerts; Vercel, Netlify env sync).
2
+
3
+ sov integrations providers what can be connected in one click here
4
+ sov integrations connections the org's deploy connections (never a token)
5
+ sov integrations connect vercel [--project P] prints the vendor's consent link; finish in the console
6
+ sov integrations state vercel [--project P] connected? last sync?
7
+ sov integrations targets vercel [--project P] the Vercel projects / Netlify sites you can sync to
8
+ sov integrations sync vercel --target prj_123 write the project URL + publishable key there
9
+ sov integrations env [--project P] those values, to set by hand
10
+ sov integrations disconnect vercel [--project P] forget it and revoke Sovaria's access where the vendor allows
11
+
12
+ The vendor's consent screen sends the browser back to the console, where the admin who started the connection
13
+ finishes it (a link someone else started can't land your workspace in their organization).
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from urllib.parse import quote
19
+
20
+ import typer
21
+
22
+ from apps.cli.src.utils.api_client import CLIRequestError, call_api
23
+ from apps.cli.src.utils.config import get_console_url
24
+ from apps.cli.src.utils.display import handle_cli_error, print_json, print_success
25
+ from apps.cli.src.utils.output_mode import wants_json
26
+ from apps.cli.src.utils.project_context import resolve_scope
27
+
28
+ app = typer.Typer(help="One-click integrations: Slack/Discord alerts, Vercel/Netlify env sync")
29
+
30
+ Profile = typer.Option(None, "--profile")
31
+ Org = typer.Option(None, "--org")
32
+ Project = typer.Option(None, "--project")
33
+
34
+
35
+ def _scope(profile: str | None, org_id: str | None, project_id: str | None, *, need_project: bool) -> tuple[str, str]:
36
+ org, project, _env = resolve_scope(profile=profile, org_id=org_id, project_id=project_id, env_id=None, require=False)
37
+ if not org:
38
+ typer.echo("Pick an organization: --org <id>, or `sov link` in a project folder.", err=True)
39
+ raise typer.Exit(2)
40
+ if need_project and not project:
41
+ typer.echo("Pick a project: --project <id>, or `sov link` in a project folder.", err=True)
42
+ raise typer.Exit(2)
43
+ return org, project
44
+
45
+
46
+ def _call(method: str, path: str, profile: str | None, org: str, project: str = "", **kw):
47
+ try:
48
+ return call_api(method=method, path=path, profile=profile, org_id=org, project_id=project or None, **kw)
49
+ except CLIRequestError as exc:
50
+ handle_cli_error(exc)
51
+ raise typer.Exit(1) from exc
52
+
53
+
54
+ def _base(org: str, provider: str | None = None) -> str:
55
+ path = f"/api/v1/org/{quote(org, safe='')}/integrations"
56
+ return f"{path}/{quote(provider, safe='')}" if provider else path
57
+
58
+
59
+ @app.command("providers")
60
+ def providers(profile: str | None = Profile) -> None:
61
+ """Integrations that can be connected in one click on this Sovaria (others use the manual form)."""
62
+ try:
63
+ data = call_api(method="GET", path="/api/v1/integrations/connect/providers", profile=profile)
64
+ except CLIRequestError as exc:
65
+ handle_cli_error(exc)
66
+ raise typer.Exit(1) from exc
67
+ rows = [{"id": p.get("id"), "name": p.get("name"), "kind": p.get("kind"),
68
+ "one_click": bool(p.get("configured") and p.get("enabled"))} for p in (data or {}).get("providers", [])]
69
+ print_json(data if wants_json() else rows, title="One-click integrations")
70
+
71
+
72
+ @app.command("connections")
73
+ def connections(profile: str | None = Profile, org_id: str | None = Org) -> None:
74
+ """The organization's deploy connections (provider, project, when, last sync). Tokens are never shown."""
75
+ org, _ = _scope(profile, org_id, None, need_project=False)
76
+ data = _call("GET", f"{_base(org)}/connections", profile, org) or {}
77
+ print_json(data if wants_json() else data.get("items", []), title="Deploy connections")
78
+
79
+
80
+ @app.command("connect")
81
+ def connect(provider: str = typer.Argument(..., help="slack, discord, vercel or netlify"), profile: str | None = Profile,
82
+ org_id: str | None = Org, project_id: str | None = Project) -> None:
83
+ """Print the vendor's consent link. After you approve, the browser returns to the console, which finishes it."""
84
+ deploy = provider in ("vercel", "netlify")
85
+ org, project = _scope(profile, org_id, project_id, need_project=deploy)
86
+ back = f"{get_console_url(profile).rstrip('/')}/org/{quote(org, safe='')}/integrations?open={quote(provider, safe='')}"
87
+ body = {"return_to": back, **({"project_id": project} if deploy else {})}
88
+ data = _call("POST", f"{_base(org, provider)}/connect", profile, org, project, body=body) or {}
89
+ url = str(data.get("authorize_url") or "")
90
+ if wants_json():
91
+ print_json(data)
92
+ return
93
+ typer.echo(f"Open this link to connect {provider} (valid for 10 minutes):\n\n {url}\n")
94
+ typer.echo("Approve it, and the console finishes the connection in the same browser.")
95
+
96
+
97
+ @app.command("state")
98
+ def state(provider: str = typer.Argument(...), profile: str | None = Profile, org_id: str | None = Org,
99
+ project_id: str | None = Project) -> None:
100
+ """Whether a deploy provider is connected to the project, and its last sync."""
101
+ org, project = _scope(profile, org_id, project_id, need_project=True)
102
+ print_json(_call("GET", f"{_base(org, provider)}/state", profile, org, project, params={"project_id": project}))
103
+
104
+
105
+ @app.command("targets")
106
+ def targets(provider: str = typer.Argument(...), profile: str | None = Profile, org_id: str | None = Org,
107
+ project_id: str | None = Project) -> None:
108
+ """The Vercel projects or Netlify sites the connection can write to."""
109
+ org, project = _scope(profile, org_id, project_id, need_project=True)
110
+ data = _call("GET", f"{_base(org, provider)}/targets", profile, org, project, params={"project_id": project}) or {}
111
+ print_json(data if wants_json() else data.get("targets", []), title=f"{provider} targets")
112
+
113
+
114
+ @app.command("sync")
115
+ def sync(provider: str = typer.Argument(...), target: str = typer.Option(..., "--target", help="Vercel project / Netlify site id"),
116
+ profile: str | None = Profile, org_id: str | None = Org, project_id: str | None = Project) -> None:
117
+ """Write the project URL and publishable (anon) key into the target's environment variables. No secret keys."""
118
+ org, project = _scope(profile, org_id, project_id, need_project=True)
119
+ data = _call("POST", f"{_base(org, provider)}/sync", profile, org, project, body={"project_id": project, "target_id": target}) or {}
120
+ if wants_json():
121
+ print_json(data)
122
+ return
123
+ print_success(f"{len(data.get('synced') or [])} variables set on {target}. Redeploy to use them.")
124
+
125
+
126
+ @app.command("env")
127
+ def env(profile: str | None = Profile, org_id: str | None = Org, project_id: str | None = Project) -> None:
128
+ """The public values a frontend needs (project URL + publishable key), to set by hand."""
129
+ org, project = _scope(profile, org_id, project_id, need_project=True)
130
+ data = _call("GET", f"{_base(org)}/env", profile, org, project, params={"project_id": project}) or {}
131
+ values = data.get("env") or {}
132
+ if wants_json():
133
+ print_json(values)
134
+ return
135
+ for key, value in values.items():
136
+ typer.echo(f"{key}={value}")
137
+
138
+
139
+ @app.command("disconnect")
140
+ def disconnect(provider: str = typer.Argument(...), profile: str | None = Profile, org_id: str | None = Org,
141
+ project_id: str | None = Project, yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask")) -> None:
142
+ """Forget a deploy connection and revoke Sovaria's access at the vendor where it allows that."""
143
+ org, project = _scope(profile, org_id, project_id, need_project=True)
144
+ if not yes and not typer.confirm(f"Disconnect {provider} from this project?"):
145
+ raise typer.Exit(1)
146
+ data = _call("DELETE", _base(org, provider), profile, org, project, params={"project_id": project}) or {}
147
+ if wants_json():
148
+ print_json(data)
149
+ return
150
+ if data.get("vendor_revoked"):
151
+ print_success(f"{provider} disconnected and its access revoked.")
152
+ else:
153
+ print_success(f"{provider} disconnected." + (f" {data['vendor_revoke_error']}" if data.get("vendor_revoke_error") else ""))
@@ -170,6 +170,18 @@ def _oauth_token_url(api_url: str) -> str:
170
170
 
171
171
 
172
172
  def _guard_login_api_url(api_url: str, *, profile: str | None) -> None:
173
+ from apps.cli.src.utils.config import implicit_target
174
+
175
+ target = implicit_target(profile)
176
+ if target:
177
+ where = (f"No ~/.sovaria/config.yaml and no --profile: this signs in to Sovaria Cloud ({target}). "
178
+ "For a local stack use `sov start` (profile local) or --profile with its api_url.")
179
+ if not sys.stdin.isatty() or (os.getenv("SOVARIA_PASSWORD") or "").strip():
180
+ # Nobody to read the warning: a script must say where it signs in.
181
+ print_error_panel(where + " Pass --profile prod (or SOVARIA_PROFILE=prod) to sign in to the cloud from a "
182
+ "script.")
183
+ raise typer.Exit(2)
184
+ print_warning(where)
173
185
  try:
174
186
  warning = assess_login_api_url(api_url, profile=profile)
175
187
  except UnsafeApiUrlError as exc:
@@ -461,9 +473,29 @@ def _password_login(
461
473
  print_warning(str(exc))
462
474
  raise typer.Exit(2) from exc
463
475
  except httpx.HTTPStatusError as exc:
476
+ if _needs_bot_check(exc):
477
+ print_error_panel(
478
+ "This server asks for a bot check (CAPTCHA) on password sign-in, which a terminal can't show.\n"
479
+ "Run `sov login` without --email to sign in in your browser, or set SOVARIA_ACCESS_TOKEN "
480
+ "(a token from the console) for scripts and CI."
481
+ )
482
+ raise typer.Exit(1) from exc
464
483
  _http_error_panel(exc, context="console/login")
465
484
 
466
485
 
486
+ def _needs_bot_check(exc: httpx.HTTPStatusError) -> bool:
487
+ """A 400/403 asking for a CAPTCHA token (the console's bot check is on)."""
488
+ if exc.response.status_code not in (400, 403):
489
+ return False
490
+ try:
491
+ detail = exc.response.json().get("detail")
492
+ except Exception: # noqa: BLE001
493
+ detail = exc.response.text
494
+ if isinstance(detail, dict):
495
+ detail = f"{detail.get('code', '')} {detail.get('message', '')}"
496
+ return "captcha" in str(detail or "").lower()
497
+
498
+
467
499
  def _pkce_login(
468
500
  api_url: str,
469
501
  *,
@@ -477,6 +509,7 @@ def _pkce_login(
477
509
  (profile ``api_url``) ``/oauth/token`` proxy — that split is intentional.
478
510
  """
479
511
  _assert_callback_host(insecure_callback=insecure_callback)
512
+ _guard_login_api_url(api_url, profile=profile)
480
513
  token_url = _oauth_token_url(api_url)
481
514
  console_url = get_console_url(profile)
482
515
  authorize_base = f"{console_url}/cli/oauth/authorize"
@@ -587,6 +620,10 @@ def logout(
587
620
 
588
621
 
589
622
  def _revoke_refresh_token(profile: str | None, tokens: dict[str, object]) -> bool:
623
+ from apps.cli.src.utils.auth_store import login_host_mismatch
624
+
625
+ if login_host_mismatch(dict(tokens), profile):
626
+ return False # never send this login's tokens to a host it wasn't made on (logout --force clears it)
590
627
  url = f"{get_api_url(profile)}/api/v1/auth/logout"
591
628
  headers = {"Authorization": f"Bearer {tokens['access_token']}"}
592
629
  body = {"refresh_token": tokens["refresh_token"]}
@@ -64,6 +64,11 @@ def create_org(
64
64
  if not tokens:
65
65
  typer.echo("Not logged in. Run: sov login", err=True)
66
66
  raise typer.Exit(1)
67
+ from apps.cli.src.utils.auth_store import login_host_mismatch
68
+
69
+ if mismatch := login_host_mismatch(tokens, profile):
70
+ typer.echo(mismatch, err=True)
71
+ raise typer.Exit(1)
67
72
 
68
73
  # Parse optional JSON metadata
69
74
  meta: dict = {}
@@ -144,6 +149,11 @@ def add_member(
144
149
  if not tokens:
145
150
  typer.echo("Not logged in. Run: sov login", err=True)
146
151
  raise typer.Exit(1)
152
+ from apps.cli.src.utils.auth_store import login_host_mismatch
153
+
154
+ if mismatch := login_host_mismatch(tokens, profile):
155
+ typer.echo(mismatch, err=True)
156
+ raise typer.Exit(1)
147
157
 
148
158
  api_url = get_api_url(profile)
149
159
  headers = {