Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ pub fn urlencode<T: AsRef<str>>(s: T) -> String {
pub mod access_token_service_api;
pub mod api_key_service_api;
pub mod auth_service_api;
pub mod org_service_api;
pub mod user_service_api;
pub mod employee_service_api;
pub mod mfa_service_api;
pub mod org_service_api;
pub(crate) mod report_service_api;
pub mod user_service_api;

pub mod configuration;
132 changes: 132 additions & 0 deletions src/apis/report_service_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* propelauth
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
* Generated by: https://openapi-generator.tech
*/

use reqwest;

use super::{configuration, Error};
use crate::apis::ResponseContent;
use crate::models::reports::{
FetchReportQuery, OrgReport, OrgReportType, UserReportPage, UserReportType,
};
use crate::propelauth::auth::AUTH_HOSTNAME_HEADER;

/// struct for typed errors of methods [`fetch_user_report`] or [`fetch_org_report`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FetchReportRequestError {
Status401(serde_json::Value),
Status400(serde_json::Value),
Status429(serde_json::Value),
UnknownValue(serde_json::Value),
}

pub(crate) async fn fetch_user_report(
configuration: &configuration::Configuration,
report_key: UserReportType,
params: FetchReportQuery,
) -> Result<UserReportPage, Error<FetchReportRequestError>> {
let local_var_configuration = configuration;

let local_var_client = &local_var_configuration.client;

let local_var_uri_str = format!(
"{}/api/backend/v1/user_report/{report_key}",
local_var_configuration.base_path,
report_key = report_key.as_str(),
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

local_var_req_builder = local_var_req_builder.query(&params);

if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.header(
AUTH_HOSTNAME_HEADER,
local_var_configuration.auth_hostname.to_owned(),
);

let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<FetchReportRequestError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error: crate::apis::ResponseContent<FetchReportRequestError> =
ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}

pub(crate) async fn fetch_org_report(
configuration: &configuration::Configuration,
report_key: OrgReportType,
params: FetchReportQuery,
) -> Result<OrgReport, Error<FetchReportRequestError>> {
let local_var_configuration = configuration;

let local_var_client = &local_var_configuration.client;

let local_var_uri_str = format!(
"{}/api/backend/v1/org_report/{report_key}",
local_var_configuration.base_path,
report_key = report_key.as_str(),
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

local_var_req_builder = local_var_req_builder.query(&params);

if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.header(
AUTH_HOSTNAME_HEADER,
local_var_configuration.auth_hostname.to_owned(),
);

let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<FetchReportRequestError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error: crate::apis::ResponseContent<FetchReportRequestError> =
ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
1 change: 1 addition & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub mod user_ids_query;
pub use self::user_ids_query::UserIdsQuery;
pub mod user_in_org;
pub use self::user_in_org::UserInOrg;
pub mod reports;
pub mod user_metadata;
pub use self::user_metadata::UserMetadata;
pub mod user_paged_response;
Expand Down
168 changes: 168 additions & 0 deletions src/models/reports.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Default)]
pub struct ReportPagination {
pub page_size: Option<i32>,
pub page_number: Option<i32>,
}

#[derive(Clone, Debug, PartialEq, Serialize)]
pub(crate) struct FetchReportQuery {
pub(crate) report_interval: ReportInterval,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) page_size: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) page_number: Option<i32>,
}

#[derive(Clone, Debug, PartialEq)]
pub enum OrgReportType {
Attrition,
Growth,
Reengagement,
Churn,
}

impl OrgReportType {
pub fn as_str(&self) -> &'static str {
match self {
OrgReportType::Attrition => "attrition",
OrgReportType::Growth => "growth",
OrgReportType::Reengagement => "reengagement",
OrgReportType::Churn => "churn",
}
}
}

#[derive(Clone, Debug, PartialEq)]
pub enum UserReportType {
TopInviter,
Champion,
Reengagement,
Churn,
}

impl UserReportType {
pub fn as_str(&self) -> &'static str {
match self {
UserReportType::TopInviter => "top_inviter",
UserReportType::Champion => "champion",
UserReportType::Reengagement => "reengagement",
UserReportType::Churn => "churn",
}
}
}

#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(untagged)]
pub(crate) enum ReportInterval {
TopInviter(TopInviterReportInterval),
Champion(ChampionReportInterval),
Reengagement(ReengagementReportInterval),
Churn(ChurnReportInterval),
Attrition(AttritionReportInterval),
Growth(GrowthReportInterval),
}

#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum TopInviterReportInterval {
#[serde(rename = "30")]
ThirtyDays,
#[serde(rename = "60")]
SixtyDays,
#[serde(rename = "90")]
NinetyDays,
}

#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum ChampionReportInterval {
#[serde(rename = "30")]
ThirtyDays,
#[serde(rename = "60")]
SixtyDays,
#[serde(rename = "90")]
NinetyDays,
}

#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum ReengagementReportInterval {
#[serde(rename = "Weekly")]
Weekly,
#[serde(rename = "Monthly")]
Monthly,
}

#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum ChurnReportInterval {
#[serde(rename = "7")]
SevenDays,
#[serde(rename = "14")]
FourteenDays,
#[serde(rename = "30")]
ThirtyDays,
}

#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum AttritionReportInterval {
#[serde(rename = "30")]
ThirtyDays,
#[serde(rename = "60")]
SixtyDays,
#[serde(rename = "90")]
NinetyDays,
}

#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum GrowthReportInterval {
#[serde(rename = "30")]
ThirtyDays,
#[serde(rename = "60")]
SixtyDays,
#[serde(rename = "90")]
NinetyDays,
}

