Coverage for polar/member/schemas.py: 100%
26 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 15:52 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 15:52 +0000
1from typing import Annotated 1a
3from annotated_types import MaxLen 1a
4from pydantic import UUID4, Field 1a
6from polar.kit.email import EmailStrDNS 1a
7from polar.kit.schemas import ( 1a
8 EmptyStrToNoneValidator,
9 IDSchema,
10 Schema,
11 TimestampedSchema,
12)
13from polar.models.member import MemberRole 1a
15_external_id_description = ( 1a
16 "The ID of the member in your system. This must be unique within the customer. "
17)
18_external_id_example = "usr_1337" 1a
19_email_description = "The email address of the member." 1a
20_email_example = "member@example.com" 1a
21_name_description = "The name of the member." 1a
22_name_example = "Jane Doe" 1a
24MemberNameInput = Annotated[ 1a
25 str,
26 MaxLen(256),
27 Field(description=_name_description, examples=[_name_example]),
28 EmptyStrToNoneValidator,
29]
32class OwnerCreate(Schema): 1a
33 """Schema for creating an owner member during customer creation."""
35 email: EmailStrDNS | None = Field( 1a
36 default=None, description=_email_description, examples=[_email_example]
37 )
38 name: MemberNameInput | None = None 1a
39 external_id: Annotated[str | None, EmptyStrToNoneValidator] = Field( 1a
40 default=None,
41 description=_external_id_description,
42 examples=[_external_id_example],
43 )
46class MemberBase(TimestampedSchema, IDSchema): 1a
47 """Base schema for member responses."""
49 id: UUID4 = Field(description="The ID of the member.") 1a
50 customer_id: UUID4 = Field( 1a
51 description="The ID of the customer this member belongs to."
52 )
53 email: str = Field(description=_email_description, examples=[_email_example]) 1a
54 name: str | None = Field(description=_name_description, examples=[_name_example]) 1a
55 external_id: str | None = Field( 1a
56 description=_external_id_description, examples=[_external_id_example]
57 )
58 role: MemberRole = Field( 1a
59 description="The role of the member within the customer.",
60 examples=[MemberRole.owner],
61 )
64class Member(MemberBase): 1a
65 """A member of a customer."""
67 pass 1a