use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum InvitationTargetType {
Email,
Phone,
Share,
Internal,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CreateInvitationTargetType {
Email,
Phone,
Internal,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum InvitationType {
SingleUse,
MultiUse,
Autojoin,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum InvitationStatus {
Queued,
Sending,
Sent,
Delivered,
Accepted,
Shared,
Unfurled,
AcceptedElsewhere,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DeliveryType {
Email,
Phone,
Share,
Internal,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct User {
pub id: String,
pub email: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub user_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub user_avatar_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub admin_scopes: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_email_domains: Option<Vec<String>>,
#[serde(flatten)]
pub extra: Option<HashMap<String, serde_json::Value>>,
}
impl User {
pub fn new(id: &str, email: &str) -> Self {
Self {
id: id.to_string(),
email: email.to_string(),
name: None,
avatar_url: None,
user_name: None,
user_avatar_url: None,
admin_scopes: None,
allowed_email_domains: None,
extra: None,
}
}
pub fn with_name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
pub fn with_avatar_url(mut self, avatar_url: &str) -> Self {
self.avatar_url = Some(avatar_url.to_string());
self
}
#[deprecated(note = "Use with_name instead")]
pub fn with_user_name(mut self, name: &str) -> Self {
self.user_name = Some(name.to_string());
self
}
#[deprecated(note = "Use with_avatar_url instead")]
pub fn with_user_avatar_url(mut self, avatar_url: &str) -> Self {
self.user_avatar_url = Some(avatar_url.to_string());
self
}
pub fn with_admin_scopes(mut self, scopes: Vec<String>) -> Self {
self.admin_scopes = Some(scopes);
self
}
pub fn with_allowed_email_domains(mut self, domains: Vec<String>) -> Self {
self.allowed_email_domains = Some(domains);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Identifier {
#[serde(rename = "type")]
pub identifier_type: String,
pub value: String,
}
impl Identifier {
pub fn new(identifier_type: &str, value: &str) -> Self {
Self {
identifier_type: identifier_type.to_string(),
value: value.to_string(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Group {
#[serde(rename = "type")]
pub scope_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub scope: Option<String>,
#[serde(rename = "groupId")]
pub name: String,
}
impl Group {
pub fn new(scope_type: &str, name: &str) -> Self {
Self {
scope_type: scope_type.to_string(),
id: None,
scope: None,
name: name.to_string(),
}
}
pub fn with_id(mut self, id: &str) -> Self {
self.id = Some(id.to_string());
self
}
pub fn with_scope(mut self, scope: &str) -> Self {
self.scope = Some(scope.to_string());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InvitationScope {
pub id: String,
pub account_id: String,
#[serde(rename = "groupId")]
pub scope: String,
#[serde(skip)]
pub scope_id: String,
#[serde(rename = "type")]
pub scope_type: String,
pub name: String,
pub created_at: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InvitationTarget {
#[serde(rename = "type")]
pub target_type: InvitationTargetType,
pub value: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "avatarUrl")]
pub avatar_url: Option<String>,
}
impl InvitationTarget {
pub fn new(target_type: InvitationTargetType, value: &str) -> Self {
Self {
target_type,
value: value.to_string(),
name: None,
avatar_url: None,
}
}
pub fn email(value: &str) -> Self {
Self::new(InvitationTargetType::Email, value)
}
pub fn phone(value: &str) -> Self {
Self::new(InvitationTargetType::Phone, value)
}
pub fn with_name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
pub fn with_avatar_url(mut self, avatar_url: &str) -> Self {
self.avatar_url = Some(avatar_url.to_string());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct AcceptUser {
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub phone: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(rename = "isExisting", skip_serializing_if = "Option::is_none")]
pub is_existing: Option<bool>,
}
impl AcceptUser {
pub fn new() -> Self {
Self::default()
}
pub fn with_email(mut self, email: &str) -> Self {
self.email = Some(email.to_string());
self
}
pub fn with_phone(mut self, phone: &str) -> Self {
self.phone = Some(phone.to_string());
self
}
pub fn with_name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
pub fn with_is_existing(mut self, is_existing: bool) -> Self {
self.is_existing = Some(is_existing);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InvitationAcceptance {
pub id: Option<String>,
pub account_id: Option<String>,
pub accepted_at: Option<String>,
pub target: Option<InvitationTarget>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Invitation {
#[serde(default)]
pub id: String,
#[serde(default)]
pub account_id: String,
#[serde(default)]
pub click_throughs: u32,
pub form_submission_data: Option<HashMap<String, serde_json::Value>>,
#[deprecated(note = "Use form_submission_data instead")]
pub configuration_attributes: Option<HashMap<String, serde_json::Value>>,
pub attributes: Option<HashMap<String, serde_json::Value>>,
#[serde(default)]
pub created_at: String,
#[serde(default)]
pub deactivated: bool,
#[serde(default)]
pub delivery_count: u32,
#[serde(default)]
pub delivery_types: Vec<DeliveryType>,
#[serde(default)]
pub foreign_creator_id: String,
pub invitation_type: InvitationType,
pub modified_at: Option<String>,
pub status: InvitationStatus,
#[serde(default)]
pub target: Vec<InvitationTarget>,
#[serde(default)]
pub views: u32,
#[serde(default)]
pub widget_configuration_id: String,
#[serde(default)]
pub groups: Vec<InvitationScope>,
#[serde(skip)]
pub scopes: Vec<InvitationScope>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub accepts: Option<Vec<InvitationAcceptance>>,
pub expired: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub expires: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subtype: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub creator_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub creator_avatar_url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InvitationsResponse {
pub invitations: Option<Vec<Invitation>>,
}
#[derive(Debug, Clone)]
pub enum AcceptInvitationParam {
User(AcceptUser),
Target(InvitationTarget),
Targets(Vec<InvitationTarget>),
}
impl From<AcceptUser> for AcceptInvitationParam {
fn from(user: AcceptUser) -> Self {
AcceptInvitationParam::User(user)
}
}
impl From<InvitationTarget> for AcceptInvitationParam {
fn from(target: InvitationTarget) -> Self {
AcceptInvitationParam::Target(target)
}
}
impl From<Vec<InvitationTarget>> for AcceptInvitationParam {
fn from(targets: Vec<InvitationTarget>) -> Self {
AcceptInvitationParam::Targets(targets)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateInvitationTarget {
#[serde(rename = "type")]
pub target_type: CreateInvitationTargetType,
pub value: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "avatarUrl")]
pub avatar_url: Option<String>,
}
impl CreateInvitationTarget {
pub fn new(target_type: CreateInvitationTargetType, value: &str) -> Self {
Self {
target_type,
value: value.to_string(),
name: None,
avatar_url: None,
}
}
pub fn email(value: &str) -> Self {
Self::new(CreateInvitationTargetType::Email, value)
}
pub fn phone(value: &str) -> Self {
Self::new(CreateInvitationTargetType::Phone, value)
}
pub fn sms(value: &str) -> Self {
Self::phone(value)
}
pub fn internal(value: &str) -> Self {
Self::new(CreateInvitationTargetType::Internal, value)
}
pub fn with_name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
pub fn with_avatar_url(mut self, avatar_url: &str) -> Self {
self.avatar_url = Some(avatar_url.to_string());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Inviter {
pub user_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub user_email: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub user_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub user_avatar_url: Option<String>,
}
impl Inviter {
pub fn new(user_id: &str) -> Self {
Self {
user_id: user_id.to_string(),
user_email: None,
name: None,
avatar_url: None,
user_name: None,
user_avatar_url: None,
}
}
pub fn with_email(mut self, email: &str) -> Self {
self.user_email = Some(email.to_string());
self
}
pub fn with_name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
pub fn with_avatar_url(mut self, url: &str) -> Self {
self.avatar_url = Some(url.to_string());
self
}
#[deprecated(note = "Use with_name instead")]
pub fn with_user_name(mut self, name: &str) -> Self {
self.user_name = Some(name.to_string());
self
}
#[deprecated(note = "Use with_avatar_url instead")]
pub fn with_user_avatar_url(mut self, url: &str) -> Self {
self.user_avatar_url = Some(url.to_string());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateInvitationScope {
#[serde(rename = "type")]
pub scope_type: String,
#[serde(rename = "groupId")]
pub scope: String,
pub name: String,
}
impl CreateInvitationScope {
pub fn new(scope_type: &str, scope: &str, name: &str) -> Self {
Self {
scope_type: scope_type.to_string(),
scope: scope.to_string(),
name: name.to_string(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum UnfurlOgType {
Website,
Article,
Video,
Music,
Book,
Profile,
Product,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct UnfurlConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub image: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", rename = "type")]
pub og_type: Option<UnfurlOgType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub site_name: Option<String>,
}
impl UnfurlConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_title(mut self, title: &str) -> Self {
self.title = Some(title.to_string());
self
}
pub fn with_description(mut self, description: &str) -> Self {
self.description = Some(description.to_string());
self
}
pub fn with_image(mut self, image: &str) -> Self {
self.image = Some(image.to_string());
self
}
pub fn with_type(mut self, og_type: UnfurlOgType) -> Self {
self.og_type = Some(og_type);
self
}
pub fn with_site_name(mut self, site_name: &str) -> Self {
self.site_name = Some(site_name.to_string());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateInvitationRequest {
pub widget_configuration_id: String,
pub target: CreateInvitationTarget,
pub inviter: Inviter,
#[serde(skip_serializing_if = "Option::is_none")]
pub groups: Option<Vec<CreateInvitationScope>>,
#[serde(skip)]
pub scope_id: Option<String>,
#[serde(skip)]
pub scope_type_flat: Option<String>,
#[serde(skip)]
pub scope_name: Option<String>,
#[serde(skip)]
pub scopes: Option<Vec<CreateInvitationScope>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subtype: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub template_variables: Option<HashMap<String, String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, serde_json::Value>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub unfurl_config: Option<UnfurlConfig>,
}
impl CreateInvitationRequest {
pub fn new(
widget_configuration_id: &str,
target: CreateInvitationTarget,
inviter: Inviter,
) -> Self {
Self {
widget_configuration_id: widget_configuration_id.to_string(),
target,
inviter,
groups: None,
scope_id: None,
scope_type_flat: None,
scope_name: None,
scopes: None,
source: None,
subtype: None,
template_variables: None,
metadata: None,
unfurl_config: None,
}
}
pub fn with_groups(mut self, groups: Vec<CreateInvitationScope>) -> Self {
self.groups = Some(groups);
self
}
pub fn with_scope(mut self, scope_id: &str, scope_type: &str, scope_name: &str) -> Self {
self.scope_id = Some(scope_id.to_string());
self.scope_type_flat = Some(scope_type.to_string());
self.scope_name = Some(scope_name.to_string());
self
}
pub fn with_source(mut self, source: &str) -> Self {
self.source = Some(source.to_string());
self
}
pub fn with_subtype(mut self, subtype: &str) -> Self {
self.subtype = Some(subtype.to_string());
self
}
pub fn with_template_variables(mut self, vars: HashMap<String, String>) -> Self {
self.template_variables = Some(vars);
self
}
pub fn with_metadata(mut self, metadata: HashMap<String, serde_json::Value>) -> Self {
self.metadata = Some(metadata);
self
}
pub fn with_unfurl_config(mut self, unfurl_config: UnfurlConfig) -> Self {
self.unfurl_config = Some(unfurl_config);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateInvitationResponse {
pub id: String,
pub short_link: String,
pub status: String,
pub created_at: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncInternalInvitationRequest {
pub creator_id: String,
pub target_value: String,
pub action: String,
pub component_id: String,
}
impl SyncInternalInvitationRequest {
pub fn new(creator_id: &str, target_value: &str, action: &str, component_id: &str) -> Self {
Self {
creator_id: creator_id.to_string(),
target_value: target_value.to_string(),
action: action.to_string(),
component_id: component_id.to_string(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncInternalInvitationResponse {
pub processed: u32,
pub invitation_ids: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AutojoinDomain {
pub id: String,
pub domain: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AutojoinDomainsResponse {
pub autojoin_domains: Vec<AutojoinDomain>,
pub invitation: Option<Invitation>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConfigureAutojoinRequest {
pub scope: String,
pub scope_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub scope_name: Option<String>,
pub domains: Vec<String>,
pub component_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, serde_json::Value>>,
}
impl ConfigureAutojoinRequest {
pub fn new(scope: &str, scope_type: &str, domains: Vec<String>, component_id: &str) -> Self {
Self {
scope: scope.to_string(),
scope_type: scope_type.to_string(),
scope_name: None,
domains,
component_id: component_id.to_string(),
metadata: None,
}
}
pub fn with_scope_name(mut self, scope_name: &str) -> Self {
self.scope_name = Some(scope_name.to_string());
self
}
pub fn with_metadata(mut self, metadata: HashMap<String, serde_json::Value>) -> Self {
self.metadata = Some(metadata);
self
}
}
#[deprecated(since = "0.1.0", note = "Use InvitationScope instead")]
pub type InvitationGroup = InvitationScope;
#[deprecated(since = "0.1.0", note = "Use CreateInvitationScope instead")]
pub type CreateInvitationGroup = CreateInvitationScope;
fn is_empty_string(s: &String) -> bool {
s.is_empty()
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct TokenUser {
#[serde(skip_serializing_if = "is_empty_string")]
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub admin_scopes: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_email_domains: Option<Vec<String>>,
#[serde(flatten)]
pub extra: Option<HashMap<String, serde_json::Value>>,
}
impl TokenUser {
pub fn new(id: &str) -> Self {
Self {
id: id.to_string(),
..Default::default()
}
}
pub fn with_name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
pub fn with_email(mut self, email: &str) -> Self {
self.email = Some(email.to_string());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GenerateTokenPayload {
#[serde(skip_serializing_if = "Option::is_none")]
pub user: Option<TokenUser>,
#[serde(skip_serializing_if = "Option::is_none")]
pub component: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub scope: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub vars: Option<HashMap<String, serde_json::Value>>,
#[serde(flatten)]
pub extra: Option<HashMap<String, serde_json::Value>>,
}
impl GenerateTokenPayload {
pub fn new() -> Self {
Self::default()
}
pub fn with_user(mut self, user: TokenUser) -> Self {
self.user = Some(user);
self
}
pub fn with_component(mut self, component: &str) -> Self {
self.component = Some(component.to_string());
self
}
pub fn with_scope(mut self, scope: &str) -> Self {
self.scope = Some(scope.to_string());
self
}
}
#[derive(Debug, Clone)]
pub enum ExpiresIn {
Duration(String),
Seconds(u64),
}
impl From<&str> for ExpiresIn {
fn from(s: &str) -> Self {
ExpiresIn::Duration(s.to_string())
}
}
impl From<String> for ExpiresIn {
fn from(s: String) -> Self {
ExpiresIn::Duration(s)
}
}
impl From<u64> for ExpiresIn {
fn from(s: u64) -> Self {
ExpiresIn::Seconds(s)
}
}
impl From<i64> for ExpiresIn {
fn from(s: i64) -> Self {
ExpiresIn::Seconds(s as u64)
}
}
impl From<u32> for ExpiresIn {
fn from(s: u32) -> Self {
ExpiresIn::Seconds(s as u64)
}
}
impl From<i32> for ExpiresIn {
fn from(s: i32) -> Self {
ExpiresIn::Seconds(s as u64)
}
}
#[derive(Debug, Clone, Default)]
pub struct GenerateTokenOptions {
pub expires_in: Option<ExpiresIn>,
}
impl GenerateTokenOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_expires_in<T: Into<ExpiresIn>>(mut self, expires_in: T) -> Self {
self.expires_in = Some(expires_in.into());
self
}
}