-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: initial customer-server boilerplate * chore: wire customer-server via cli * chore: render Subject in customer-server schema * refactor: move Customer to own file * fix: context wording
- Loading branch information
1 parent
7f21975
commit b7e8bcd
Showing
23 changed files
with
444 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[package] | ||
name = "customer-server" | ||
version = "0.3.32-dev" | ||
edition = "2021" | ||
|
||
[features] | ||
|
||
fail-on-warnings = [] | ||
|
||
[dependencies] | ||
lana-app = { path = "../app" } | ||
|
||
core-customer = { path = "../../core/customer", features = ["graphql"] } | ||
|
||
tracing-utils = { path = "../../lib/tracing-utils" } | ||
jwks-utils = { path = "../../lib/jwks-utils" } | ||
|
||
es-entity = { workspace = true, features = ["graphql"] } | ||
|
||
serde = { workspace = true } | ||
serde_json = { workspace = true } | ||
async-graphql = { workspace = true } | ||
async-graphql-axum = { workspace = true } | ||
tracing = { workspace = true } | ||
axum = { workspace = true } | ||
axum-extra = { workspace = true } | ||
tower-http = { workspace = true } | ||
tokio = { workspace = true } | ||
anyhow = { workspace = true } | ||
uuid = { workspace = true } | ||
chrono = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("{}", customer_server::graphql::schema(None).sdl().trim()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct CustomerServerConfig { | ||
#[serde(default = "default_port")] | ||
pub port: u16, | ||
#[serde(default = "default_jwks_url")] | ||
pub jwks_url: String, | ||
#[serde(default = "aud")] | ||
pub aud: String, | ||
} | ||
|
||
impl Default for CustomerServerConfig { | ||
fn default() -> Self { | ||
Self { | ||
port: default_port(), | ||
jwks_url: default_jwks_url(), | ||
aud: "https://admin-api/graphql".to_string(), | ||
} | ||
} | ||
} | ||
|
||
fn default_port() -> u16 { | ||
5254 | ||
} | ||
|
||
fn default_jwks_url() -> String { | ||
"http://localhost:4456/.well-known/jwks.json".to_string() | ||
} | ||
|
||
fn aud() -> String { | ||
"https://admin-api/graphql".to_string() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use async_graphql::*; | ||
|
||
use core_customer::Customer as DomainCustomer; | ||
|
||
use super::customer::*; | ||
|
||
#[derive(SimpleObject)] | ||
#[graphql(name = "Subject")] | ||
pub struct AuthenticatedSubject { | ||
customer: Customer, | ||
} | ||
|
||
impl From<DomainCustomer> for AuthenticatedSubject { | ||
fn from(entity: DomainCustomer) -> Self { | ||
Self { | ||
customer: Customer::from(entity), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use async_graphql::*; | ||
|
||
use std::sync::Arc; | ||
|
||
use core_customer::{AccountStatus, Customer as DomainCustomer, KycLevel}; | ||
|
||
use crate::primitives::*; | ||
|
||
#[derive(SimpleObject, Clone)] | ||
#[graphql(complex)] | ||
pub struct Customer { | ||
id: ID, | ||
customer_id: UUID, | ||
status: AccountStatus, | ||
level: KycLevel, | ||
created_at: Timestamp, | ||
|
||
#[graphql(skip)] | ||
pub(super) entity: Arc<DomainCustomer>, | ||
} | ||
|
||
impl From<DomainCustomer> for Customer { | ||
fn from(customer: DomainCustomer) -> Self { | ||
Customer { | ||
id: customer.id.to_global_id(), | ||
customer_id: UUID::from(customer.id), | ||
status: customer.status, | ||
level: customer.level, | ||
created_at: customer.created_at().into(), | ||
entity: Arc::new(customer), | ||
} | ||
} | ||
} | ||
|
||
#[ComplexObject] | ||
impl Customer { | ||
async fn email(&self) -> &str { | ||
&self.entity.email | ||
} | ||
|
||
async fn telegram_id(&self) -> &str { | ||
&self.entity.telegram_id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Helper to extract the 'app' and 'sub' args | ||
// instead of: | ||
// | ||
// async fn users(&self, ctx: &Context<'_>) -> async_graphql::Result<Vec<User>> { | ||
// let app = ctx.data_unchecked::<LanaApp>(); | ||
// let AdminAuthContext { sub } = ctx.data()?; | ||
// | ||
// use | ||
// | ||
// async fn users(&self, ctx: &Context<'_>) -> async_graphql::Result<Vec<User>> { | ||
// let (app, sub) = app_and_sub_from_ctx!(ctx); | ||
// | ||
#[macro_export] | ||
macro_rules! app_and_sub_from_ctx { | ||
($ctx:expr) => {{ | ||
let app = $ctx.data_unchecked::<lana_app::app::LanaApp>(); | ||
let $crate::primitives::CustomerAuthContext { sub } = $ctx.data()?; | ||
(app, sub) | ||
}}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#[macro_use] | ||
pub mod macros; | ||
mod authenticated_subject; | ||
mod customer; | ||
mod schema; | ||
|
||
use async_graphql::*; | ||
|
||
pub use schema::*; | ||
|
||
use lana_app::app::LanaApp; | ||
|
||
pub fn schema(app: Option<LanaApp>) -> Schema<Query, EmptyMutation, EmptySubscription> { | ||
let mut schema_builder = Schema::build(Query, EmptyMutation, EmptySubscription); | ||
|
||
if let Some(app) = app { | ||
schema_builder = schema_builder.data(app); | ||
} | ||
|
||
schema_builder.finish() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
enum AccountStatus { | ||
INACTIVE | ||
ACTIVE | ||
} | ||
|
||
|
||
type Customer { | ||
id: ID! | ||
customerId: UUID! | ||
status: AccountStatus! | ||
level: KycLevel! | ||
createdAt: Timestamp! | ||
email: String! | ||
telegramId: String! | ||
} | ||
|
||
|
||
|
||
|
||
enum KycLevel { | ||
NOT_KYCED | ||
BASIC | ||
ADVANCED | ||
} | ||
|
||
type Query { | ||
me: Subject! | ||
} | ||
|
||
|
||
type Subject { | ||
customer: Customer! | ||
} | ||
|
||
scalar Timestamp | ||
|
||
scalar UUID | ||
|
||
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
schema { | ||
query: Query | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use async_graphql::{Context, Object}; | ||
|
||
use super::authenticated_subject::*; | ||
|
||
pub struct Query; | ||
|
||
#[Object] | ||
impl Query { | ||
async fn me(&self, ctx: &Context<'_>) -> async_graphql::Result<AuthenticatedSubject> { | ||
let (app, sub) = app_and_sub_from_ctx!(ctx); | ||
let customer = app.customers().find_for_subject(sub).await?; | ||
Ok(AuthenticatedSubject::from(customer)) | ||
} | ||
} |
Oops, something went wrong.