Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(auth): mobile welcome email endpoint (#2608)

Evan Hutnik283b4821dd39
diff --git a/js/app/packages/service-clients/service-auth/generated/client.ts b/js/app/packages/service-clients/service-auth/generated/client.ts
index d3bc3f37ba..bcab681d97 100644
--- a/js/app/packages/service-clients/service-auth/generated/client.ts
+++ b/js/app/packages/service-clients/service-auth/generated/client.ts
@@ -41,6 +41,7 @@ import type {
PutUserNameParams,
ResendFusionauthVerifyUserEmailRequest,
SendInviteBody,
+ SendMobileWelcomeEmailRequest,
SsoLoginParams,
SsoRequiredResponse,
StripeSessionResponse,
@@ -1062,6 +1063,80 @@ export const verifyMergeRequest = async (
} as verifyMergeRequestResponse;
};
+/**
+ * @summary Sends a mobile welcome email to the given address, if it hasn't already been sent
+and the email is not blocked.
+ */
+export type sendMobileWelcomeEmailResponse200 = {
+ data: EmptyResponse;
+ status: 200;
+};
+
+export type sendMobileWelcomeEmailResponse204 = {
+ data: void;
+ status: 204;
+};
+
+export type sendMobileWelcomeEmailResponse400 = {
+ data: ErrorResponse;
+ status: 400;
+};
+
+export type sendMobileWelcomeEmailResponse429 = {
+ data: ErrorResponse;
+ status: 429;
+};
+
+export type sendMobileWelcomeEmailResponse500 = {
+ data: ErrorResponse;
+ status: 500;
+};
+
+export type sendMobileWelcomeEmailResponseSuccess = (
+ | sendMobileWelcomeEmailResponse200
+ | sendMobileWelcomeEmailResponse204
+) & {
+ headers: Headers;
+};
+export type sendMobileWelcomeEmailResponseError = (
+ | sendMobileWelcomeEmailResponse400
+ | sendMobileWelcomeEmailResponse429
+ | sendMobileWelcomeEmailResponse500
+) & {
+ headers: Headers;
+};
+
+export type sendMobileWelcomeEmailResponse =
+ | sendMobileWelcomeEmailResponseSuccess
+ | sendMobileWelcomeEmailResponseError;
+
+export const getSendMobileWelcomeEmailUrl = () => {
+ return `/mobile-welcome-email`;
+};
+
+export const sendMobileWelcomeEmail = async (
+ sendMobileWelcomeEmailRequest: SendMobileWelcomeEmailRequest,
+ options?: RequestInit
+): Promise<sendMobileWelcomeEmailResponse> => {
+ const res = await fetch(getSendMobileWelcomeEmailUrl(), {
+ ...options,
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json', ...options?.headers },
+ body: JSON.stringify(sendMobileWelcomeEmailRequest),
+ });
+
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
+
+ const data: sendMobileWelcomeEmailResponse['data'] = body
+ ? JSON.parse(body)
+ : {};
+ return {
+ data,
+ status: res.status,
+ headers: res.headers,
+ } as sendMobileWelcomeEmailResponse;
+};
+
/**
* @summary Handles oauth redirect
*/
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/index.ts b/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
index f7631f2170..a1a97e49d9 100644
--- a/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
@@ -56,6 +56,7 @@ export * from './putUserNameQueryParamsFirstName';
export * from './putUserNameQueryParamsLastName';
export * from './resendFusionauthVerifyUserEmailRequest';
export * from './sendInviteBody';
+export * from './sendMobileWelcomeEmailRequest';
export * from './ssoLoginParams';
export * from './ssoRequiredResponse';
export * from './stripeProductTier';
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/sendMobileWelcomeEmailRequest.ts b/js/app/packages/service-clients/service-auth/generated/schemas/sendMobileWelcomeEmailRequest.ts
new file mode 100644
index 0000000000..95a6799737
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/sendMobileWelcomeEmailRequest.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+export interface SendMobileWelcomeEmailRequest {
+ /** The email address to send the welcome email to */
+ email: string;
+}
diff --git a/js/app/packages/service-clients/service-auth/openapi.json b/js/app/packages/service-clients/service-auth/openapi.json
index 2ca3b35b1e..b7417ee6e6 100644
--- a/js/app/packages/service-clients/service-auth/openapi.json
+++ b/js/app/packages/service-clients/service-auth/openapi.json
@@ -895,6 +895,68 @@
}
}
},
+ "/mobile-welcome-email": {
+ "post": {
+ "tags": ["mobile_welcome_email"],
+ "summary": "Sends a mobile welcome email to the given address, if it hasn't already been sent\nand the email is not blocked.",
+ "operationId": "send_mobile_welcome_email",
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/SendMobileWelcomeEmailRequest"
+ }
+ }
+ },
+ "required": true
+ },
+ "responses": {
+ "200": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/EmptyResponse"
+ }
+ }
+ }
+ },
+ "204": {
+ "description": ""
+ },
+ "400": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "429": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/oauth/passwordless/{code}": {
"get": {
"tags": ["oauth::passwordless_callback"],
@@ -3536,6 +3598,16 @@
}
}
},
+ "SendMobileWelcomeEmailRequest": {
+ "type": "object",
+ "required": ["email"],
+ "properties": {
+ "email": {
+ "type": "string",
+ "description": "The email address to send the welcome email to"
+ }
+ }
+ },
"SsoRequiredResponse": {
"type": "object",
"required": ["idp_id"],
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 9856bf3aa8..365a2ccbde 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -614,6 +614,7 @@ dependencies = [
"macro_uuid",
"maud",
"miniserde",
+ "mobile_welcome_email_db_client",
"mockall",
"model",
"model-entity",
@@ -6563,6 +6564,16 @@ dependencies = [
"windows-sys 0.52.0",
]
+[[package]]
+name = "mobile_welcome_email_db_client"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "macro_db_migrator",
+ "sqlx",
+ "tracing",
+]
+
[[package]]
name = "mockall"
version = "0.13.1"
diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.toml
index 3a71dfa03c..637ca71b43 100644
--- a/rust/cloud-storage/Cargo.toml
+++ b/rust/cloud-storage/Cargo.toml
@@ -90,6 +90,7 @@ members = [
"models_sfs",
"models_soup",
"models_team",
+ "mobile_welcome_email_db_client",
"name_search",
"non_empty",
"notification",
diff --git a/rust/cloud-storage/authentication_service/Cargo.toml b/rust/cloud-storage/authentication_service/Cargo.toml
index fc9f691020..58ee8286d3 100644
--- a/rust/cloud-storage/authentication_service/Cargo.toml
+++ b/rust/cloud-storage/authentication_service/Cargo.toml
@@ -59,6 +59,7 @@ macro_cache_client = { path = "../macro_cache_client", default-features = false,
"auth",
"auth_rate_limit",
"login_code_rate_limit",
+ "mobile_welcome_email_rate_limit",
"verify_email_rate_limit",
] }
macro_cors = { path = "../macro_cors" }
@@ -67,6 +68,7 @@ macro_db_client = { path = "../macro_db_client", default-features = false, featu
"team",
] }
macro_entrypoint = { path = "../macro_entrypoint" }
+mobile_welcome_email_db_client = { path = "../mobile_welcome_email_db_client" }
macro_env = { path = "../macro_env" }
macro_env_var = { path = "../macro_env_var" }
macro_middleware = { path = "../macro_middleware", default-features = false, features = [
diff --git a/rust/cloud-storage/authentication_service/src/api/middleware/rate_limit/mobile_welcome_email.rs b/rust/cloud-storage/authentication_service/src/api/middleware/rate_limit/mobile_welcome_email.rs
new file mode 100644
index 0000000000..9979918d5b
--- /dev/null
+++ b/rust/cloud-storage/authentication_service/src/api/middleware/rate_limit/mobile_welcome_email.rs
@@ -0,0 +1,74 @@
+use crate::{api::context::ApiContext, rate_limit_config::RATE_LIMIT_CONFIG};
+use axum::{
+ Json,
+ extract::{Request, State},
+ http::StatusCode,
+ middleware::Next,
+ response::{IntoResponse, Response},
+};
+use macro_middleware::tracking::ClientIp;
+use model::response::ErrorResponse;
+
+/// IP-based rate limit for mobile welcome email requests.
+#[tracing::instrument(skip(ctx, req, next, ip_context), fields(client_ip=%ip_context), err(Debug))]
+pub(in crate::api) async fn handler(
+ State(ctx): State<ApiContext>,
+ ip_context: ClientIp,
+ req: Request,
+ next: Next,
+) -> Result<Response, Response> {
+ if cfg!(not(feature = "rate_limit")) {
+ tracing::trace!("rate limit disabled");
+ return Ok(next.run(req).await);
+ }
+
+ let ip = ip_context.to_string();
+
+ let count = ctx
+ .macro_cache_client
+ .get_mobile_welcome_email_rate_limit(&ip)
+ .await
+ .map_err(|e| {
+ tracing::error!(error=?e, "failed to get rate limit");
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ Json(ErrorResponse {
+ message: "failed to get rate limit".into(),
+ }),
+ )
+ .into_response()
+ })?
+ .unwrap_or(0);
+
+ if count >= RATE_LIMIT_CONFIG.mobile_welcome_email.0 {
+ tracing::error!(
+ ip = ip,
+ rate_limit = RATE_LIMIT_CONFIG.mobile_welcome_email.0,
+ count = count,
+ "rate_limit_exceeded"
+ );
+ return Err((
+ StatusCode::TOO_MANY_REQUESTS,
+ Json(ErrorResponse {
+ message: "rate limit exceeded".into(),
+ }),
+ )
+ .into_response());
+ }
+
+ ctx.macro_cache_client
+ .increment_mobile_welcome_email_rate_limit(&ip, RATE_LIMIT_CONFIG.mobile_welcome_email.1)
+ .await
+ .map_err(|e| {
+ tracing::error!(error=?e, "failed to increment rate limit");
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ Json(ErrorResponse {
+ message: "failed to increment rate limit".into(),
+ }),
+ )
+ .into_response()
+ })?;
+
+ Ok(next.run(req).await)
+}
diff --git a/rust/cloud-storage/authentication_service/src/api/middleware/rate_limit/mod.rs b/rust/cloud-storage/authentication_service/src/api/middleware/rate_limit/mod.rs
index 2aac7963bc..c104920045 100644
--- a/rust/cloud-storage/authentication_service/src/api/middleware/rate_limit/mod.rs
+++ b/rust/cloud-storage/authentication_service/src/api/middleware/rate_limit/mod.rs
@@ -1,2 +1,3 @@
pub mod login_code;
+pub mod mobile_welcome_email;
pub mod passwordless;
diff --git a/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/_welcome_email_template.html b/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/_welcome_email_template.html
new file mode 100644
index 0000000000..3998bd62b7
--- /dev/null
+++ b/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/_welcome_email_template.html
@@ -0,0 +1,124 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:v="urn:schemas-microsoft-com:vml">
+<head>
+ <meta charset="utf-8" />
+ <meta name="x-apple-disable-message-reformatting" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta
+ name="format-detection"
+ content="telephone=no, date=no, address=no, email=no"
+ />
+ <meta name="color-scheme" content="dark" />
+ <meta name="supported-color-schemes" content="dark" />
+ <title>Welcome to Macro</title>
+ <!--[if mso]><style>body{font-family:Helvetica,Arial,sans-serif}</style><![endif]-->
+</head>
+
+<body>
+<div
+ role="article"
+ aria-roledescription="email"
+ aria-label="Welcome to Macro"
+ lang="en"
+ style="background-color: #030303; width: 100%; font-family: 'Rajdhani', Helvetica, Arial, sans-serif"
+>
+ <table
+ cellpadding="0"
+ cellspacing="0"
+ role="presentation"
+ style="width: 100%; max-width: 640px; margin: 0 auto; background-color: #030303"
+ >
+ <tr>
+ <td align="center" style="padding: 56px 0 32px">
+ <a href="https://macro.com">
+ <img
+ src="https://macro.com/logo-256px.png"
+ width="128"
+ alt="Macro"
+ style="border: 0; max-width: 100%"
+ />
+ </a>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <div style="background-color: #090909; border-radius: 5px; padding: 56px 40px; margin: 0 16px; border: 1px solid #484848">
+ <h1
+ style="
+ margin: 0 0 16px;
+ text-align: center;
+ font-size: 36px;
+ font-weight: 450;
+ font-family: 'Roboto Slab', Rockwell, Georgia, serif;
+ letter-spacing: -0.02em;
+ color: #f2f2f2;
+ "
+ >
+ You're in.
+ </h1>
+ <p
+ style="
+ margin: 0;
+ text-align: center;
+ font-size: 16px;
+ color: #aeaeae;
+ font-family: 'Rajdhani', Helvetica, Arial, sans-serif;
+ "
+ >
+ Tap below from your computer to get started.
+ </p>
+ <div style="text-align: center; margin: 56px 0">
+ <a
+ href="https://macro.com/app/welcome"
+ style="
+ display: inline-block;
+ background-color: #ff8f00;
+ color: #090909;
+ text-decoration: none;
+ padding: 16px 32px;
+ border-radius: 3px;
+ font-size: 16px;
+ font-family: 'Rajdhani', Helvetica, Arial, sans-serif;
+ font-weight: 600;
+ "
+ >
+ Launch Macro
+ </a>
+ </div>
+ <!--[if mso]>
+ <table cellpadding="0" cellspacing="0" role="presentation" style="margin: 56px auto;">
+ <tr>
+ <td style="background-color: #ff8f00; border-radius: 3px;">
+ <a href="https://macro.com/app/welcome" style="color: #090909; text-decoration: none; display: block; padding: 16px 32px; font-size: 16px; font-weight: 600; font-family: 'Rajdhani', Helvetica, Arial, sans-serif;">
+ Launch Macro
+ </a>
+ </td>
+ </tr>
+ </table>
+ <![endif]-->
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td style="padding: 48px 0; text-align: center">
+ <p
+ style="
+ margin: 0;
+ font-size: 14px;
+ color: #484848;
+ font-family: 'Rajdhani', Helvetica, Arial, sans-serif;
+ "
+ >
+ Questions? Email us at
+ <a
+ href="mailto:[email protected]"
+ style="color: #aeaeae; text-decoration: none"
+ >
+ </p>
+ </td>
+ </tr>
+ </table>
+</div>
+</body>
+</html>
diff --git a/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/mod.rs b/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/mod.rs
new file mode 100644
index 0000000000..b594c4b11c
--- /dev/null
+++ b/rust/cloud-storage/authentication_service/src/api/mobile_welcome_email/mod.rs
@@ -0,0 +1,127 @@
+use axum::{
+ Json, Router,
+ extract::{self, State},
+ http::StatusCode,
+ response::{IntoResponse, Response},
+ routing::post,
+};
+use model::response::{EmptyResponse, ErrorResponse};
+use thiserror::Error;
+use tower::ServiceBuilder;
+use utoipa::ToSchema;
+
+use crate::api::{context::ApiContext, middleware};
+
+static WELCOME_EMAIL_TEMPLATE: &str = include_str!("./_welcome_email_template.html");
+
+#[derive(Debug, Error)]
+pub enum SendMobileWelcomeEmailError {
+ #[error("Invalid email address")]
+ InvalidEmail,
+
+ #[error("Email is blocked")]
+ EmailBlocked,
+
+ #[error("Internal error")]
+ InternalError(#[from] anyhow::Error),
+}
+
+impl IntoResponse for SendMobileWelcomeEmailError {
+ fn into_response(self) -> Response {
+ let status_code = match &self {
+ SendMobileWelcomeEmailError::InvalidEmail
+ | SendMobileWelcomeEmailError::EmailBlocked => StatusCode::BAD_REQUEST,
+ SendMobileWelcomeEmailError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
+ };
+
+ (
+ status_code,
+ Json(ErrorResponse {
+ message: self.to_string().into(),
+ }),
+ )
+ .into_response()
+ }
+}
+
+#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
+pub struct SendMobileWelcomeEmailRequest {
+ /// The email address to send the welcome email to
+ pub email: String,
+}
+
+pub fn router(state: ApiContext) -> Router<ApiContext> {
+ Router::new().route(
+ "/mobile-welcome-email",
+ post(handler).layer(
+ ServiceBuilder::new().layer(axum::middleware::from_fn_with_state(
+ state,
+ middleware::rate_limit::mobile_welcome_email::handler,
+ )),
+ ),
+ )
+}
+
+/// Sends a mobile welcome email to the given address, if it hasn't already been sent
+/// and the email is not blocked.
+#[utoipa::path(
+ post,
+ path = "/mobile-welcome-email",
+ operation_id = "send_mobile_welcome_email",
+ responses(
+ (status = 200, body = EmptyResponse),
+ (status = 204),
+ (status = 400, body = ErrorResponse),
+ (status = 429, body = ErrorResponse),
+ (status = 500, body = ErrorResponse),
+ )
+)]
+#[tracing::instrument(skip(ctx), fields(email=%req.email), err)]
+pub async fn handler(
+ State(ctx): State<ApiContext>,
+ extract::Json(req): extract::Json<SendMobileWelcomeEmailRequest>,
+) -> Result<Response, SendMobileWelcomeEmailError> {
+ if !email_validator::is_valid_email(&req.email) {
+ return Err(SendMobileWelcomeEmailError::InvalidEmail);
+ }
+
+ let lowercase_email = req.email.to_lowercase();
+ let lowercase_email = if let Some((local, domain)) = lowercase_email.split_once('@') {
+ let local = local.split('+').next().unwrap_or(local);
+ format!("{local}@{domain}")
+ } else {
+ lowercase_email
+ };
+
+ // Check if the email is blocked
+ let blocked_emails =
+ macro_db_client::blocked_email::get_blocked_emails(&ctx.db, &[&lowercase_email]).await?;
+
+ if !blocked_emails.is_empty() {
+ return Err(SendMobileWelcomeEmailError::EmailBlocked);
+ }
+
+ // Atomically claim the slot — returns false if the email was already sent
+ let inserted =
+ mobile_welcome_email_db_client::mobile_welcome_email::insert_mobile_welcome_email(
+ &ctx.db,
+ &lowercase_email,
+ )
+ .await?;
+
+ if !inserted {
+ return Ok(StatusCode::NO_CONTENT.into_response());
+ }
+
+ let welcome_email_content = WELCOME_EMAIL_TEMPLATE.to_string();
+ ctx.ses_client
+ .send_email(
+ &lowercase_email,
+ "Welcome to Macro",
+ &welcome_email_content,
+ )
+ .await?;
+
+ Ok((StatusCode::OK, Json(EmptyResponse {})).into_response())
+}
diff --git a/rust/cloud-storage/authentication_service/src/api/mod.rs b/rust/cloud-storage/authentication_service/src/api/mod.rs
index 5dd8780243..f0bc59aca4 100644
--- a/rust/cloud-storage/authentication_service/src/api/mod.rs
+++ b/rust/cloud-storage/authentication_service/src/api/mod.rs
@@ -20,6 +20,7 @@ mod email;
mod link;
#[allow(unused_imports)]
mod merge;
+mod mobile_welcome_email;
mod health;
mod internal;
@@ -123,6 +124,7 @@ fn api_router(state: ApiContext) -> Router<ApiContext> {
)
.nest("/jwt", jwt::router(state.jwt_args.clone()))
.nest("/session", session::router())
+ .merge(mobile_welcome_email::router(state.clone()))
.nest(
"/webhooks",
webhooks::router().layer(ServiceBuilder::new().layer(axum::middleware::from_fn(
diff --git a/rust/cloud-storage/authentication_service/src/api/swagger.rs b/rust/cloud-storage/authentication_service/src/api/swagger.rs
index fd131e2ddf..53a078748c 100644
--- a/rust/cloud-storage/authentication_service/src/api/swagger.rs
+++ b/rust/cloud-storage/authentication_service/src/api/swagger.rs
@@ -31,7 +31,8 @@ use crate::api::user::stripe::{
StripeSessionResponse,
};
use crate::api::{
- email, health, jwt, link, login, logout, merge, oauth, oauth2, permissions, session, user,
+ email, health, jwt, link, login, logout, merge, mobile_welcome_email, oauth, oauth2,
+ permissions, session, user,
};
use model::authentication::login::response::SsoRequiredResponse;
use model::authentication::{
@@ -129,6 +130,9 @@ use model::user::{
referral::inbound::axum_router::get_referral_code_handler::<crate::api::context::ReferralServiceType>,
referral::inbound::axum_router::post_referral_invite_handler::<crate::api::context::ReferralServiceType>,
+ /// /mobile-welcome-email
+ mobile_welcome_email::handler,
+
/// /merge
merge::create_merge_request::handler,
merge::verify_merge_request::handler,
@@ -188,6 +192,9 @@ use model::user::{
PatchTeamUserTierRequest,
TeamUserTier,
+ // Mobile welcome email
+ mobile_welcome_email::SendMobileWelcomeEmailRequest,
+
// Merge
CreateAccountMergeRequest,
),
diff --git a/rust/cloud-storage/authentication_service/src/rate_limit_config.rs b/rust/cloud-storage/authentication_service/src/rate_limit_config.rs
index 3a123550e9..950db7fbf0 100644
--- a/rust/cloud-storage/authentication_service/src/rate_limit_config.rs
+++ b/rust/cloud-storage/authentication_service/src/rate_limit_config.rs
@@ -13,6 +13,7 @@ pub struct RateLimitConfig {
#[allow(dead_code)]
pub merge_email_daily: (u64, i64),
pub create_user_hourly: (u64, i64),
+ pub mobile_welcome_email: (u64, i64),
// pub sso: (u64, i64),
}
@@ -29,4 +30,5 @@ pub static RATE_LIMIT_CONFIG: RateLimitConfig = RateLimitConfig {
merge_email_daily: (5, 86400),
create_user_hourly: (50, 3600),
+ mobile_welcome_email: (5, 3600), // 10 attempts per hour per IP
};
diff --git a/rust/cloud-storage/justfile b/rust/cloud-storage/justfile
index b9688530ca..c0d82e90fd 100644
--- a/rust/cloud-storage/justfile
+++ b/rust/cloud-storage/justfile
@@ -90,6 +90,7 @@ setup_test_envs:
echo "DATABASE_URL={{ MACRODB }}" >> ./call/.env
echo "DATABASE_URL={{ MACRODB }}" >> ./backfill_entity_access/.env
echo "DATABASE_URL={{ MACRODB }}" >> ./entity_access_management/.env
+ echo "DATABASE_URL={{ MACRODB }}" >> ./mobile_welcome_email_db_client/.env
setup_macrodb:
just macro_db_client/create_db
diff --git a/rust/cloud-storage/macro_cache_client/Cargo.toml b/rust/cloud-storage/macro_cache_client/Cargo.toml
index 64e833f344..cd0fc4107a 100644
--- a/rust/cloud-storage/macro_cache_client/Cargo.toml
+++ b/rust/cloud-storage/macro_cache_client/Cargo.toml
@@ -9,6 +9,7 @@ all = [
"auth",
"auth_rate_limit",
"login_code_rate_limit",
+ "mobile_welcome_email_rate_limit",
"notification_rate_limit",
"verify_email_rate_limit",
]
@@ -16,6 +17,7 @@ auth = []
auth_rate_limit = ["dep:email_validator"]
default = ["all"]
login_code_rate_limit = ["dep:email_validator"]
+mobile_welcome_email_rate_limit = []
notification_rate_limit = ["dep:email_validator"]
verify_email_rate_limit = ["dep:email_validator"]
diff --git a/rust/cloud-storage/macro_cache_client/src/lib.rs b/rust/cloud-storage/macro_cache_client/src/lib.rs
index 220aea9873..487aba9bdc 100644
--- a/rust/cloud-storage/macro_cache_client/src/lib.rs
+++ b/rust/cloud-storage/macro_cache_client/src/lib.rs
@@ -15,6 +15,9 @@ pub mod notification_rate_limit;
#[cfg(feature = "login_code_rate_limit")]
mod login_code_rate_limit;
+#[cfg(feature = "mobile_welcome_email_rate_limit")]
+pub mod mobile_welcome_email_rate_limit;
+
#[cfg(feature = "verify_email_rate_limit")]
pub mod verify_email_rate_limit;
diff --git a/rust/cloud-storage/macro_cache_client/src/mobile_welcome_email_rate_limit.rs b/rust/cloud-storage/macro_cache_client/src/mobile_welcome_email_rate_limit.rs
new file mode 100644
index 0000000000..2ff338ebe0
--- /dev/null
+++ b/rust/cloud-storage/macro_cache_client/src/mobile_welcome_email_rate_limit.rs
@@ -0,0 +1,28 @@
+use crate::MacroCache;
+
+macro_rules! mobile_welcome_email_rate_limit {
+ ($ip:expr) => {
+ format!("rtl_mobile_welcome_email:{}", $ip)
+ };
+}
+
+impl MacroCache {
+ /// Gets the mobile welcome email rate limit count for a given IP.
+ pub async fn get_mobile_welcome_email_rate_limit(
+ &self,
+ ip: &str,
+ ) -> anyhow::Result<Option<u64>> {
+ let key = mobile_welcome_email_rate_limit!(ip);
+ macro_redis::get::get_optional::<u64>(&self.inner, &key).await
+ }
+
+ /// Increments the mobile welcome email rate limit for a given IP.
+ pub async fn increment_mobile_welcome_email_rate_limit(
+ &self,
+ ip: &str,
+ expiry_seconds: i64,
+ ) -> anyhow::Result<()> {
+ let key = mobile_welcome_email_rate_limit!(ip);
+ macro_redis::incr::incr_with_expiry(&self.inner, &key, expiry_seconds).await
+ }
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-03a323aefdba22727c6789b28d90d7200e795a4591812dab4c4e7718c5512055.json b/rust/cloud-storage/macro_db_client/.sqlx/query-03a323aefdba22727c6789b28d90d7200e795a4591812dab4c4e7718c5512055.json
deleted file mode 100644
index 83caec4173..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-03a323aefdba22727c6789b28d90d7200e795a4591812dab4c4e7718c5512055.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM email_threads t\n JOIN \"Project\" p ON t.project_id = p.id AND p.\"deletedAt\" IS NULL\n WHERE t.id = $1\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT DISTINCT user_id FROM \"UserItemAccess\"\n WHERE item_id IN (\n SELECT $2\n UNION\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Text"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "03a323aefdba22727c6789b28d90d7200e795a4591812dab4c4e7718c5512055"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json b/rust/cloud-storage/macro_db_client/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json
new file mode 100644
index 0000000000..4c5afc274a
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM notification_user_device_registration\n WHERE device_endpoint = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
deleted file mode 100644
index d2b084cf10..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[],\n $4::JSONB[]\n ) AS u(id, entity_id, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "UuidArray",
- "JsonbArray"
- ]
- },
- "nullable": []
- },
- "hash": "1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json b/rust/cloud-storage/macro_db_client/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json
new file mode 100644
index 0000000000..01cece9642
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json
@@ -0,0 +1,33 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM notification_user_device_registration\n WHERE device_token = $1 AND device_type = $2\n RETURNING device_endpoint\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json b/rust/cloud-storage/macro_db_client/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json
new file mode 100644
index 0000000000..b17b203167
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json
@@ -0,0 +1,98 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND n.event_item_id = ANY($2)\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($4::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($4, $5))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "Int8",
+ "Timestamptz",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json b/rust/cloud-storage/macro_db_client/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json
new file mode 100644
index 0000000000..e4a18ac5f0
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET done = $3\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json b/rust/cloud-storage/macro_db_client/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json
new file mode 100644
index 0000000000..6696253445
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS(\n SELECT 1 FROM notification_message_receipt\n WHERE user_id = $1\n AND notification_id = $2\n AND failed = false\n ) as \"exists!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "exists!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json b/rust/cloud-storage/macro_db_client/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json
new file mode 100644
index 0000000000..c07ec0acbe
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO user_notification_type_preference (user_id, notification_event_type)\n VALUES ($1, $2)\n ON CONFLICT (user_id, notification_event_type) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Varchar"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json b/rust/cloud-storage/macro_db_client/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
deleted file mode 100644
index 44d3a67e72..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT EXISTS (\n SELECT 1\n FROM public.email_threads t\n JOIN public.email_links l ON l.id = t.link_id\n WHERE t.id = $1::uuid\n AND l.macro_id = $2\n ) AS \"exists!\"\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "exists!",
- "type_info": "Bool"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json
new file mode 100644
index 0000000000..3fdea7e232
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json
@@ -0,0 +1,95 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.notification_id = $2\n AND un.deleted_at IS NULL\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json b/rust/cloud-storage/macro_db_client/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json
new file mode 100644
index 0000000000..55fcda1121
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM user_notification\n WHERE user_id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-54e3755d63a676a7fa70da77321e618032f0130c73eb6b0ae985f07c5c6c448b.json b/rust/cloud-storage/macro_db_client/.sqlx/query-54e3755d63a676a7fa70da77321e618032f0130c73eb6b0ae985f07c5c6c448b.json
deleted file mode 100644
index 03a8dbf6bb..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-54e3755d63a676a7fa70da77321e618032f0130c73eb6b0ae985f07c5c6c448b.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM \"Chat\" c\n JOIN \"Project\" p ON c.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE c.id = $1 AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT DISTINCT user_id FROM \"UserItemAccess\"\n WHERE item_id IN (\n SELECT $1\n UNION\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "54e3755d63a676a7fa70da77321e618032f0130c73eb6b0ae985f07c5c6c448b"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json b/rust/cloud-storage/macro_db_client/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json
similarity index 50%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
rename to rust/cloud-storage/macro_db_client/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json
index a110bb67c6..d0a749ebd2 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT DISTINCT cp.user_id\n FROM comms_channel_participants cp\n WHERE cp.channel_id = $1 AND cp.left_at IS NULL\n ",
+ "query": "\n SELECT user_id FROM user_mute_notification\n WHERE user_id = ANY($1)\n ",
"describe": {
"columns": [
{
@@ -11,12 +11,12 @@
],
"parameters": {
"Left": [
- "Uuid"
+ "TextArray"
]
},
"nullable": [
false
]
},
- "hash": "63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8"
+ "hash": "621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6"
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json b/rust/cloud-storage/macro_db_client/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json
new file mode 100644
index 0000000000..d374c2f79f
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM user_notification_type_preference\n WHERE user_id = $1 AND notification_event_type = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json b/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
deleted file mode 100644
index 6d97183829..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n NULL\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[]\n ) AS u(id, entity_id, property_definition_id)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO NOTHING\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "UuidArray"
- ]
- },
- "nullable": []
- },
- "hash": "63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json b/rust/cloud-storage/macro_db_client/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json
new file mode 100644
index 0000000000..65459bcefd
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM \"User\"\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json b/rust/cloud-storage/macro_db_client/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json
new file mode 100644
index 0000000000..34382e8725
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id, apns_collapse_key as \"apns_collapse_key!: String\"\n FROM notification\n WHERE id = ANY($1) AND apns_collapse_key IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "apns_collapse_key!: String",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json b/rust/cloud-storage/macro_db_client/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
deleted file mode 100644
index 655495fb29..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT c.id\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n AND c.id = ANY($2::uuid[])\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "UuidArray"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json b/rust/cloud-storage/macro_db_client/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json
new file mode 100644
index 0000000000..a8e7326c35
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_notification_item_unsubscribe\n WHERE item_id = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json b/rust/cloud-storage/macro_db_client/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json
new file mode 100644
index 0000000000..9e6f7f8877
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT d.device_endpoint\n FROM notification_user_device_registration d\n WHERE d.device_token = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-79d3bc72e6f424765706f7deea426379ae49cbd70dd122daedd95343618b9ac6.json b/rust/cloud-storage/macro_db_client/.sqlx/query-79d3bc72e6f424765706f7deea426379ae49cbd70dd122daedd95343618b9ac6.json
deleted file mode 100644
index 2bde15938f..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-79d3bc72e6f424765706f7deea426379ae49cbd70dd122daedd95343618b9ac6.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT id as project_id\n FROM \"Project\"\n WHERE id = $1 AND \"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT DISTINCT user_id FROM \"UserItemAccess\"\n WHERE item_id IN (\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "79d3bc72e6f424765706f7deea426379ae49cbd70dd122daedd95343618b9ac6"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json b/rust/cloud-storage/macro_db_client/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json
new file mode 100644
index 0000000000..721b0038f2
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id, notification_event_type\n FROM user_notification_type_preference\n WHERE user_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json b/rust/cloud-storage/macro_db_client/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
new file mode 100644
index 0000000000..a166680895
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
@@ -0,0 +1,21 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification (id, notification_event_type, event_item_id, event_item_type, service_sender, metadata, sender_id, apns_collapse_key)\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8)\n ON CONFLICT (id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Text",
+ "Text",
+ "Text",
+ "Jsonb",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json b/rust/cloud-storage/macro_db_client/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json
new file mode 100644
index 0000000000..eab49b91f7
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET sent = true\n WHERE notification_id = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-8d21bf0aa4c20589a55cf5777aa9c658fdacea4d0d0c7070aded12cccd373911.json b/rust/cloud-storage/macro_db_client/.sqlx/query-8d21bf0aa4c20589a55cf5777aa9c658fdacea4d0d0c7070aded12cccd373911.json
deleted file mode 100644
index 505a2bd912..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-8d21bf0aa4c20589a55cf5777aa9c658fdacea4d0d0c7070aded12cccd373911.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n UPDATE entity_properties\n SET values = $2\n WHERE entity_id = $1\n AND property_definition_id = $3\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Jsonb",
- "Uuid"
- ]
- },
- "nullable": []
- },
- "hash": "8d21bf0aa4c20589a55cf5777aa9c658fdacea4d0d0c7070aded12cccd373911"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json b/rust/cloud-storage/macro_db_client/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json
new file mode 100644
index 0000000000..a8520fdfd0
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification_message_receipt (message_id, user_id, notification_id)\n VALUES ($1, $2, $3)\n ON CONFLICT (message_id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json b/rust/cloud-storage/macro_db_client/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json
new file mode 100644
index 0000000000..4035617965
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET deleted_at = NOW()\n WHERE user_id = $1 AND notification_id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-96d853b887f2e6d7aac6b15ddd2b71a8d8900d2ef30047da7ca1a5940503b6d0.json b/rust/cloud-storage/macro_db_client/.sqlx/query-96d853b887f2e6d7aac6b15ddd2b71a8d8900d2ef30047da7ca1a5940503b6d0.json
deleted file mode 100644
index e42c9f2009..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-96d853b887f2e6d7aac6b15ddd2b71a8d8900d2ef30047da7ca1a5940503b6d0.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM \"Document\" d\n JOIN \"Project\" p ON d.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE d.id = $1 AND d.\"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT DISTINCT user_id FROM \"UserItemAccess\"\n WHERE item_id IN (\n SELECT $1\n UNION\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "96d853b887f2e6d7aac6b15ddd2b71a8d8900d2ef30047da7ca1a5940503b6d0"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
deleted file mode 100644
index 9d717fa5f9..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT property_definition_id, values\n FROM entity_properties\n WHERE entity_id = $1\n AND entity_type = 'TASK'\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "property_definition_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "values",
- "type_info": "Jsonb"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- true
- ]
- },
- "hash": "9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json b/rust/cloud-storage/macro_db_client/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json
new file mode 100644
index 0000000000..ad14cfedba
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json
@@ -0,0 +1,44 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id, device_endpoint, device_type as \"device_type: DbDeviceType\"\n FROM notification_user_device_registration\n WHERE user_id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "device_type: DbDeviceType",
+ "type_info": {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json b/rust/cloud-storage/macro_db_client/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json
new file mode 100644
index 0000000000..7626c0a06b
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET seen_at = NOW()\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json
new file mode 100644
index 0000000000..e5d913399d
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification_user_device_registration (id, user_id, device_token, device_endpoint, device_type)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT (device_endpoint) DO UPDATE SET user_id = $2, device_token = $3, device_type = $5, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json
new file mode 100644
index 0000000000..1168d26a34
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE notification_message_receipt\n SET failed = true, failed_at = NOW()\n WHERE message_id = $1\n RETURNING user_id, notification_id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json b/rust/cloud-storage/macro_db_client/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json
new file mode 100644
index 0000000000..f3780614e0
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json
@@ -0,0 +1,97 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($3::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($3, $4))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-d536db3ccfb32aee9a48227e2b15d2404023ea24b62c159466c95899d76e29ed.json b/rust/cloud-storage/macro_db_client/.sqlx/query-d536db3ccfb32aee9a48227e2b15d2404023ea24b62c159466c95899d76e29ed.json
deleted file mode 100644
index 6ef8856744..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-d536db3ccfb32aee9a48227e2b15d2404023ea24b62c159466c95899d76e29ed.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM email_threads t\n JOIN \"Project\" p ON t.project_id = p.id AND p.\"deletedAt\" IS NULL\n WHERE t.id = $1\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT access_level FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT access_level::text FROM \"UserItemAccess\"\n WHERE user_id = $3 AND item_id IN (\n SELECT $2 -- The thread ID as text\n UNION\n SELECT project_id FROM project_hierarchy -- All parent projects\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $2\n UNION\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" IN (SELECT project_id FROM project_hierarchy)\n )\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "d536db3ccfb32aee9a48227e2b15d2404023ea24b62c159466c95899d76e29ed"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json b/rust/cloud-storage/macro_db_client/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json
new file mode 100644
index 0000000000..d197caf563
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_notification_type_preference\n WHERE notification_event_type = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d.json b/rust/cloud-storage/macro_db_client/.sqlx/query-efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d.json
new file mode 100644
index 0000000000..1cbb49a96b
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO user_notification (notification_id, user_id)\n SELECT $1, user_id\n FROM UNNEST($2::text[]) as user_id\n RETURNING created_at::timestamptz as \"created_at!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json b/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
deleted file mode 100644
index 182e0858ba..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n u.entity_type::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::TEXT[],\n $4::UUID[],\n $5::JSONB[]\n ) AS u(id, entity_id, entity_type, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "TextArray",
- "UuidArray",
- "JsonbArray"
- ]
- },
- "nullable": []
- },
- "hash": "f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json b/rust/cloud-storage/macro_db_client/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json
new file mode 100644
index 0000000000..39180b3b0f
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET deleted_at = NOW()\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b"
+}
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260415121644_create_mobile_welcome_email.sql b/rust/cloud-storage/macro_db_client/migrations/20260415121644_create_mobile_welcome_email.sql
new file mode 100644
index 0000000000..ea5928185f
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260415121644_create_mobile_welcome_email.sql
@@ -0,0 +1,6 @@
+CREATE TABLE IF NOT EXISTS mobile_welcome_email
+(
+ email TEXT NOT NULL,
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+ CONSTRAINT mobile_welcome_email_pkey PRIMARY KEY (email)
+);
diff --git a/rust/cloud-storage/mobile_welcome_email_db_client/.sqlx/query-7eaa606441665fa4dca3077c6b3c02e8c4a0d136a40149829b96dff878897108.json b/rust/cloud-storage/mobile_welcome_email_db_client/.sqlx/query-7eaa606441665fa4dca3077c6b3c02e8c4a0d136a40149829b96dff878897108.json
new file mode 100644
index 0000000000..dd685835c4
--- /dev/null
+++ b/rust/cloud-storage/mobile_welcome_email_db_client/.sqlx/query-7eaa606441665fa4dca3077c6b3c02e8c4a0d136a40149829b96dff878897108.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO mobile_welcome_email (email)\n VALUES ($1)\n ON CONFLICT (email) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7eaa606441665fa4dca3077c6b3c02e8c4a0d136a40149829b96dff878897108"
+}
diff --git a/rust/cloud-storage/mobile_welcome_email_db_client/.sqlx/query-c27077a4053c8a35ca011c5edaf08e3bf1c954b1773fcd2ecab33c2ba518ba34.json b/rust/cloud-storage/mobile_welcome_email_db_client/.sqlx/query-c27077a4053c8a35ca011c5edaf08e3bf1c954b1773fcd2ecab33c2ba518ba34.json
new file mode 100644
index 0000000000..7efbc7703b
--- /dev/null
+++ b/rust/cloud-storage/mobile_welcome_email_db_client/.sqlx/query-c27077a4053c8a35ca011c5edaf08e3bf1c954b1773fcd2ecab33c2ba518ba34.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT email\n FROM mobile_welcome_email\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "email",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "c27077a4053c8a35ca011c5edaf08e3bf1c954b1773fcd2ecab33c2ba518ba34"
+}
diff --git a/rust/cloud-storage/mobile_welcome_email_db_client/Cargo.toml b/rust/cloud-storage/mobile_welcome_email_db_client/Cargo.toml
new file mode 100644
index 0000000000..885a02b190
--- /dev/null
+++ b/rust/cloud-storage/mobile_welcome_email_db_client/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+edition = "2024"
+name = "mobile_welcome_email_db_client"
+publish = false
+version = "0.1.0"
+
+[dependencies]
+anyhow = { workspace = true }
+sqlx = { workspace = true }
+tracing = { workspace = true }
+
+[dev-dependencies]
+macro_db_migrator = { path = "../macro_db_migrator" }
diff --git a/rust/cloud-storage/mobile_welcome_email_db_client/justfile b/rust/cloud-storage/mobile_welcome_email_db_client/justfile
new file mode 100644
index 0000000000..d5a52bc432
--- /dev/null
+++ b/rust/cloud-storage/mobile_welcome_email_db_client/justfile
@@ -0,0 +1,6 @@
+DATABASE_URL := "postgres://user:password@localhost:5432/macrodb"
+
+mod sqlx '../sqlx.just'
+
+prepare_db:
+ just sqlx::prepare_db {{ DATABASE_URL }}
diff --git a/rust/cloud-storage/mobile_welcome_email_db_client/src/lib.rs b/rust/cloud-storage/mobile_welcome_email_db_client/src/lib.rs
new file mode 100644
index 0000000000..4a5cdf4a9c
--- /dev/null
+++ b/rust/cloud-storage/mobile_welcome_email_db_client/src/lib.rs
@@ -0,0 +1,5 @@
+#![deny(missing_docs)]
+
+//! Database client for the mobile welcome email table.
+
+pub mod mobile_welcome_email;
diff --git a/rust/cloud-storage/mobile_welcome_email_db_client/src/mobile_welcome_email.rs b/rust/cloud-storage/mobile_welcome_email_db_client/src/mobile_welcome_email.rs
new file mode 100644
index 0000000000..d732097e3a
--- /dev/null
+++ b/rust/cloud-storage/mobile_welcome_email_db_client/src/mobile_welcome_email.rs
@@ -0,0 +1,49 @@
+//! Queries for the `mobile_welcome_email` table.
+
+/// Checks if a mobile welcome email has already been sent to the given email address.
+#[tracing::instrument(skip(db), err)]
+pub async fn get_mobile_welcome_email(
+ db: &sqlx::Pool<sqlx::Postgres>,
+ email: &str,
+) -> anyhow::Result<bool> {
+ let email = email.to_lowercase();
+
+ let exists = sqlx::query!(
+ r#"
+ SELECT email
+ FROM mobile_welcome_email
+ WHERE email = $1
+ "#,
+ &email
+ )
+ .fetch_optional(db)
+ .await?;
+
+ Ok(exists.is_some())
+}
+
+/// Inserts a record indicating a mobile welcome email was sent.
+/// Returns `true` if a new row was inserted, `false` if the email already existed.
+#[tracing::instrument(skip(db), err)]
+pub async fn insert_mobile_welcome_email(
+ db: &sqlx::Pool<sqlx::Postgres>,
+ email: &str,
+) -> anyhow::Result<bool> {
+ let email = email.to_lowercase();
+
+ let result = sqlx::query!(
+ r#"
+ INSERT INTO mobile_welcome_email (email)
+ VALUES ($1)
+ ON CONFLICT (email) DO NOTHING
+ "#,
+ &email
+ )
+ .execute(db)
+ .await?;
+
+ Ok(result.rows_affected() > 0)
+}
+
+#[cfg(test)]
+mod test;
diff --git a/rust/cloud-storage/mobile_welcome_email_db_client/src/mobile_welcome_email/test.rs b/rust/cloud-storage/mobile_welcome_email_db_client/src/mobile_welcome_email/test.rs
new file mode 100644
index 0000000000..afb78005c7
--- /dev/null
+++ b/rust/cloud-storage/mobile_welcome_email_db_client/src/mobile_welcome_email/test.rs
@@ -0,0 +1,23 @@
+use super::*;
+use macro_db_migrator::MACRO_DB_MIGRATIONS;
+use sqlx::{Pool, Postgres};
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn test_insert_and_get_mobile_welcome_email(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let email = "[email protected]";
+
+ // Should not exist initially
+ assert!(!get_mobile_welcome_email(&pool, email).await?);
+
+ // Insert returns true on first insert
+ assert!(insert_mobile_welcome_email(&pool, email).await?);
+
+ // Should exist now (case-insensitive)
+ assert!(get_mobile_welcome_email(&pool, email).await?);
+ assert!(get_mobile_welcome_email(&pool, "[email protected]").await?);
+
+ // Duplicate insert returns false
+ assert!(!insert_mobile_welcome_email(&pool, email).await?);
+
+ Ok(())
+}