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