2024-06-25 01:59:38 +02:00
|
|
|
use std::str::FromStr;
|
2023-10-25 21:35:47 +08:00
|
|
|
use validator::Validate;
|
|
|
|
|
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
2024-06-25 01:59:38 +02:00
|
|
|
use flowy_user_pub::cloud::{AFWorkspaceSettings, AFWorkspaceSettingsChange};
|
2024-06-12 17:08:55 +02:00
|
|
|
use flowy_user_pub::entities::{
|
|
|
|
RecurringInterval, Role, SubscriptionPlan, WorkspaceInvitation, WorkspaceMember,
|
|
|
|
WorkspaceSubscription,
|
|
|
|
};
|
2023-12-29 13:02:27 +08:00
|
|
|
use lib_infra::validator_fn::required_not_empty_str;
|
2023-10-25 21:35:47 +08:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone)]
|
|
|
|
pub struct WorkspaceMemberPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub role: AFRolePB,
|
2024-06-03 14:27:28 +08:00
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
|
|
|
pub avatar_url: Option<String>,
|
2023-10-25 21:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<WorkspaceMember> for WorkspaceMemberPB {
|
|
|
|
fn from(value: WorkspaceMember) -> Self {
|
|
|
|
Self {
|
|
|
|
email: value.email,
|
|
|
|
name: value.name,
|
|
|
|
role: value.role.into(),
|
2024-06-03 14:27:28 +08:00
|
|
|
avatar_url: value.avatar_url,
|
2023-10-25 21:35:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone)]
|
|
|
|
pub struct RepeatedWorkspaceMemberPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<WorkspaceMemberPB>,
|
|
|
|
}
|
|
|
|
|
2024-04-11 14:47:34 +08:00
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct WorkspaceMemberInvitationPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
#[validate(email)]
|
|
|
|
pub invitee_email: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub role: AFRolePB,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, ProtoBuf, Default, Clone)]
|
|
|
|
pub struct RepeatedWorkspaceInvitationPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<WorkspaceInvitationPB>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, ProtoBuf, Default, Clone)]
|
|
|
|
pub struct WorkspaceInvitationPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub invite_id: String,
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub workspace_id: String,
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub workspace_name: String,
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub inviter_email: String,
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub inviter_name: String,
|
|
|
|
#[pb(index = 6)]
|
|
|
|
pub status: String,
|
|
|
|
#[pb(index = 7)]
|
|
|
|
pub updated_at_timestamp: i64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<WorkspaceInvitation> for WorkspaceInvitationPB {
|
|
|
|
fn from(value: WorkspaceInvitation) -> Self {
|
|
|
|
Self {
|
|
|
|
invite_id: value.invite_id.to_string(),
|
|
|
|
workspace_id: value.workspace_id.to_string(),
|
|
|
|
workspace_name: value.workspace_name.unwrap_or_default(),
|
|
|
|
inviter_email: value.inviter_email.unwrap_or_default(),
|
|
|
|
inviter_name: value.inviter_name.unwrap_or_default(),
|
|
|
|
status: format!("{:?}", value.status),
|
|
|
|
updated_at_timestamp: value.updated_at.timestamp(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct AcceptWorkspaceInvitationPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub invite_id: String,
|
|
|
|
}
|
|
|
|
|
2024-06-24 14:19:36 +08:00
|
|
|
// Deprecated
|
2023-10-25 21:35:47 +08:00
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct AddWorkspaceMemberPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
#[validate(email)]
|
|
|
|
pub email: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct QueryWorkspacePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct RemoveWorkspaceMemberPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
#[validate(email)]
|
|
|
|
pub email: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct UpdateWorkspaceMemberPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
#[validate(email)]
|
|
|
|
pub email: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub role: AFRolePB,
|
|
|
|
}
|
|
|
|
|
2024-04-11 14:47:34 +08:00
|
|
|
// Workspace Role
|
2023-10-25 21:35:47 +08:00
|
|
|
#[derive(ProtoBuf_Enum, Clone, Default)]
|
|
|
|
pub enum AFRolePB {
|
|
|
|
Owner = 0,
|
|
|
|
Member = 1,
|
|
|
|
#[default]
|
|
|
|
Guest = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<AFRolePB> for Role {
|
|
|
|
fn from(value: AFRolePB) -> Self {
|
|
|
|
match value {
|
|
|
|
AFRolePB::Owner => Role::Owner,
|
|
|
|
AFRolePB::Member => Role::Member,
|
|
|
|
AFRolePB::Guest => Role::Guest,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Role> for AFRolePB {
|
|
|
|
fn from(value: Role) -> Self {
|
|
|
|
match value {
|
|
|
|
Role::Owner => AFRolePB::Owner,
|
|
|
|
Role::Member => AFRolePB::Member,
|
|
|
|
Role::Guest => AFRolePB::Guest,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-05 14:00:24 +08:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct UserWorkspaceIdPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
}
|
2024-02-04 05:49:45 +08:00
|
|
|
|
2024-06-14 09:02:06 +08:00
|
|
|
#[derive(ProtoBuf, Default, Clone)]
|
|
|
|
pub struct WorkspaceMemberIdPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub uid: i64,
|
|
|
|
}
|
|
|
|
|
2024-02-04 05:49:45 +08:00
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct CreateWorkspacePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub name: String,
|
|
|
|
}
|
2024-03-04 16:05:16 +08:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct RenameWorkspacePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub new_name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct ChangeWorkspaceIconPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub new_icon: String,
|
|
|
|
}
|
2024-06-12 17:08:55 +02:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate, Debug)]
|
|
|
|
pub struct SubscribeWorkspacePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub recurring_interval: RecurringIntervalPB,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub workspace_subscription_plan: SubscriptionPlanPB,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub success_url: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf_Enum, Clone, Default, Debug)]
|
|
|
|
pub enum RecurringIntervalPB {
|
|
|
|
#[default]
|
|
|
|
Month = 0,
|
|
|
|
Year = 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<RecurringIntervalPB> for RecurringInterval {
|
|
|
|
fn from(r: RecurringIntervalPB) -> Self {
|
|
|
|
match r {
|
|
|
|
RecurringIntervalPB::Month => RecurringInterval::Month,
|
|
|
|
RecurringIntervalPB::Year => RecurringInterval::Year,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<RecurringInterval> for RecurringIntervalPB {
|
|
|
|
fn from(r: RecurringInterval) -> Self {
|
|
|
|
match r {
|
|
|
|
RecurringInterval::Month => RecurringIntervalPB::Month,
|
|
|
|
RecurringInterval::Year => RecurringIntervalPB::Year,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf_Enum, Clone, Default, Debug)]
|
|
|
|
pub enum SubscriptionPlanPB {
|
|
|
|
#[default]
|
|
|
|
None = 0,
|
|
|
|
Pro = 1,
|
|
|
|
Team = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SubscriptionPlanPB> for SubscriptionPlan {
|
|
|
|
fn from(value: SubscriptionPlanPB) -> Self {
|
|
|
|
match value {
|
|
|
|
SubscriptionPlanPB::Pro => SubscriptionPlan::Pro,
|
|
|
|
SubscriptionPlanPB::Team => SubscriptionPlan::Team,
|
|
|
|
SubscriptionPlanPB::None => SubscriptionPlan::None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SubscriptionPlan> for SubscriptionPlanPB {
|
|
|
|
fn from(value: SubscriptionPlan) -> Self {
|
|
|
|
match value {
|
|
|
|
SubscriptionPlan::Pro => SubscriptionPlanPB::Pro,
|
|
|
|
SubscriptionPlan::Team => SubscriptionPlanPB::Team,
|
|
|
|
SubscriptionPlan::None => SubscriptionPlanPB::None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, ProtoBuf, Default, Clone)]
|
|
|
|
pub struct PaymentLinkPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub payment_link: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, ProtoBuf, Default, Clone)]
|
|
|
|
pub struct RepeatedWorkspaceSubscriptionPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<WorkspaceSubscriptionPB>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, ProtoBuf, Default, Clone)]
|
|
|
|
pub struct WorkspaceSubscriptionPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub workspace_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub subscription_plan: SubscriptionPlanPB,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub recurring_interval: RecurringIntervalPB,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub is_active: bool,
|
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub has_canceled: bool,
|
|
|
|
|
|
|
|
#[pb(index = 6)]
|
|
|
|
pub canceled_at: i64, // value is valid only if has_canceled is true
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<WorkspaceSubscription> for WorkspaceSubscriptionPB {
|
|
|
|
fn from(s: WorkspaceSubscription) -> Self {
|
|
|
|
Self {
|
|
|
|
workspace_id: s.workspace_id,
|
|
|
|
subscription_plan: s.subscription_plan.into(),
|
|
|
|
recurring_interval: s.recurring_interval.into(),
|
|
|
|
is_active: s.is_active,
|
|
|
|
has_canceled: s.canceled_at.is_some(),
|
|
|
|
canceled_at: s.canceled_at.unwrap_or_default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, ProtoBuf, Default, Clone)]
|
|
|
|
pub struct WorkspaceUsagePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub member_count: u64,
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub member_count_limit: u64,
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub total_blob_bytes: u64,
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub total_blob_bytes_limit: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, ProtoBuf, Default, Clone)]
|
|
|
|
pub struct BillingPortalPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub url: String,
|
|
|
|
}
|
2024-06-25 01:59:38 +02:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct UseAISettingPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub disable_search_indexing: bool,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub ai_model: AIModelPB,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<AFWorkspaceSettings> for UseAISettingPB {
|
|
|
|
fn from(value: AFWorkspaceSettings) -> Self {
|
|
|
|
Self {
|
|
|
|
disable_search_indexing: value.disable_search_indexing,
|
|
|
|
ai_model: AIModelPB::from_str(&value.ai_model).unwrap_or_default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Clone, Validate)]
|
|
|
|
pub struct UpdateUserWorkspaceSettingPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
#[validate(custom = "required_not_empty_str")]
|
|
|
|
pub workspace_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2, one_of)]
|
|
|
|
pub disable_search_indexing: Option<bool>,
|
|
|
|
|
|
|
|
#[pb(index = 3, one_of)]
|
|
|
|
pub ai_model: Option<AIModelPB>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<UpdateUserWorkspaceSettingPB> for AFWorkspaceSettingsChange {
|
|
|
|
fn from(value: UpdateUserWorkspaceSettingPB) -> Self {
|
|
|
|
let mut change = AFWorkspaceSettingsChange::new();
|
|
|
|
if let Some(disable_search_indexing) = value.disable_search_indexing {
|
|
|
|
change = change.disable_search_indexing(disable_search_indexing);
|
|
|
|
}
|
|
|
|
if let Some(ai_model) = value.ai_model {
|
|
|
|
change = change.ai_model(ai_model.to_str().to_string());
|
|
|
|
}
|
|
|
|
change
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf_Enum, Debug, Clone, Eq, PartialEq, Default)]
|
|
|
|
pub enum AIModelPB {
|
|
|
|
#[default]
|
|
|
|
DefaultModel = 0,
|
|
|
|
GPT35 = 1,
|
|
|
|
GPT4o = 2,
|
|
|
|
Claude3Sonnet = 3,
|
|
|
|
Claude3Opus = 4,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AIModelPB {
|
|
|
|
pub fn to_str(&self) -> &str {
|
|
|
|
match self {
|
|
|
|
AIModelPB::DefaultModel => "default-model",
|
|
|
|
AIModelPB::GPT35 => "gpt-3.5-turbo",
|
|
|
|
AIModelPB::GPT4o => "gpt-4o",
|
|
|
|
AIModelPB::Claude3Sonnet => "claude-3-sonnet",
|
|
|
|
AIModelPB::Claude3Opus => "claude-3-opus",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for AIModelPB {
|
|
|
|
type Err = anyhow::Error;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"gpt-3.5-turbo" => Ok(AIModelPB::GPT35),
|
|
|
|
"gpt-4o" => Ok(AIModelPB::GPT4o),
|
|
|
|
"claude-3-sonnet" => Ok(AIModelPB::Claude3Sonnet),
|
|
|
|
"claude-3-opus" => Ok(AIModelPB::Claude3Opus),
|
|
|
|
_ => Ok(AIModelPB::DefaultModel),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|