#[derive(Debug, Clone, Deserialize)]
pub struct OrgReportRecord {
pub id: String,
pub report_id: String,
pub org_id: String,
pub name: String,
pub num_users: i32,
pub org_created_at: i64,
pub extra_properties: Option<serde_json::Value>,
}

#[derive(Deserialize)]
pub struct OrgReport {
pub org_reports: Vec<OrgReportRecord>,
pub current_page: i64,
pub total_count: i64,
pub page_size: i64,
pub has_more_results: bool,
pub report_time: i64,
}

#[derive(Debug, Clone, Deserialize)]
pub struct UserReportRecord {
pub id: String,
pub report_id: String,
pub user_id: String,
pub user_created_at: i64,
pub username: Option<String>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub email: String,
pub last_active_at: i64,
pub org_data: serde_json::Value,
pub extra_properties: Option<serde_json::Value>,
}
#[derive(Deserialize)]
pub struct UserReportPage {
pub user_reports: Vec<UserReportRecord>,
pub current_page: i64,
pub total_count: i64,
pub page_size: i64,
pub has_more_results: bool,
pub report_time: i64,
}
12 changes: 10 additions & 2 deletions src/propelauth/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
use crate::models::AuthTokenVerificationMetadata;
use crate::propelauth::access_token::AccessTokenService;
use crate::propelauth::api_key::ApiKeyService;
use crate::propelauth::employee::EmployeeService;
use crate::propelauth::errors::InitializationError;
use crate::propelauth::helpers::map_autogenerated_error;
use crate::propelauth::mfa::MfaService;
use crate::propelauth::options::{AuthOptions, AuthOptionsWithTokenVerification};
use crate::propelauth::org::OrgService;
use crate::propelauth::reports::ReportService;
use crate::propelauth::token::TokenService;
use crate::propelauth::user::UserService;
use crate::propelauth::employee::EmployeeService;

static BACKEND_API_BASE_URL: &str = "https://propelauth-api.com";
pub(crate) static AUTH_HOSTNAME_HEADER: &str = "X-Propelauth-url";
Expand Down Expand Up @@ -82,28 +83,28 @@
}

/// API requests related to users
pub fn user(&self) -> UserService {

Check warning on line 86 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 86 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing
UserService {
config: &self.config,
}
}

/// API requests related to organizations
pub fn org(&self) -> OrgService {

Check warning on line 93 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 93 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing
OrgService {
config: &self.config,
}
}

/// API requests related to organizations
pub fn api_key(&self) -> ApiKeyService {

Check warning on line 100 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 100 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing
ApiKeyService {
config: &self.config,
}
}

/// Verify access tokens from your frontend
pub fn verify(&self) -> TokenService {

Check warning on line 107 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 107 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing
TokenService {
token_verification_metadata: &self.token_verification_metadata,
issuer: &self.issuer,
Expand All @@ -111,25 +112,32 @@
}

/// API requests related to access tokens.
pub fn access_token(&self) -> AccessTokenService {

Check warning on line 115 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 115 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing
AccessTokenService {
config: &self.config,
}
}

/// API requests related to employees.
pub fn employee(&self) -> EmployeeService {

Check warning on line 122 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 122 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing
EmployeeService {
config: &self.config,
}
}

/// API requests related to employees.
/// API requests related to mfa.
pub fn mfa(&self) -> MfaService {

Check warning on line 129 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 129 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing
MfaService {
config: &self.config,
}
}

/// API requests related to reports.
pub fn reports(&self) -> ReportService {

Check warning on line 136 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing

Check warning on line 136 in src/propelauth/auth.rs

View workflow job for this annotation

GitHub Actions / Rust project

hiding a lifetime that's elided elsewhere is confusing
ReportService {
config: &self.config,
}
}
}

fn validate_auth_url_extract_hostname(auth_url: &str) -> Result<String, InitializationError> {
Expand Down
17 changes: 14 additions & 3 deletions src/propelauth/errors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::models::{
BadCreateAccessTokenError, BadCreateMagicLinkRequest, BadCreateOrgRequest,
BadCreateUserRequest, BadFetchOrgQuery, BadFetchUsersByQuery, BadFetchUsersInOrgQuery,
BadMigrateUserRequest, BadMigrateUserPasswordRequest, BadUpdateOrgRequest, BadUpdatePasswordRequest,
BadUpdateUserEmailRequest, BadUpdateUserMetadataRequest,
BadMigrateUserPasswordRequest, BadMigrateUserRequest, BadUpdateOrgRequest,
BadUpdatePasswordRequest, BadUpdateUserEmailRequest, BadUpdateUserMetadataRequest,
};
use thiserror::Error;

Expand Down Expand Up @@ -462,7 +462,7 @@ pub enum VerifyStepUpGrantError {

#[derive(Error, Debug, PartialEq, Clone)]
pub enum SendSmsCodeError {
#[error("Invalid API Key")]
#[error("Invalid API Key")]
InvalidApiKey,

#[error("Rate limited by PropelAuth")]
Expand Down Expand Up @@ -511,3 +511,14 @@ pub enum VerifySmsChallengeError {
UnexpectedException,
}

#[derive(Error, Debug, PartialEq, Clone)]
pub enum FetchReportError {
#[error("Invalid API Key")]
InvalidApiKey,

#[error("Rate limited by PropelAuth")]
PropelAuthRateLimit,

#[error("Unexpected exception, please try again")]
UnexpectedException,
}
Loading
Loading