workos 1.13.0__py3-none-any.whl → 5.38.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.
Files changed (152) hide show
  1. workos/__about__.py +1 -1
  2. workos/__init__.py +3 -7
  3. workos/_base_client.py +138 -0
  4. workos/_client_configuration.py +10 -0
  5. workos/api_keys.py +53 -0
  6. workos/async_client.py +144 -0
  7. workos/audit_logs.py +125 -0
  8. workos/client.py +105 -20
  9. workos/directory_sync.py +369 -146
  10. workos/events.py +111 -0
  11. workos/exceptions.py +53 -26
  12. workos/fga.py +649 -0
  13. workos/mfa.py +152 -116
  14. workos/organization_domains.py +179 -0
  15. workos/organizations.py +401 -86
  16. workos/passwordless.py +67 -43
  17. workos/pipes.py +93 -0
  18. workos/portal.py +51 -28
  19. workos/session.py +337 -0
  20. workos/sso.py +305 -149
  21. workos/types/__init__.py +4 -0
  22. workos/types/api_keys/__init__.py +1 -0
  23. workos/types/api_keys/api_keys.py +20 -0
  24. workos/types/audit_logs/__init__.py +6 -0
  25. workos/types/audit_logs/audit_log_event.py +16 -0
  26. workos/types/audit_logs/audit_log_event_actor.py +12 -0
  27. workos/types/audit_logs/audit_log_event_context.py +8 -0
  28. workos/types/audit_logs/audit_log_event_target.py +12 -0
  29. workos/types/audit_logs/audit_log_export.py +18 -0
  30. workos/types/audit_logs/audit_log_metadata.py +4 -0
  31. workos/types/directory_sync/__init__.py +5 -0
  32. workos/types/directory_sync/directory.py +31 -0
  33. workos/types/directory_sync/directory_group.py +16 -0
  34. workos/types/directory_sync/directory_state.py +28 -0
  35. workos/types/directory_sync/directory_type.py +24 -0
  36. workos/types/directory_sync/directory_user.py +50 -0
  37. workos/types/directory_sync/list_filters.py +21 -0
  38. workos/types/events/__init__.py +13 -0
  39. workos/types/events/authentication_payload.py +70 -0
  40. workos/types/events/connection_payload_with_legacy_fields.py +5 -0
  41. workos/types/events/directory_group_membership_payload.py +9 -0
  42. workos/types/events/directory_group_with_previous_attributes.py +6 -0
  43. workos/types/events/directory_payload.py +16 -0
  44. workos/types/events/directory_payload_with_legacy_fields.py +29 -0
  45. workos/types/events/directory_user_with_previous_attributes.py +6 -0
  46. workos/types/events/event.py +324 -0
  47. workos/types/events/event_model.py +103 -0
  48. workos/types/events/event_type.py +59 -0
  49. workos/types/events/list_filters.py +10 -0
  50. workos/types/events/organization_domain_verification_failed_payload.py +14 -0
  51. workos/types/events/previous_attributes.py +3 -0
  52. workos/types/events/session_payload.py +27 -0
  53. workos/types/feature_flags/__init__.py +3 -0
  54. workos/types/feature_flags/feature_flag.py +12 -0
  55. workos/types/feature_flags/list_filters.py +5 -0
  56. workos/types/fga/__init__.py +5 -0
  57. workos/types/fga/authorization_resource_types.py +9 -0
  58. workos/types/fga/authorization_resources.py +10 -0
  59. workos/types/fga/check.py +51 -0
  60. workos/types/fga/list_filters.py +24 -0
  61. workos/types/fga/warnings.py +33 -0
  62. workos/types/fga/warrant.py +49 -0
  63. workos/types/list_resource.py +198 -0
  64. workos/types/metadata.py +4 -0
  65. workos/types/mfa/__init__.py +5 -0
  66. workos/types/mfa/authentication_challenge.py +14 -0
  67. workos/types/mfa/authentication_challenge_verification_response.py +9 -0
  68. workos/types/mfa/authentication_factor.py +70 -0
  69. workos/types/mfa/authentication_factor_totp_and_challenge_response.py +10 -0
  70. workos/types/mfa/enroll_authentication_factor_type.py +8 -0
  71. workos/types/organization_domains/__init__.py +1 -0
  72. workos/types/organization_domains/organization_domain.py +18 -0
  73. workos/types/organizations/__init__.py +6 -0
  74. workos/types/organizations/domain_data_input.py +7 -0
  75. workos/types/organizations/list_filters.py +6 -0
  76. workos/types/organizations/organization.py +13 -0
  77. workos/types/organizations/organization_common.py +12 -0
  78. workos/types/passwordless/__init__.py +2 -0
  79. workos/types/passwordless/passwordless_session.py +12 -0
  80. workos/types/passwordless/passwordless_session_type.py +3 -0
  81. workos/types/pipes/__init__.py +6 -0
  82. workos/types/pipes/pipes.py +34 -0
  83. workos/types/portal/__init__.py +2 -0
  84. workos/types/portal/portal_link.py +7 -0
  85. workos/types/portal/portal_link_intent.py +11 -0
  86. workos/types/portal/portal_link_intent_options.py +9 -0
  87. workos/types/roles/__init__.py +0 -0
  88. workos/types/roles/role.py +27 -0
  89. workos/types/sso/__init__.py +4 -0
  90. workos/types/sso/connection.py +70 -0
  91. workos/types/sso/connection_domain.py +8 -0
  92. workos/types/sso/profile.py +35 -0
  93. workos/types/sso/sso_provider_type.py +10 -0
  94. workos/types/user_management/__init__.py +12 -0
  95. workos/types/user_management/authenticate_with_common.py +66 -0
  96. workos/types/user_management/authentication_response.py +53 -0
  97. workos/types/user_management/email_verification.py +18 -0
  98. workos/types/user_management/impersonator.py +8 -0
  99. workos/types/user_management/invitation.py +26 -0
  100. workos/types/user_management/list_filters.py +29 -0
  101. workos/types/user_management/magic_auth.py +18 -0
  102. workos/types/user_management/oauth_tokens.py +21 -0
  103. workos/types/user_management/organization_membership.py +25 -0
  104. workos/types/user_management/password_hash_type.py +4 -0
  105. workos/types/user_management/password_reset.py +18 -0
  106. workos/types/user_management/screen_hint.py +3 -0
  107. workos/types/user_management/session.py +79 -0
  108. workos/types/user_management/user.py +22 -0
  109. workos/types/user_management/user_management_provider_type.py +11 -0
  110. workos/types/vault/__init__.py +2 -0
  111. workos/types/vault/key.py +25 -0
  112. workos/types/vault/object.py +38 -0
  113. workos/types/webhooks/__init__.py +0 -0
  114. workos/types/webhooks/webhook.py +330 -0
  115. workos/types/webhooks/webhook_model.py +14 -0
  116. workos/types/webhooks/webhook_payload.py +4 -0
  117. workos/types/widgets/__init__.py +2 -0
  118. workos/types/widgets/widget_scope.py +4 -0
  119. workos/types/widgets/widget_token_response.py +7 -0
  120. workos/types/workos_model.py +26 -0
  121. workos/typing/__init__.py +1 -0
  122. workos/typing/literals.py +32 -0
  123. workos/typing/sync_or_async.py +5 -0
  124. workos/typing/untyped_literal.py +37 -0
  125. workos/typing/webhooks.py +18 -0
  126. workos/user_management.py +2400 -0
  127. workos/utils/_base_http_client.py +252 -0
  128. workos/utils/crypto_provider.py +39 -0
  129. workos/utils/http_client.py +214 -0
  130. workos/utils/pagination_order.py +4 -0
  131. workos/utils/request_helper.py +27 -0
  132. workos/vault.py +544 -0
  133. workos/webhooks.py +96 -39
  134. workos/widgets.py +55 -0
  135. {workos-1.13.0.dist-info → workos-5.38.0.dist-info}/LICENSE +1 -1
  136. {workos-1.13.0.dist-info → workos-5.38.0.dist-info}/METADATA +47 -22
  137. workos-5.38.0.dist-info/RECORD +141 -0
  138. {workos-1.13.0.dist-info → workos-5.38.0.dist-info}/WHEEL +1 -1
  139. workos/audit_trail.py +0 -179
  140. workos/resources/base.py +0 -36
  141. workos/resources/directory_sync.py +0 -28
  142. workos/resources/event.py +0 -42
  143. workos/resources/event_action.py +0 -11
  144. workos/resources/mfa.py +0 -32
  145. workos/resources/sso.py +0 -53
  146. workos/utils/connection_types.py +0 -35
  147. workos/utils/pagiantion_order.py +0 -6
  148. workos/utils/request.py +0 -100
  149. workos/utils/validation.py +0 -60
  150. workos-1.13.0.dist-info/RECORD +0 -29
  151. /workos/{resources/__init__.py → py.typed} +0 -0
  152. {workos-1.13.0.dist-info → workos-5.38.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,103 @@
1
+ from typing import Generic, Literal, TypeVar
2
+ from workos.types.user_management import OrganizationMembership, User
3
+ from workos.types.workos_model import WorkOSModel
4
+ from workos.types.directory_sync.directory_group import DirectoryGroup
5
+ from workos.types.directory_sync.directory_user import DirectoryUser
6
+ from workos.types.events.authentication_payload import (
7
+ AuthenticationEmailVerificationSucceededPayload,
8
+ AuthenticationMagicAuthFailedPayload,
9
+ AuthenticationMagicAuthSucceededPayload,
10
+ AuthenticationMfaSucceededPayload,
11
+ AuthenticationOauthFailedPayload,
12
+ AuthenticationOauthSucceededPayload,
13
+ AuthenticationPasswordFailedPayload,
14
+ AuthenticationPasswordSucceededPayload,
15
+ AuthenticationSsoFailedPayload,
16
+ AuthenticationSsoSucceededPayload,
17
+ )
18
+ from workos.types.events.connection_payload_with_legacy_fields import (
19
+ ConnectionPayloadWithLegacyFields,
20
+ )
21
+ from workos.types.events.directory_group_membership_payload import (
22
+ DirectoryGroupMembershipPayload,
23
+ )
24
+ from workos.types.events.directory_group_with_previous_attributes import (
25
+ DirectoryGroupWithPreviousAttributes,
26
+ )
27
+ from workos.types.events.directory_payload import DirectoryPayload
28
+ from workos.types.events.directory_payload_with_legacy_fields import (
29
+ DirectoryPayloadWithLegacyFields,
30
+ DirectoryPayloadWithLegacyFieldsForEventsApi,
31
+ )
32
+ from workos.types.events.directory_user_with_previous_attributes import (
33
+ DirectoryUserWithPreviousAttributes,
34
+ )
35
+ from workos.types.events.organization_domain_verification_failed_payload import (
36
+ OrganizationDomainVerificationFailedPayload,
37
+ )
38
+
39
+ from workos.types.events.session_payload import (
40
+ SessionCreatedPayload,
41
+ SessionRevokedPayload,
42
+ )
43
+ from workos.types.organizations.organization_common import OrganizationCommon
44
+ from workos.types.organization_domains import OrganizationDomain
45
+ from workos.types.roles.role import EventRole
46
+ from workos.types.sso.connection import Connection
47
+ from workos.types.user_management.email_verification import (
48
+ EmailVerificationCommon,
49
+ )
50
+ from workos.types.user_management.invitation import InvitationCommon
51
+ from workos.types.user_management.magic_auth import MagicAuthCommon
52
+ from workos.types.user_management.password_reset import PasswordResetCommon
53
+
54
+
55
+ EventPayload = TypeVar(
56
+ "EventPayload",
57
+ AuthenticationEmailVerificationSucceededPayload,
58
+ AuthenticationMagicAuthFailedPayload,
59
+ AuthenticationMagicAuthSucceededPayload,
60
+ AuthenticationMfaSucceededPayload,
61
+ AuthenticationOauthFailedPayload,
62
+ AuthenticationOauthSucceededPayload,
63
+ AuthenticationPasswordFailedPayload,
64
+ AuthenticationPasswordSucceededPayload,
65
+ AuthenticationSsoFailedPayload,
66
+ AuthenticationSsoSucceededPayload,
67
+ Connection,
68
+ ConnectionPayloadWithLegacyFields,
69
+ DirectoryPayload,
70
+ DirectoryPayloadWithLegacyFields,
71
+ # TODO: Remove once merged with DirectoryPayloadWithLegacyFields in next major release.
72
+ DirectoryPayloadWithLegacyFieldsForEventsApi,
73
+ DirectoryGroup,
74
+ DirectoryGroupWithPreviousAttributes,
75
+ DirectoryUser,
76
+ DirectoryUserWithPreviousAttributes,
77
+ DirectoryGroupMembershipPayload,
78
+ EmailVerificationCommon,
79
+ EventRole,
80
+ InvitationCommon,
81
+ MagicAuthCommon,
82
+ OrganizationCommon,
83
+ OrganizationDomain,
84
+ OrganizationDomainVerificationFailedPayload,
85
+ OrganizationMembership,
86
+ PasswordResetCommon,
87
+ SessionCreatedPayload,
88
+ SessionRevokedPayload,
89
+ User,
90
+ )
91
+
92
+
93
+ class EventModel(WorkOSModel, Generic[EventPayload]):
94
+ # TODO: fix these docs
95
+ """Representation of an Event returned from the Events API or via Webhook.
96
+ Attributes:
97
+ OBJECT_FIELDS (list): List of fields an Event is comprised of.
98
+ """
99
+
100
+ id: str
101
+ object: Literal["event"]
102
+ data: EventPayload
103
+ created_at: str
@@ -0,0 +1,59 @@
1
+ from typing import Literal, TypeVar
2
+
3
+ # README
4
+ # When adding a new event type, ensure a new event class is created
5
+ # and added to the Event class union type in event.py.
6
+
7
+ EventType = Literal[
8
+ "authentication.email_verification_succeeded",
9
+ "authentication.magic_auth_failed",
10
+ "authentication.magic_auth_succeeded",
11
+ "authentication.mfa_succeeded",
12
+ "authentication.oauth_failed",
13
+ "authentication.oauth_succeeded",
14
+ "authentication.password_failed",
15
+ "authentication.password_succeeded",
16
+ "authentication.sso_failed",
17
+ "authentication.sso_succeeded",
18
+ "connection.activated",
19
+ "connection.deactivated",
20
+ "connection.deleted",
21
+ "dsync.activated",
22
+ "dsync.deleted",
23
+ "dsync.group.created",
24
+ "dsync.group.deleted",
25
+ "dsync.group.updated",
26
+ "dsync.user.created",
27
+ "dsync.user.deleted",
28
+ "dsync.user.updated",
29
+ "dsync.group.user_added",
30
+ "dsync.group.user_removed",
31
+ "email_verification.created",
32
+ "invitation.accepted",
33
+ "invitation.created",
34
+ "invitation.revoked",
35
+ "magic_auth.created",
36
+ "organization.created",
37
+ "organization.deleted",
38
+ "organization.updated",
39
+ "organization_domain.verification_failed",
40
+ "organization_domain.verified",
41
+ "organization_domain.created",
42
+ "organization_domain.deleted",
43
+ "organization_domain.updated",
44
+ "organization_membership.created",
45
+ "organization_membership.deleted",
46
+ "organization_membership.updated",
47
+ "password_reset.created",
48
+ "password_reset.succeeded",
49
+ "role.created",
50
+ "role.deleted",
51
+ "role.updated",
52
+ "session.created",
53
+ "session.revoked",
54
+ "user.created",
55
+ "user.deleted",
56
+ "user.updated",
57
+ ]
58
+
59
+ EventTypeDiscriminator = TypeVar("EventTypeDiscriminator", bound=EventType)
@@ -0,0 +1,10 @@
1
+ from typing import Optional, Sequence
2
+ from workos.types.events import EventType
3
+ from workos.types.list_resource import ListArgs
4
+
5
+
6
+ class EventsListFilters(ListArgs, total=False):
7
+ events: Sequence[EventType]
8
+ organization_id: Optional[str]
9
+ range_start: Optional[str]
10
+ range_end: Optional[str]
@@ -0,0 +1,14 @@
1
+ from typing import Literal
2
+ from workos.types.workos_model import WorkOSModel
3
+ from workos.types.organization_domains import OrganizationDomain
4
+ from workos.typing.literals import LiteralOrUntyped
5
+
6
+
7
+ class OrganizationDomainVerificationFailedPayload(WorkOSModel):
8
+ reason: LiteralOrUntyped[
9
+ Literal[
10
+ "domain_verification_period_expired",
11
+ "domain_verified_by_other_organization",
12
+ ]
13
+ ]
14
+ organization_domain: OrganizationDomain
@@ -0,0 +1,3 @@
1
+ from typing import Any, Mapping
2
+
3
+ PreviousAttributes = Mapping[str, Any]
@@ -0,0 +1,27 @@
1
+ from typing import Literal, Optional
2
+ from workos.types.workos_model import WorkOSModel
3
+ from workos.types.user_management.impersonator import Impersonator
4
+
5
+
6
+ class SessionCreatedPayload(WorkOSModel):
7
+ object: Literal["session"]
8
+ id: str
9
+ impersonator: Optional[Impersonator] = None
10
+ ip_address: Optional[str] = None
11
+ organization_id: Optional[str] = None
12
+ user_agent: Optional[str] = None
13
+ user_id: str
14
+ created_at: str
15
+ updated_at: str
16
+
17
+
18
+ class SessionRevokedPayload(WorkOSModel):
19
+ object: Literal["session"]
20
+ id: str
21
+ impersonator: Optional[Impersonator] = None
22
+ ip_address: Optional[str] = None
23
+ organization_id: Optional[str] = None
24
+ user_agent: Optional[str] = None
25
+ user_id: str
26
+ created_at: str
27
+ updated_at: str
@@ -0,0 +1,3 @@
1
+ from workos.types.feature_flags.feature_flag import FeatureFlag
2
+
3
+ __all__ = ["FeatureFlag"]
@@ -0,0 +1,12 @@
1
+ from typing import Literal, Optional
2
+ from workos.types.workos_model import WorkOSModel
3
+
4
+
5
+ class FeatureFlag(WorkOSModel):
6
+ id: str
7
+ object: Literal["feature_flag"]
8
+ slug: str
9
+ name: str
10
+ description: Optional[str]
11
+ created_at: str
12
+ updated_at: str
@@ -0,0 +1,5 @@
1
+ from workos.types.list_resource import ListArgs
2
+
3
+
4
+ class FeatureFlagListFilters(ListArgs, total=False):
5
+ pass
@@ -0,0 +1,5 @@
1
+ from .check import *
2
+ from .authorization_resource_types import *
3
+ from .authorization_resources import *
4
+ from .warrant import *
5
+ from .warnings import *
@@ -0,0 +1,9 @@
1
+ from typing import Any, Mapping, Optional
2
+
3
+ from workos.types.workos_model import WorkOSModel
4
+
5
+
6
+ class AuthorizationResourceType(WorkOSModel):
7
+ type: str
8
+ relations: Mapping[str, Any]
9
+ created_at: Optional[str] = None
@@ -0,0 +1,10 @@
1
+ from typing import Any, Mapping, Optional
2
+
3
+ from workos.types.workos_model import WorkOSModel
4
+
5
+
6
+ class AuthorizationResource(WorkOSModel):
7
+ resource_type: str
8
+ resource_id: str
9
+ meta: Optional[Mapping[str, Any]] = None
10
+ created_at: Optional[str] = None
@@ -0,0 +1,51 @@
1
+ from typing import Any, Literal, Mapping, Optional, Sequence, TypedDict
2
+
3
+ from workos.types.workos_model import WorkOSModel
4
+ from workos.typing.literals import LiteralOrUntyped
5
+
6
+ from .warnings import FGAWarning
7
+ from .warrant import Subject, SubjectInput
8
+
9
+ CheckOperation = Literal["any_of", "all_of", "batch"]
10
+
11
+
12
+ class WarrantCheckInput(TypedDict, total=False):
13
+ resource_type: str
14
+ resource_id: str
15
+ relation: str
16
+ subject: SubjectInput
17
+ context: Optional[Mapping[str, Any]]
18
+
19
+
20
+ class WarrantCheck(WorkOSModel):
21
+ resource_type: str
22
+ resource_id: str
23
+ relation: str
24
+ subject: Subject
25
+ context: Optional[Mapping[str, Any]] = None
26
+
27
+
28
+ class DecisionTreeNode(WorkOSModel):
29
+ check: WarrantCheck
30
+ decision: str
31
+ processing_time: int
32
+ children: Optional[Sequence["DecisionTreeNode"]] = None
33
+ policy: Optional[str] = None
34
+
35
+
36
+ class DebugInfo(WorkOSModel):
37
+ processing_time: int
38
+ decision_tree: DecisionTreeNode
39
+
40
+
41
+ CheckResult = Literal["authorized", "not_authorized"]
42
+
43
+
44
+ class CheckResponse(WorkOSModel):
45
+ result: LiteralOrUntyped[CheckResult]
46
+ is_implicit: bool
47
+ debug_info: Optional[DebugInfo] = None
48
+ warnings: Optional[Sequence[FGAWarning]] = None
49
+
50
+ def authorized(self) -> bool:
51
+ return self.result == "authorized"
@@ -0,0 +1,24 @@
1
+ from typing import Mapping, Optional, Any
2
+
3
+ from workos.types.list_resource import ListArgs
4
+
5
+
6
+ class AuthorizationResourceListFilters(ListArgs, total=False):
7
+ resource_type: Optional[str]
8
+ search: Optional[str]
9
+
10
+
11
+ class WarrantListFilters(ListArgs, total=False):
12
+ resource_type: Optional[str]
13
+ resource_id: Optional[str]
14
+ relation: Optional[str]
15
+ subject_type: Optional[str]
16
+ subject_id: Optional[str]
17
+ subject_relation: Optional[str]
18
+ warrant_token: Optional[str]
19
+
20
+
21
+ class WarrantQueryListFilters(ListArgs, total=False):
22
+ q: Optional[str]
23
+ context: Optional[Mapping[str, Any]]
24
+ warrant_token: Optional[str]
@@ -0,0 +1,33 @@
1
+ from typing import Sequence, Union, Any, Dict, Literal
2
+ from typing_extensions import Annotated
3
+
4
+ from pydantic import BeforeValidator
5
+ from pydantic_core.core_schema import ValidationInfo
6
+
7
+ from workos.types.workos_model import WorkOSModel
8
+
9
+
10
+ class FGABaseWarning(WorkOSModel):
11
+ code: str
12
+ message: str
13
+
14
+
15
+ class MissingContextKeysWarning(FGABaseWarning):
16
+ code: Literal["missing_context_keys"]
17
+ keys: Sequence[str]
18
+
19
+
20
+ def fga_warning_dispatch_validator(
21
+ value: Dict[str, Any], info: ValidationInfo
22
+ ) -> FGABaseWarning:
23
+ if value.get("code") == "missing_context_keys":
24
+ return MissingContextKeysWarning.model_validate(value)
25
+
26
+ # Fallback to the base warning model
27
+ return FGABaseWarning.model_validate(value)
28
+
29
+
30
+ FGAWarning = Annotated[
31
+ Union[MissingContextKeysWarning, FGABaseWarning],
32
+ BeforeValidator(fga_warning_dispatch_validator),
33
+ ]
@@ -0,0 +1,49 @@
1
+ from typing import Literal, Mapping, Optional, Any
2
+ from typing_extensions import TypedDict
3
+
4
+ from workos.types.workos_model import WorkOSModel
5
+
6
+
7
+ class SubjectInput(TypedDict, total=False):
8
+ resource_type: str
9
+ resource_id: str
10
+ relation: Optional[str]
11
+
12
+
13
+ class Subject(WorkOSModel):
14
+ resource_type: str
15
+ resource_id: str
16
+ relation: Optional[str] = None
17
+
18
+
19
+ class Warrant(WorkOSModel):
20
+ resource_type: str
21
+ resource_id: str
22
+ relation: str
23
+ subject: Subject
24
+ policy: Optional[str] = None
25
+
26
+
27
+ class WriteWarrantResponse(WorkOSModel):
28
+ warrant_token: str
29
+
30
+
31
+ WarrantWriteOperation = Literal["create", "delete"]
32
+
33
+
34
+ class WarrantWrite(TypedDict, total=False):
35
+ op: WarrantWriteOperation
36
+ resource_type: str
37
+ resource_id: str
38
+ relation: str
39
+ subject: SubjectInput
40
+ policy: Optional[str]
41
+
42
+
43
+ class WarrantQueryResult(WorkOSModel):
44
+ resource_type: str
45
+ resource_id: str
46
+ relation: str
47
+ warrant: Warrant
48
+ is_implicit: bool
49
+ meta: Optional[Mapping[str, Any]] = None
@@ -0,0 +1,198 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import (
3
+ Any,
4
+ Awaitable,
5
+ AsyncIterator,
6
+ Dict,
7
+ Literal,
8
+ Mapping,
9
+ Sequence,
10
+ Tuple,
11
+ TypeVar,
12
+ Generic,
13
+ Callable,
14
+ Iterator,
15
+ Optional,
16
+ Union,
17
+ cast,
18
+ )
19
+ from typing_extensions import Required, TypedDict
20
+ from workos.types.directory_sync import (
21
+ Directory,
22
+ DirectoryGroup,
23
+ DirectoryUserWithGroups,
24
+ )
25
+ from workos.types.events import Event
26
+ from workos.types.feature_flags import FeatureFlag
27
+ from workos.types.fga import (
28
+ Warrant,
29
+ AuthorizationResource,
30
+ AuthorizationResourceType,
31
+ WarrantQueryResult,
32
+ )
33
+ from workos.types.mfa import AuthenticationFactor
34
+ from workos.types.organizations import Organization
35
+ from workos.types.sso import ConnectionWithDomains
36
+ from workos.types.user_management import Invitation, OrganizationMembership, User
37
+ from workos.types.user_management.session import Session as UserManagementSession
38
+ from workos.types.vault import ObjectDigest
39
+ from workos.types.workos_model import WorkOSModel
40
+ from workos.utils.request_helper import DEFAULT_LIST_RESPONSE_LIMIT
41
+
42
+ ListableResource = TypeVar(
43
+ # add all possible generics of List Resource
44
+ "ListableResource",
45
+ AuthenticationFactor,
46
+ ConnectionWithDomains,
47
+ Directory,
48
+ DirectoryGroup,
49
+ DirectoryUserWithGroups,
50
+ Event,
51
+ FeatureFlag,
52
+ Invitation,
53
+ Organization,
54
+ OrganizationMembership,
55
+ AuthorizationResource,
56
+ AuthorizationResourceType,
57
+ User,
58
+ UserManagementSession,
59
+ ObjectDigest,
60
+ Warrant,
61
+ WarrantQueryResult,
62
+ )
63
+
64
+
65
+ class ListAfterMetadata(BaseModel):
66
+ after: Optional[str] = None
67
+
68
+
69
+ class ListMetadata(ListAfterMetadata):
70
+ before: Optional[str] = None
71
+
72
+
73
+ ListMetadataType = TypeVar("ListMetadataType", ListAfterMetadata, ListMetadata)
74
+
75
+
76
+ class ListPage(WorkOSModel, Generic[ListableResource]):
77
+ object: Literal["list"]
78
+ data: Sequence[ListableResource]
79
+ list_metadata: ListMetadata
80
+
81
+
82
+ class ListArgs(TypedDict, total=False):
83
+ before: Optional[str]
84
+ after: Optional[str]
85
+ limit: Required[int]
86
+ order: Optional[Literal["asc", "desc"]]
87
+
88
+
89
+ ListAndFilterParams = TypeVar("ListAndFilterParams", bound=ListArgs)
90
+
91
+
92
+ class WorkOSListResource(
93
+ WorkOSModel,
94
+ Generic[ListableResource, ListAndFilterParams, ListMetadataType],
95
+ ):
96
+ object: Literal["list"]
97
+ data: Sequence[ListableResource]
98
+ list_metadata: ListMetadataType
99
+
100
+ # TODO: Fix type hinting for list_method to support both sync and async
101
+ list_method: Union[
102
+ Callable[
103
+ ...,
104
+ "WorkOSListResource[ListableResource, ListAndFilterParams, ListMetadataType]",
105
+ ],
106
+ Callable[
107
+ ...,
108
+ "Awaitable[WorkOSListResource[ListableResource, ListAndFilterParams, ListMetadataType]]",
109
+ ],
110
+ ] = Field(exclude=True)
111
+ list_args: ListAndFilterParams = Field(exclude=True)
112
+
113
+ def _parse_params(
114
+ self, limit_override: Optional[int] = None
115
+ ) -> Tuple[Dict[str, Union[int, str, None]], Mapping[str, Any]]:
116
+ fixed_pagination_params = cast(
117
+ # Type hints consider this a mismatch because it assume the dictionary is dict[str, int]
118
+ Dict[str, Union[int, str, None]],
119
+ {
120
+ "limit": limit_override or self.list_args["limit"],
121
+ },
122
+ )
123
+ if "order" in self.list_args:
124
+ fixed_pagination_params["order"] = self.list_args["order"]
125
+
126
+ # Omit common list parameters
127
+ filter_params = {
128
+ k: v
129
+ for k, v in self.list_args.items()
130
+ if k not in {"order", "limit", "before", "after"}
131
+ }
132
+
133
+ return fixed_pagination_params, filter_params
134
+
135
+ # Pydantic uses a custom `__iter__` method to support casting BaseModels
136
+ # to dictionaries. e.g. dict(model).
137
+ # As we want to support `for item in page`, this is inherently incompatible
138
+ # with the default pydantic behaviour. It is not possible to support both
139
+ # use cases at once. Fortunately, this is not a big deal as all other pydantic
140
+ # methods should continue to work as expected as there is an alternative method
141
+ # to cast a model to a dictionary, model.dict(), which is used internally
142
+ # by pydantic.
143
+ def __iter__(self) -> Iterator[ListableResource]: # type: ignore
144
+ next_page: WorkOSListResource[
145
+ ListableResource, ListAndFilterParams, ListMetadataType
146
+ ]
147
+ after = self.list_metadata.after
148
+ fixed_pagination_params, filter_params = self._parse_params(
149
+ # Singe we're auto-paginating, ignore the original limit and use the default
150
+ limit_override=DEFAULT_LIST_RESPONSE_LIMIT
151
+ )
152
+ index: int = 0
153
+
154
+ while True:
155
+ if index >= len(self.data):
156
+ if after is not None:
157
+ # TODO: Fix type hinting for list_method to support both sync and async
158
+ # We use a union to support both sync and async methods,
159
+ # but when we get to the particular implementation, it
160
+ # doesn't know which one it is. It's safe, but should be fixed.
161
+ next_page = self.list_method(
162
+ after=after, **fixed_pagination_params, **filter_params
163
+ ) # type: ignore
164
+ self.data = next_page.data
165
+ after = next_page.list_metadata.after
166
+ index = 0
167
+ continue
168
+ else:
169
+ return
170
+ yield self.data[index]
171
+ index += 1
172
+
173
+ async def __aiter__(self) -> AsyncIterator[ListableResource]:
174
+ next_page: WorkOSListResource[
175
+ ListableResource, ListAndFilterParams, ListMetadataType
176
+ ]
177
+ after = self.list_metadata.after
178
+ fixed_pagination_params, filter_params = self._parse_params()
179
+ index: int = 0
180
+
181
+ while True:
182
+ if index >= len(self.data):
183
+ if after is not None:
184
+ # TODO: Fix type hinting for list_method to support both sync and async
185
+ # We use a union to support both sync and async methods,
186
+ # but when we get to the particular implementation, it
187
+ # doesn't know which one it is. It's safe, but should be fixed.
188
+ next_page = await self.list_method(
189
+ after=after, **fixed_pagination_params, **filter_params
190
+ ) # type: ignore
191
+ self.data = next_page.data
192
+ after = next_page.list_metadata.after
193
+ index = 0
194
+ continue
195
+ else:
196
+ return
197
+ yield self.data[index]
198
+ index += 1
@@ -0,0 +1,4 @@
1
+ from typing import Dict
2
+
3
+
4
+ Metadata = Dict[str, str]
@@ -0,0 +1,5 @@
1
+ from .authentication_challenge_verification_response import *
2
+ from .authentication_challenge import *
3
+ from .authentication_factor_totp_and_challenge_response import *
4
+ from .authentication_factor import *
5
+ from .enroll_authentication_factor_type import *
@@ -0,0 +1,14 @@
1
+ from typing import Literal, Optional
2
+ from workos.types.workos_model import WorkOSModel
3
+
4
+
5
+ class AuthenticationChallenge(WorkOSModel):
6
+ """Representation of a MFA Challenge Response as returned by WorkOS through the MFA feature."""
7
+
8
+ object: Literal["authentication_challenge"]
9
+ id: str
10
+ created_at: str
11
+ updated_at: str
12
+ expires_at: Optional[str] = None
13
+ code: Optional[str] = None
14
+ authentication_factor_id: str
@@ -0,0 +1,9 @@
1
+ from workos.types.workos_model import WorkOSModel
2
+ from workos.types.mfa.authentication_challenge import AuthenticationChallenge
3
+
4
+
5
+ class AuthenticationChallengeVerificationResponse(WorkOSModel):
6
+ """Representation of a WorkOS MFA Challenge Verification Response."""
7
+
8
+ challenge: AuthenticationChallenge
9
+ valid: bool