Skip to content

Commit 09c7bf4

Browse files
author
Cyril De Faria
committed
[IMP] Add clerk organizations types and CRUD endpoints.
Update Organization object.
1 parent a17cb72 commit 09c7bf4

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,4 @@ dmypy.json
137137
# Cython debug symbols
138138
cython_debug/
139139

140+
*.idea

clerk/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ def users(self):
5151

5252
return UsersService(self)
5353

54+
@property
55+
def organizations(self):
56+
from clerk.organizations import OrganizationsService
57+
58+
return OrganizationsService(self)
59+
5460
@asynccontextmanager
5561
async def get(
5662
self, endpoint: str, params: Optional[Mapping[str, str]] = None

clerk/organizations.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import List
2+
3+
from clerk import types
4+
from clerk.client import Service
5+
6+
7+
class OrganizationsService(Service):
8+
endpoint = "organizations"
9+
10+
async def list(self) -> List[types.Organization]:
11+
"""Retrieve a list of all organizations"""
12+
async with self._client.get(self.endpoint) as r:
13+
s = await r.json()
14+
return [types.Organization.parse_obj(s) for s in s.get("data")]
15+
16+
async def get(self, organization_id: str) -> types.Organization:
17+
"""Retrieve an organization by their id"""
18+
async with self._client.get(f"{self.endpoint}/{organization_id}") as r:
19+
return types.Organization.parse_obj(await r.json())
20+
21+
async def delete(self, organization_id: str) -> types.DeleteOrganizationResponse:
22+
"""Delete an organization by their id"""
23+
async with self._client.delete(f"{self.endpoint}/{organization_id}") as r:
24+
return types.DeleteOrganizationResponse.parse_obj(await r.json())
25+
26+
async def update(self, organization_id: str, request: types.UpdateOrganizationRequest) -> types.Organization:
27+
"""Update an organization by their id"""
28+
async with self._client.patch(
29+
f"{self.endpoint}/{organization_id}", data=request.json(exclude_unset=True)
30+
) as r:
31+
return types.Organization.parse_obj(await r.json())

clerk/types.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,43 @@ class VerifyRequest(BaseModel):
8383
token: str
8484

8585

86-
class DeleteUserResponse(BaseModel):
86+
class DeleteResponse(BaseModel):
8787
object: str
8888
id: str
8989
deleted: bool
9090

9191

92+
class DeleteUserResponse(DeleteResponse):
93+
pass
94+
95+
9296
class UpdateUserRequest(BaseModel):
9397
first_name: Optional[str] = None
9498
last_name: Optional[str] = None
9599
primary_email_address_id: Optional[str] = None
96100
primary_phone_number_id: Optional[str] = None
97101
profile_image: Optional[str] = None
98102
password: Optional[str] = None
103+
104+
105+
class Organization(BaseModel):
106+
object: str
107+
id: str
108+
name: str
109+
slug: str
110+
max_allowed_memberships: int
111+
admin_delete_enabled: bool | None = None
112+
public_metadata: dict
113+
private_metadata: dict
114+
created_by: str | None = None
115+
116+
117+
class DeleteOrganizationResponse(DeleteResponse):
118+
pass
119+
120+
121+
class UpdateOrganizationRequest(BaseModel):
122+
name: str | None = None
123+
slug: str | None = None
124+
max_allowed_memberships: int | None = None
125+
admin_delete_enabled: bool | None = None

0 commit comments

Comments
 (0)