|
| 1 | +import type { EnterpriseAccountConnectionJSON, EnterpriseAccountJSON } from './JSON'; |
| 2 | +import { Verification } from './Verification'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Represents an enterprise SSO connection associated with an enterprise account. |
| 6 | + */ |
| 7 | +export class EnterpriseAccountConnection { |
| 8 | + constructor( |
| 9 | + /** |
| 10 | + * The unique identifier for this enterprise connection. |
| 11 | + */ |
| 12 | + readonly id: string, |
| 13 | + /** |
| 14 | + * Whether the connection is currently active. |
| 15 | + */ |
| 16 | + readonly active: boolean, |
| 17 | + /** |
| 18 | + * Whether IdP-initiated SSO is allowed. |
| 19 | + */ |
| 20 | + readonly allowIdpInitiated: boolean, |
| 21 | + /** |
| 22 | + * Whether subdomains are allowed for this connection. |
| 23 | + */ |
| 24 | + readonly allowSubdomains: boolean, |
| 25 | + /** |
| 26 | + * Whether additional identifications are disabled for users authenticating via this connection. |
| 27 | + */ |
| 28 | + readonly disableAdditionalIdentifications: boolean, |
| 29 | + /** |
| 30 | + * The domain associated with this connection. |
| 31 | + */ |
| 32 | + readonly domain: string, |
| 33 | + /** |
| 34 | + * The public URL of the connection's logo, if available. |
| 35 | + */ |
| 36 | + readonly logoPublicUrl: string | null, |
| 37 | + /** |
| 38 | + * The name of the enterprise connection. |
| 39 | + */ |
| 40 | + readonly name: string, |
| 41 | + /** |
| 42 | + * The SSO protocol used (e.g., `saml` or `oauth`). |
| 43 | + */ |
| 44 | + readonly protocol: string, |
| 45 | + /** |
| 46 | + * The SSO provider (e.g., `saml_custom`, `saml_okta`). |
| 47 | + */ |
| 48 | + readonly provider: string, |
| 49 | + /** |
| 50 | + * Whether user attributes are synced from the IdP. |
| 51 | + */ |
| 52 | + readonly syncUserAttributes: boolean, |
| 53 | + /** |
| 54 | + * The date when this connection was created. |
| 55 | + */ |
| 56 | + readonly createdAt: number, |
| 57 | + /** |
| 58 | + * The date when this connection was last updated. |
| 59 | + */ |
| 60 | + readonly updatedAt: number, |
| 61 | + ) {} |
| 62 | + |
| 63 | + static fromJSON(data: EnterpriseAccountConnectionJSON): EnterpriseAccountConnection { |
| 64 | + return new EnterpriseAccountConnection( |
| 65 | + data.id, |
| 66 | + data.active, |
| 67 | + data.allow_idp_initiated, |
| 68 | + data.allow_subdomains, |
| 69 | + data.disable_additional_identifications, |
| 70 | + data.domain, |
| 71 | + data.logo_public_url, |
| 72 | + data.name, |
| 73 | + data.protocol, |
| 74 | + data.provider, |
| 75 | + data.sync_user_attributes, |
| 76 | + data.created_at, |
| 77 | + data.updated_at, |
| 78 | + ); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +/** |
| 83 | + * The Backend `EnterpriseAccount` object represents an identification obtained via enterprise SSO (SAML or OIDC). |
| 84 | + */ |
| 85 | +export class EnterpriseAccount { |
| 86 | + constructor( |
| 87 | + /** |
| 88 | + * The unique identifier for this enterprise account. |
| 89 | + */ |
| 90 | + readonly id: string, |
| 91 | + /** |
| 92 | + * Whether this enterprise account is currently active. |
| 93 | + */ |
| 94 | + readonly active: boolean, |
| 95 | + /** |
| 96 | + * The email address associated with this enterprise account. |
| 97 | + */ |
| 98 | + readonly emailAddress: string, |
| 99 | + /** |
| 100 | + * The enterprise connection through which this account was authenticated. |
| 101 | + */ |
| 102 | + readonly enterpriseConnection: EnterpriseAccountConnection | null, |
| 103 | + /** |
| 104 | + * The user's first name as provided by the IdP. |
| 105 | + */ |
| 106 | + readonly firstName: string | null, |
| 107 | + /** |
| 108 | + * The user's last name as provided by the IdP. |
| 109 | + */ |
| 110 | + readonly lastName: string | null, |
| 111 | + /** |
| 112 | + * The SSO protocol used (e.g., `saml` or `oauth`). |
| 113 | + */ |
| 114 | + readonly protocol: string, |
| 115 | + /** |
| 116 | + * The SSO provider (e.g., `saml_custom`, `saml_okta`). |
| 117 | + */ |
| 118 | + readonly provider: string, |
| 119 | + /** |
| 120 | + * The unique ID of the user in the provider. |
| 121 | + */ |
| 122 | + readonly providerUserId: string | null, |
| 123 | + /** |
| 124 | + * Metadata that can be read from the Frontend API and Backend API and can be set only from the Backend API. |
| 125 | + */ |
| 126 | + readonly publicMetadata: Record<string, unknown>, |
| 127 | + /** |
| 128 | + * An object holding information on the verification of this enterprise account. |
| 129 | + */ |
| 130 | + readonly verification: Verification | null, |
| 131 | + /** |
| 132 | + * The date when the user last authenticated via this enterprise account. |
| 133 | + */ |
| 134 | + readonly lastAuthenticatedAt: number | null, |
| 135 | + /** |
| 136 | + * The ID of the enterprise connection associated with this account. |
| 137 | + */ |
| 138 | + readonly enterpriseConnectionId: string | null, |
| 139 | + ) {} |
| 140 | + |
| 141 | + static fromJSON(data: EnterpriseAccountJSON): EnterpriseAccount { |
| 142 | + return new EnterpriseAccount( |
| 143 | + data.id, |
| 144 | + data.active, |
| 145 | + data.email_address, |
| 146 | + data.enterprise_connection && EnterpriseAccountConnection.fromJSON(data.enterprise_connection), |
| 147 | + data.first_name, |
| 148 | + data.last_name, |
| 149 | + data.protocol, |
| 150 | + data.provider, |
| 151 | + data.provider_user_id, |
| 152 | + data.public_metadata, |
| 153 | + data.verification && Verification.fromJSON(data.verification), |
| 154 | + data.last_authenticated_at, |
| 155 | + data.enterprise_connection_id, |
| 156 | + ); |
| 157 | + } |
| 158 | +} |
0 commit comments