Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: modularize vercel api crate #7329

Merged
merged 1 commit into from
Feb 9, 2024
Merged
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
2 changes: 1 addition & 1 deletion crates/turborepo-api-client/src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_trait::async_trait;
use reqwest::Method;
use turborepo_vercel_api::TelemetryEvent;
use turborepo_vercel_api::telemetry::TelemetryEvent;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could avoid having to do the ::telemetry::, which I'm not opposed to.


use crate::{retry, AnonAPIClient, Error};

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-telemetry/src/events/command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;

use serde::{Deserialize, Serialize};
use turborepo_vercel_api::{TelemetryCommandEvent, TelemetryEvent};
use turborepo_vercel_api::telemetry::{TelemetryCommandEvent, TelemetryEvent};
use uuid::Uuid;

use super::{Event, EventBuilder, EventType, Identifiable};
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-telemetry/src/events/generic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;

use serde::{Deserialize, Serialize};
use turborepo_vercel_api::{TelemetryEvent, TelemetryGenericEvent};
use turborepo_vercel_api::telemetry::{TelemetryEvent, TelemetryGenericEvent};
use uuid::Uuid;

use super::{Event, EventBuilder, EventType, Identifiable, TrackedErrors};
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-telemetry/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod task;
/// These events must be added to the backend (telemetry.vercel.com)
/// before they can be tracked - invalid or unknown events will be
/// ignored.
pub use turborepo_vercel_api::TelemetryEvent;
pub use turborepo_vercel_api::telemetry::TelemetryEvent;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum EventType {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-telemetry/src/events/repo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use turborepo_vercel_api::{TelemetryEvent, TelemetryRepoEvent};
use turborepo_vercel_api::telemetry::{TelemetryEvent, TelemetryRepoEvent};
use uuid::Uuid;

use super::{Event, EventBuilder, EventType, Identifiable};
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-telemetry/src/events/task.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use turborepo_vercel_api::{TelemetryEvent, TelemetryTaskEvent};
use turborepo_vercel_api::telemetry::{TelemetryEvent, TelemetryTaskEvent};
use uuid::Uuid;

use super::{Event, EventBuilder, EventType, Identifiable, TrackedErrors};
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ mod tests {
};
use turborepo_api_client::telemetry::TelemetryClient;
use turborepo_ui::UI;
use turborepo_vercel_api::{TelemetryEvent, TelemetryGenericEvent};
use turborepo_vercel_api::telemetry::{TelemetryEvent, TelemetryGenericEvent};

use crate::init;

Expand Down
54 changes: 2 additions & 52 deletions crates/turborepo-vercel-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! mock server (`turborepo-vercel-api-mock`)
use serde::{Deserialize, Serialize};
use url::Url;
pub mod telemetry;
pub mod token;

#[derive(Debug, Clone, Deserialize)]
pub struct VerifiedSsoUser {
Expand Down Expand Up @@ -158,58 +160,6 @@ impl AnalyticsEvent {
}
}

// telemetry events

/// All possible telemetry events must be included in this enum.
///
/// These events must be added to the backend (telemetry.vercel.com)
/// before they can be tracked - invalid or unknown events will be
/// ignored.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum TelemetryEvent {
Task(TelemetryTaskEvent),
Command(TelemetryCommandEvent),
Repo(TelemetryRepoEvent),
Generic(TelemetryGenericEvent),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TelemetryCommandEvent {
pub id: String,
pub command: String,
pub key: String,
pub value: String,
pub parent_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TelemetryRepoEvent {
pub id: String,
pub repo: String,
pub key: String,
pub value: String,
pub parent_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TelemetryTaskEvent {
pub id: String,
pub package: String,
pub task: String,
pub key: String,
pub value: String,
pub parent_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TelemetryGenericEvent {
pub id: String,
pub key: String,
pub value: String,
pub parent_id: Option<String>,
}

#[cfg(test)]
mod tests {
use test_case::test_case;
Expand Down
53 changes: 53 additions & 0 deletions crates/turborepo-vercel-api/src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// telemetry events

use serde::{Deserialize, Serialize};

/// All possible telemetry events must be included in this enum.
///
/// These events must be added to the backend (telemetry.vercel.com)
/// before they can be tracked - invalid or unknown events will be
/// ignored.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum TelemetryEvent {
Task(TelemetryTaskEvent),
Command(TelemetryCommandEvent),
Repo(TelemetryRepoEvent),
Generic(TelemetryGenericEvent),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TelemetryCommandEvent {
pub id: String,
pub command: String,
pub key: String,
pub value: String,
pub parent_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TelemetryRepoEvent {
pub id: String,
pub repo: String,
pub key: String,
pub value: String,
pub parent_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TelemetryTaskEvent {
pub id: String,
pub package: String,
pub task: String,
pub key: String,
pub value: String,
pub parent_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TelemetryGenericEvent {
pub id: String,
pub key: String,
pub value: String,
pub parent_id: Option<String>,
}
28 changes: 28 additions & 0 deletions crates/turborepo-vercel-api/src/token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResponseTokenMetadata {
id: String,
name: String,
#[serde(rename = "type")]
token_type: String,
origin: String,
scopes: Vec<Scope>,
#[serde(rename = "activeAt")]
active_at: u64,
#[serde(rename = "createdAt")]
created_at: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Scope {
#[serde(rename = "type")]
scope_type: String,
origin: String,
#[serde(rename = "createdAt")]
created_at: u64,
#[serde(rename = "expiresAt")]
expires_at: Option<u64>,
#[serde(rename = "teamId")]
team_id: Option<String>,
}
Comment on lines +1 to +28
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't being used yet but I plan on using it for upcoming token work.

Loading