-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathschema.py
More file actions
96 lines (76 loc) · 2.6 KB
/
schema.py
File metadata and controls
96 lines (76 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import typing as t
from datetime import datetime
from enum import Enum
from pydantic import BaseModel
from pydantic import Field
from pydantic import validator
from pydantic.generics import GenericModel
from .model import ConnectInteropStatus
from .model import EntityType
from .model import Provenance
from .model import WalletManagementType
from .model import WalletType
from .util import ObjectID
DataT = t.TypeVar("DataT")
json_encoders = {
ObjectID: lambda v: v.encode(),
datetime: lambda dt: int(dt.timestamp()),
Enum: lambda e: e.value,
}
class BaseSchema(BaseModel):
class Config:
arbitrary_types_allowed = True
json_encoders = dict(json_encoders)
orm_mode = True
@classmethod
def _get_value(cls, v: t.Any, *args: t.Any, **kwargs: t.Any) -> t.Any:
if hasattr(v, "__serialize__"):
return v.__serialize__()
for type_, converter in cls.__config__.json_encoders.items():
if isinstance(v, type_):
return converter(v)
return super()._get_value(v, *args, **kwargs)
class ResponseWrapper(GenericModel, t.Generic[DataT]):
"""Generic response wrapper"""
class Config:
arbitrary_types_allowed = True
json_encoders = dict(json_encoders)
error_code: str = ""
status: str = ""
message: str = ""
data: DataT = Field(default_factory=dict)
@validator("status")
def set_status_by_error_code(cls, v, values):
return "failed" if (error_code := values.get("error_code")) else "ok"
class MagicClientSchema(BaseSchema):
id: ObjectID
app_name: str
rate_limit_tier: t.Optional[str] = None
connect_interop: t.Optional[ConnectInteropStatus] = None
is_signing_modal_enabled: bool
global_audience_enabled: bool
public_api_key: str
secret_api_key: str
class AuthUserSchema(BaseSchema):
id: ObjectID
client_id: ObjectID
email: str
phone_number: t.Optional[str] = None
user_type: EntityType = EntityType.MAGIC
provenance: t.Optional[Provenance] = None
date_verified: t.Optional[datetime] = None
is_admin: bool = False
linked_primary_auth_user_id: t.Optional[ObjectID] = None
global_auth_user_id: t.Optional[ObjectID] = None
delegated_user_id: t.Optional[str] = None
delegated_identity_pool_id: t.Optional[str] = None
current_session_token: t.Optional[str] = None
class AuthWalletSchema(BaseSchema):
id: ObjectID
auth_user_id: ObjectID
wallet_type: WalletType
management_type: WalletManagementType
public_address: str
encrypted_private_address: str
network: str
is_exported: bool