proxy-platform 0.3.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.

Potentially problematic release.


This version of proxy-platform might be problematic. Click here for more details.

@@ -0,0 +1,323 @@
1
+ """Support ticket portal commands for users."""
2
+
3
+ import typer
4
+ from rich.console import Console
5
+ from rich.table import Table
6
+
7
+ from ..client import APIClient
8
+ from ..config import get_default_api_type
9
+
10
+ app = typer.Typer()
11
+ console = Console()
12
+
13
+ # Valid support ticket categories and statuses (mirrors pbd-shared enums)
14
+ SUPPORT_CATEGORIES = ["general", "billing", "technical", "other"]
15
+ SUPPORT_STATUSES = ["open", "in_progress", "closed"]
16
+
17
+
18
+ @app.command(name="submit")
19
+ def submit_ticket(
20
+ subject: str = typer.Option(..., "--subject", "-s", help="Ticket subject"),
21
+ description: str = typer.Option(..., "--description", "-d", help="Ticket description"),
22
+ category: str = typer.Option(..., "--category", "-c", help=f"Category: {', '.join(SUPPORT_CATEGORIES)}"),
23
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
24
+ ) -> None:
25
+ """Submit a new support ticket.
26
+
27
+ Creates a new support ticket in the portal. The category must be one of:
28
+ general, billing, technical, other.
29
+
30
+ Examples:
31
+ pbd support submit --subject "Cannot access cluster" --description "Getting 403 error" --category technical
32
+ pbd support submit --subject "Invoice question" --description "Need clarification on invoice" --category billing
33
+ """
34
+ if api is None:
35
+ api = get_default_api_type()
36
+
37
+ if category not in SUPPORT_CATEGORIES:
38
+ console.print(f"[red]Error: Invalid category '{category}'[/red]")
39
+ console.print(f"[yellow]Valid categories: {', '.join(SUPPORT_CATEGORIES)}[/yellow]")
40
+ raise typer.Exit(1)
41
+
42
+ try:
43
+ client = APIClient(api_type=api)
44
+ data = {
45
+ "subject": subject,
46
+ "description": description,
47
+ "category": category,
48
+ }
49
+
50
+ response = client.post("/api/v1/support", data=data)
51
+
52
+ if response.status_code == 201:
53
+ result = response.json()
54
+ console.print()
55
+ console.print("[green]Support ticket submitted successfully![/green]")
56
+ console.print()
57
+ console.print("[bold]Ticket Details[/bold]")
58
+ console.print("-" * 70)
59
+ console.print(f"ID: [cyan]{result.get('id')}[/cyan]")
60
+ console.print(f"Subject: {result.get('subject')}")
61
+ console.print(f"Category: [blue]{result.get('category')}[/blue]")
62
+ console.print(f"Status: [yellow]{result.get('status')}[/yellow]")
63
+ console.print()
64
+ else:
65
+ console.print(f"[red]Error: {response.status_code}[/red]")
66
+ try:
67
+ console.print(response.json().get("detail", "Unknown error"))
68
+ except Exception:
69
+ console.print(response.text)
70
+ raise typer.Exit(1)
71
+
72
+ except typer.Exit:
73
+ raise
74
+ except Exception as e:
75
+ console.print(f"[red]Error: {str(e)}[/red]")
76
+ raise typer.Exit(1) from None
77
+
78
+
79
+ @app.command(name="list")
80
+ def list_tickets(
81
+ page: int = typer.Option(1, "--page", "-p", help="Page number (1-based)"),
82
+ category: str | None = typer.Option(
83
+ None, "--category", "-c", help=f"Filter by category: {', '.join(SUPPORT_CATEGORIES)}"
84
+ ),
85
+ status: str | None = typer.Option(None, "--status", "-s", help=f"Filter by status: {', '.join(SUPPORT_STATUSES)}"),
86
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
87
+ ) -> None:
88
+ """List your own support tickets.
89
+
90
+ Shows your submitted support tickets. Supports filtering by category and status.
91
+
92
+ Examples:
93
+ pbd support list
94
+ pbd support list --category technical
95
+ pbd support list --status open
96
+ pbd support list --page 2
97
+ """
98
+ if api is None:
99
+ api = get_default_api_type()
100
+
101
+ if category and category not in SUPPORT_CATEGORIES:
102
+ console.print(f"[red]Error: Invalid category '{category}'[/red]")
103
+ console.print(f"[yellow]Valid categories: {', '.join(SUPPORT_CATEGORIES)}[/yellow]")
104
+ raise typer.Exit(1)
105
+
106
+ if status and status not in SUPPORT_STATUSES:
107
+ console.print(f"[red]Error: Invalid status '{status}'[/red]")
108
+ console.print(f"[yellow]Valid statuses: {', '.join(SUPPORT_STATUSES)}[/yellow]")
109
+ raise typer.Exit(1)
110
+
111
+ try:
112
+ client = APIClient(api_type=api)
113
+ params: dict[str, str | int] = {"page": page}
114
+ if category:
115
+ params["category"] = category
116
+ if status:
117
+ params["status"] = status
118
+
119
+ response = client.get("/api/v1/support", params=params)
120
+
121
+ if response.status_code == 200:
122
+ data = response.json()
123
+ items = data.get("data", [])
124
+
125
+ if not items:
126
+ console.print("[yellow]No support tickets found[/yellow]")
127
+ return
128
+
129
+ total = data.get("total", len(items))
130
+ table = Table(title=f"Support Tickets ({len(items)} of {total})")
131
+ table.add_column("ID", style="cyan", no_wrap=True)
132
+ table.add_column("Subject", style="white")
133
+ table.add_column("Category", style="blue")
134
+ table.add_column("Status", style="yellow")
135
+ table.add_column("Date", style="dim")
136
+
137
+ for item in items:
138
+ item_id = str(item.get("id", "N/A"))[:8] + "..."
139
+ created = item.get("created_at", "N/A")[:10] if item.get("created_at") else "N/A"
140
+
141
+ table.add_row(
142
+ item_id,
143
+ item.get("subject", "N/A"),
144
+ item.get("category", "N/A"),
145
+ item.get("status", "N/A"),
146
+ created,
147
+ )
148
+
149
+ console.print()
150
+ console.print(table)
151
+
152
+ if data.get("has_next"):
153
+ console.print(f"\n[dim]Page {data.get('page')}. Use --page to navigate.[/dim]")
154
+
155
+ console.print()
156
+ else:
157
+ console.print(f"[red]Error: {response.status_code}[/red]")
158
+ try:
159
+ console.print(response.json().get("detail", "Unknown error"))
160
+ except Exception:
161
+ console.print(response.text)
162
+ raise typer.Exit(1)
163
+
164
+ except typer.Exit:
165
+ raise
166
+ except Exception as e:
167
+ console.print(f"[red]Error: {str(e)}[/red]")
168
+ raise typer.Exit(1) from None
169
+
170
+
171
+ @app.command(name="get")
172
+ def get_ticket(
173
+ ticket_id: str = typer.Argument(..., help="Ticket ID (UUID)"),
174
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
175
+ ) -> None:
176
+ """View a support ticket with its full message thread.
177
+
178
+ Examples:
179
+ pbd support get 550e8400-e29b-41d4-a716-446655440000
180
+ """
181
+ if api is None:
182
+ api = get_default_api_type()
183
+
184
+ try:
185
+ client = APIClient(api_type=api)
186
+ response = client.get(f"/api/v1/support/{ticket_id}")
187
+
188
+ if response.status_code == 200:
189
+ item = response.json()
190
+ console.print()
191
+ console.print("[bold]Support Ticket Details[/bold]")
192
+ console.print("-" * 70)
193
+ console.print(f"ID: [cyan]{item.get('id')}[/cyan]")
194
+ console.print(f"Subject: {item.get('subject')}")
195
+ console.print(f"Description: {item.get('description')}")
196
+ console.print(f"Category: [blue]{item.get('category')}[/blue]")
197
+ console.print(f"Status: [yellow]{item.get('status')}[/yellow]")
198
+ if item.get("created_at"):
199
+ console.print(f"Created: {item.get('created_at')}")
200
+
201
+ # Show message thread if present
202
+ messages = item.get("messages", [])
203
+ if messages:
204
+ console.print()
205
+ console.print(f"[bold]Messages ({len(messages)})[/bold]")
206
+ console.print("-" * 70)
207
+ for message in messages:
208
+ sender = message.get("sender_name", "N/A")
209
+ created = message.get("created_at", "N/A")[:10] if message.get("created_at") else "N/A"
210
+ console.print(f"[cyan]{sender}[/cyan] ({created}):")
211
+ console.print(f" {message.get('content')}")
212
+ console.print()
213
+ console.print()
214
+ elif response.status_code == 404:
215
+ console.print(f"[red]Ticket not found: {ticket_id}[/red]")
216
+ raise typer.Exit(1)
217
+ else:
218
+ console.print(f"[red]Error: {response.status_code}[/red]")
219
+ try:
220
+ console.print(response.json().get("detail", "Unknown error"))
221
+ except Exception:
222
+ console.print(response.text)
223
+ raise typer.Exit(1)
224
+
225
+ except typer.Exit:
226
+ raise
227
+ except Exception as e:
228
+ console.print(f"[red]Error: {str(e)}[/red]")
229
+ raise typer.Exit(1) from None
230
+
231
+
232
+ @app.command(name="reply")
233
+ def reply_ticket(
234
+ ticket_id: str = typer.Argument(..., help="Ticket ID (UUID)"),
235
+ content: str = typer.Option(..., "--content", "-c", help="Reply content"),
236
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
237
+ ) -> None:
238
+ """Reply to a support ticket.
239
+
240
+ Examples:
241
+ pbd support reply <id> --content "Here is the additional information you requested"
242
+ """
243
+ if api is None:
244
+ api = get_default_api_type()
245
+
246
+ try:
247
+ client = APIClient(api_type=api)
248
+ data = {"content": content}
249
+ response = client.post(f"/api/v1/support/{ticket_id}/messages", data=data)
250
+
251
+ if response.status_code == 201:
252
+ result = response.json()
253
+ console.print(f"[green]Reply added to ticket [cyan]{ticket_id}[/cyan][/green]")
254
+ console.print(f" Message ID: [cyan]{result.get('id')}[/cyan]")
255
+ console.print(f" Content: {result.get('content')}")
256
+ console.print()
257
+ elif response.status_code == 404:
258
+ console.print(f"[red]Ticket not found: {ticket_id}[/red]")
259
+ raise typer.Exit(1)
260
+ else:
261
+ console.print(f"[red]Error: {response.status_code}[/red]")
262
+ try:
263
+ console.print(response.json().get("detail", "Unknown error"))
264
+ except Exception:
265
+ console.print(response.text)
266
+ raise typer.Exit(1)
267
+
268
+ except typer.Exit:
269
+ raise
270
+ except Exception as e:
271
+ console.print(f"[red]Error: {str(e)}[/red]")
272
+ raise typer.Exit(1) from None
273
+
274
+
275
+ @app.command(name="close")
276
+ def close_ticket(
277
+ ticket_id: str = typer.Argument(..., help="Ticket ID (UUID)"),
278
+ yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
279
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
280
+ ) -> None:
281
+ """Close your own support ticket.
282
+
283
+ This marks the ticket as closed. Only the ticket owner can close their ticket.
284
+
285
+ Examples:
286
+ pbd support close <id>
287
+ pbd support close <id> --yes
288
+ """
289
+ if api is None:
290
+ api = get_default_api_type()
291
+
292
+ try:
293
+ client = APIClient(api_type=api)
294
+
295
+ if not yes:
296
+ confirm = typer.confirm(f"Are you sure you want to close ticket {ticket_id}?")
297
+ if not confirm:
298
+ console.print("[yellow]Close cancelled[/yellow]")
299
+ raise typer.Exit(0)
300
+
301
+ response = client.delete(f"/api/v1/support/{ticket_id}")
302
+
303
+ if response.status_code in [200, 204]:
304
+ console.print(f"[green]Ticket [cyan]{ticket_id}[/cyan] closed successfully[/green]")
305
+ elif response.status_code == 403:
306
+ console.print("[red]Error: You are not allowed to close this ticket[/red]")
307
+ raise typer.Exit(1)
308
+ elif response.status_code == 404:
309
+ console.print(f"[red]Ticket not found: {ticket_id}[/red]")
310
+ raise typer.Exit(1)
311
+ else:
312
+ console.print(f"[red]Error: {response.status_code}[/red]")
313
+ try:
314
+ console.print(response.json().get("detail", "Unknown error"))
315
+ except Exception:
316
+ console.print(response.text)
317
+ raise typer.Exit(1)
318
+
319
+ except typer.Exit:
320
+ raise
321
+ except Exception as e:
322
+ console.print(f"[red]Error: {str(e)}[/red]")
323
+ raise typer.Exit(1) from None
@@ -0,0 +1,221 @@
1
+ """User management commands."""
2
+
3
+ import typer
4
+ from rich.console import Console
5
+ from rich.table import Table
6
+
7
+ from ..client import APIClient
8
+ from ..config import get_default_api_type
9
+
10
+ app = typer.Typer()
11
+ console = Console()
12
+
13
+
14
+ @app.command(name="profile")
15
+ def get_profile(
16
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
17
+ ) -> None:
18
+ """Get user profile information."""
19
+ if api is None:
20
+ api = get_default_api_type()
21
+
22
+ try:
23
+ client = APIClient(api_type=api)
24
+ response = client.get("/api/v1/users/profile")
25
+
26
+ if response.status_code == 200:
27
+ user = response.json()
28
+
29
+ console.print()
30
+ console.print("[bold]User Profile[/bold]")
31
+ console.print("─" * 70)
32
+ console.print(f"ID: [cyan]{user.get('id')}[/cyan]")
33
+ console.print(f"Email: [cyan]{user.get('email')}[/cyan]")
34
+ console.print(f"First Name: {user.get('first_name', 'N/A')}")
35
+ console.print(f"Last Name: {user.get('last_name', 'N/A')}")
36
+ console.print(f"Company: {user.get('company_name', 'N/A')}")
37
+ console.print(f"Phone: {user.get('phone', 'N/A')}")
38
+
39
+ if user.get("is_admin"):
40
+ console.print("Role: [magenta]Admin[/magenta]")
41
+
42
+ if user.get("created_at"):
43
+ console.print(f"Member Since: {user.get('created_at')}")
44
+
45
+ console.print()
46
+ else:
47
+ console.print(f"[red]Error: {response.status_code}[/red]")
48
+ console.print(response.json().get("detail", "Unknown error"))
49
+ raise typer.Exit(1)
50
+
51
+ except Exception as e:
52
+ console.print(f"[red]Error: {str(e)}[/red]")
53
+ raise typer.Exit(1) from None
54
+
55
+
56
+ @app.command(name="stats")
57
+ def get_stats(
58
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
59
+ ) -> None:
60
+ """Get user statistics."""
61
+ if api is None:
62
+ api = get_default_api_type()
63
+
64
+ try:
65
+ client = APIClient(api_type=api)
66
+ response = client.get("/api/v1/users/stats")
67
+
68
+ if response.status_code == 200:
69
+ stats = response.json()
70
+
71
+ console.print()
72
+ console.print("[bold]User Statistics[/bold]")
73
+ console.print("─" * 70)
74
+
75
+ for key, value in stats.items():
76
+ formatted_key = key.replace("_", " ").title()
77
+ console.print(f"{formatted_key}: [cyan]{value}[/cyan]")
78
+
79
+ console.print()
80
+ else:
81
+ console.print(f"[red]Error: {response.status_code}[/red]")
82
+ console.print(response.json().get("detail", "Unknown error"))
83
+ raise typer.Exit(1)
84
+
85
+ except Exception as e:
86
+ console.print(f"[red]Error: {str(e)}[/red]")
87
+ raise typer.Exit(1) from None
88
+
89
+
90
+ @app.command(name="activities")
91
+ def get_activities(
92
+ limit: int = typer.Option(10, "--limit", "-l", help="Number of activities to fetch"),
93
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
94
+ ) -> None:
95
+ """Get user activity log."""
96
+ if api is None:
97
+ api = get_default_api_type()
98
+
99
+ try:
100
+ client = APIClient(api_type=api)
101
+ response = client.get(f"/api/v1/users/activities?limit={limit}")
102
+
103
+ if response.status_code == 200:
104
+ data = response.json()
105
+ activities = data.get("items", [])
106
+
107
+ if not activities:
108
+ console.print("[yellow]No activities found[/yellow]")
109
+ return
110
+
111
+ table = Table(title=f"Recent Activities ({len(activities)} of {data.get('total', 0)})")
112
+ table.add_column("ID", style="cyan", no_wrap=True)
113
+ table.add_column("Type", style="green")
114
+ table.add_column("Description", style="white")
115
+ table.add_column("Date", style="yellow")
116
+
117
+ for activity in activities:
118
+ table.add_row(
119
+ str(activity.get("id", "N/A")),
120
+ activity.get("activity_type", "N/A"),
121
+ activity.get("description", "N/A"),
122
+ activity.get("created_at", "N/A"),
123
+ )
124
+
125
+ console.print()
126
+ console.print(table)
127
+ console.print()
128
+ else:
129
+ console.print(f"[red]Error: {response.status_code}[/red]")
130
+ console.print(response.json().get("detail", "Unknown error"))
131
+ raise typer.Exit(1)
132
+
133
+ except Exception as e:
134
+ console.print(f"[red]Error: {str(e)}[/red]")
135
+ raise typer.Exit(1) from None
136
+
137
+
138
+ @app.command(name="orders")
139
+ def get_orders(
140
+ limit: int = typer.Option(10, "--limit", "-l", help="Number of orders to fetch"),
141
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
142
+ ) -> None:
143
+ """Get user orders."""
144
+ if api is None:
145
+ api = get_default_api_type()
146
+
147
+ try:
148
+ client = APIClient(api_type=api)
149
+ response = client.get(f"/api/v1/users/orders?limit={limit}")
150
+
151
+ if response.status_code == 200:
152
+ data = response.json()
153
+ orders = data.get("items", [])
154
+
155
+ if not orders:
156
+ console.print("[yellow]No orders found[/yellow]")
157
+ return
158
+
159
+ table = Table(title=f"Orders ({len(orders)} of {data.get('total', 0)})")
160
+ table.add_column("ID", style="cyan", no_wrap=True)
161
+ table.add_column("Status", style="yellow")
162
+ table.add_column("Total", style="green")
163
+ table.add_column("Date", style="blue")
164
+
165
+ for order in orders:
166
+ table.add_row(
167
+ str(order.get("id", "N/A")),
168
+ order.get("status", "N/A"),
169
+ f"€{order.get('total_amount', 0):.2f}",
170
+ order.get("created_at", "N/A"),
171
+ )
172
+
173
+ console.print()
174
+ console.print(table)
175
+ console.print()
176
+ else:
177
+ console.print(f"[red]Error: {response.status_code}[/red]")
178
+ console.print(response.json().get("detail", "Unknown error"))
179
+ raise typer.Exit(1)
180
+
181
+ except Exception as e:
182
+ console.print(f"[red]Error: {str(e)}[/red]")
183
+ raise typer.Exit(1) from None
184
+
185
+
186
+ @app.command(name="verification")
187
+ def get_verification_status(
188
+ api: str | None = typer.Option(None, "--api", "-a", help="API type (admin or user)"),
189
+ ) -> None:
190
+ """Get user verification status."""
191
+ if api is None:
192
+ api = get_default_api_type()
193
+
194
+ try:
195
+ client = APIClient(api_type=api)
196
+ response = client.get("/api/v1/users/verification-status")
197
+
198
+ if response.status_code == 200:
199
+ status = response.json()
200
+
201
+ console.print()
202
+ console.print("[bold]Verification Status[/bold]")
203
+ console.print("─" * 70)
204
+
205
+ for key, value in status.items():
206
+ formatted_key = key.replace("_", " ").title()
207
+ if isinstance(value, bool):
208
+ value_str = "[green]Yes[/green]" if value else "[red]No[/red]"
209
+ console.print(f"{formatted_key}: {value_str}")
210
+ else:
211
+ console.print(f"{formatted_key}: [cyan]{value}[/cyan]")
212
+
213
+ console.print()
214
+ else:
215
+ console.print(f"[red]Error: {response.status_code}[/red]")
216
+ console.print(response.json().get("detail", "Unknown error"))
217
+ raise typer.Exit(1)
218
+
219
+ except Exception as e:
220
+ console.print(f"[red]Error: {str(e)}[/red]")
221
+ raise typer.Exit(1) from None