fiberplane_models/
workspaces.rs

1use crate::data_sources::SelectedDataSources;
2pub use crate::labels::Label;
3use crate::names::Name;
4use crate::timestamps::Timestamp;
5use base64uuid::Base64Uuid;
6#[cfg(feature = "fp-bindgen")]
7use fp_bindgen::prelude::Serializable;
8use serde::{Deserialize, Serialize};
9use strum_macros::Display;
10use time::OffsetDateTime;
11use typed_builder::TypedBuilder;
12
13/// Workspace representation.
14#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
15#[cfg_attr(
16    feature = "fp-bindgen",
17    derive(Serializable),
18    fp(rust_module = "fiberplane_models::workspaces")
19)]
20#[non_exhaustive]
21#[serde(rename_all = "camelCase")]
22pub struct Workspace {
23    pub id: Base64Uuid,
24    pub name: Name,
25    pub display_name: String,
26    #[serde(rename = "type")]
27    pub ty: WorkspaceType,
28    pub owner_id: Base64Uuid,
29    pub default_data_sources: SelectedDataSources,
30    pub created_at: Timestamp,
31    pub updated_at: Timestamp,
32}
33
34#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, Display)]
35#[cfg_attr(
36    feature = "fp-bindgen",
37    derive(Serializable),
38    fp(rust_module = "fiberplane_models::workspaces")
39)]
40#[non_exhaustive]
41#[serde(rename_all = "snake_case")]
42pub enum WorkspaceType {
43    Personal,
44    Organization,
45}
46
47/// Payload to be able to invite someone to a workspace.
48#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
49#[cfg_attr(
50    feature = "fp-bindgen",
51    derive(Serializable),
52    fp(rust_module = "fiberplane_models::workspaces")
53)]
54#[non_exhaustive]
55#[serde(rename_all = "camelCase")]
56pub struct NewWorkspaceInvite {
57    pub email: String,
58    #[serde(default)]
59    pub role: AuthRole,
60}
61
62impl NewWorkspaceInvite {
63    pub fn new(email: impl Into<String>, role: AuthRole) -> Self {
64        Self {
65            email: email.into(),
66            role,
67        }
68    }
69}
70
71/// Response received from create a new workspace endpoint.
72#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
73#[cfg_attr(
74    feature = "fp-bindgen",
75    derive(Serializable),
76    fp(rust_module = "fiberplane_models::workspaces")
77)]
78#[non_exhaustive]
79#[serde(rename_all = "camelCase")]
80pub struct WorkspaceInviteResponse {
81    #[builder(setter(into))]
82    pub url: String,
83}
84
85/// Payload to create a new organization workspace.
86#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
87#[cfg_attr(
88    feature = "fp-bindgen",
89    derive(Serializable),
90    fp(rust_module = "fiberplane_models::workspaces")
91)]
92#[non_exhaustive]
93#[serde(rename_all = "camelCase")]
94pub struct NewWorkspace {
95    pub name: Name,
96    /// The display name of the workspace. The `name` will be used if none is provided
97    #[builder(default, setter(into, strip_option))]
98    pub display_name: Option<String>,
99    #[builder(default, setter(into, strip_option))]
100    #[serde(default, skip_serializing_if = "Option::is_none")]
101    pub default_data_sources: Option<SelectedDataSources>,
102}
103
104impl NewWorkspace {
105    pub fn new(name: Name) -> Self {
106        Self {
107            name,
108            display_name: None,
109            default_data_sources: None,
110        }
111    }
112}
113
114/// Payload to update workspace settings
115#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
116#[cfg_attr(
117    feature = "fp-bindgen",
118    derive(Serializable),
119    fp(rust_module = "fiberplane_models::workspaces")
120)]
121#[non_exhaustive]
122#[serde(rename_all = "camelCase")]
123pub struct UpdateWorkspace {
124    #[builder(default, setter(into, strip_option))]
125    #[serde(default, skip_serializing_if = "Option::is_none")]
126    pub display_name: Option<String>,
127    #[builder(default, setter(strip_option))]
128    #[serde(default, skip_serializing_if = "Option::is_none")]
129    pub owner: Option<Base64Uuid>,
130    #[builder(default, setter(strip_option))]
131    #[serde(default, skip_serializing_if = "Option::is_none")]
132    pub default_data_sources: Option<SelectedDataSources>,
133}
134
135/// Payload to update a workspace members' role
136#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
137#[cfg_attr(
138    feature = "fp-bindgen",
139    derive(Serializable),
140    fp(rust_module = "fiberplane_models::workspaces")
141)]
142#[non_exhaustive]
143#[serde(rename_all = "camelCase")]
144pub struct WorkspaceUserUpdate {
145    #[builder(default, setter(strip_option))]
146    #[serde(default, skip_serializing_if = "Option::is_none")]
147    pub role: Option<AuthRole>,
148}
149
150#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, Display)]
151#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
152#[cfg_attr(
153    feature = "fp-bindgen",
154    derive(Serializable),
155    fp(rust_module = "fiberplane_models::workspaces")
156)]
157#[non_exhaustive]
158#[serde(rename_all = "snake_case")]
159pub enum AuthRole {
160    #[strum(serialize = "Viewer")]
161    Read,
162    #[strum(serialize = "Editor")]
163    Write,
164    Admin,
165}
166
167impl Default for AuthRole {
168    fn default() -> Self {
169        Self::Write
170    }
171}
172
173#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
174#[cfg_attr(
175    feature = "fp-bindgen",
176    derive(Serializable),
177    fp(rust_module = "fiberplane_models::workspaces")
178)]
179#[non_exhaustive]
180#[serde(rename_all = "camelCase")]
181pub struct WorkspaceInvite {
182    pub id: Base64Uuid,
183    pub sender: Base64Uuid,
184    pub receiver: String,
185    #[serde(with = "time::serde::rfc3339")]
186    pub created_at: OffsetDateTime,
187    #[serde(with = "time::serde::rfc3339")]
188    pub expires_at: OffsetDateTime,
189}
190
191#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
192#[cfg_attr(
193    feature = "fp-bindgen",
194    derive(Serializable),
195    fp(rust_module = "fiberplane_models::workspaces")
196)]
197#[non_exhaustive]
198#[serde(rename_all = "camelCase")]
199pub struct Membership {
200    pub id: Base64Uuid,
201    pub email: String,
202    pub name: String,
203    pub role: AuthRole,
204}