-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
295 changed files
with
32,923 additions
and
5,817 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
members = [ | ||
"stripe_types", | ||
"stripe_webhook", | ||
"openapi", | ||
"tests", | ||
"generated/*", | ||
"examples/*", | ||
|
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[package] | ||
name = "async_stripe_forwarding" | ||
version.workspace = true | ||
description.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
keywords.workspace = true | ||
categories.workspace = true | ||
|
||
[lib] | ||
path = "src/mod.rs" | ||
|
||
[dependencies] | ||
serde.workspace = true | ||
serde_json = { workspace = true, optional = true } | ||
smol_str.workspace = true | ||
miniserde.workspace = true | ||
stripe_types = {path = "../../stripe_types"} | ||
stripe_client_core = {path = "../../stripe_client_core"} | ||
|
||
stripe_shared = {path = "../../generated/stripe_shared"} | ||
|
||
|
||
[features] | ||
serialize = ["stripe_types/serialize","stripe_shared/serialize"] | ||
deserialize = ["stripe_types/deserialize","stripe_shared/deserialize", "dep:serde_json"] | ||
forwarding_request = [] | ||
|
||
full = ["forwarding_request"] | ||
|
||
|
||
[package.metadata.docs.rs] | ||
features = ["full"] | ||
|
109 changes: 109 additions & 0 deletions
109
generated/async_stripe_forwarding/src/forwarded_request_context.rs
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,109 @@ | ||
/// Metadata about the forwarded request. | ||
#[derive(Clone, Debug)] | ||
#[cfg_attr(feature = "serialize", derive(serde::Serialize))] | ||
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] | ||
pub struct ForwardedRequestContext { | ||
/// The time it took in milliseconds for the destination endpoint to respond. | ||
pub destination_duration: i64, | ||
/// The IP address of the destination. | ||
pub destination_ip_address: String, | ||
} | ||
#[doc(hidden)] | ||
pub struct ForwardedRequestContextBuilder { | ||
destination_duration: Option<i64>, | ||
destination_ip_address: Option<String>, | ||
} | ||
|
||
#[allow(unused_variables, clippy::match_single_binding, clippy::single_match)] | ||
const _: () = { | ||
use miniserde::de::{Map, Visitor}; | ||
use miniserde::json::Value; | ||
use miniserde::{make_place, Deserialize, Result}; | ||
use stripe_types::miniserde_helpers::FromValueOpt; | ||
use stripe_types::{MapBuilder, ObjectDeser}; | ||
|
||
make_place!(Place); | ||
|
||
impl Deserialize for ForwardedRequestContext { | ||
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor { | ||
Place::new(out) | ||
} | ||
} | ||
|
||
struct Builder<'a> { | ||
out: &'a mut Option<ForwardedRequestContext>, | ||
builder: ForwardedRequestContextBuilder, | ||
} | ||
|
||
impl Visitor for Place<ForwardedRequestContext> { | ||
fn map(&mut self) -> Result<Box<dyn Map + '_>> { | ||
Ok(Box::new(Builder { | ||
out: &mut self.out, | ||
builder: ForwardedRequestContextBuilder::deser_default(), | ||
})) | ||
} | ||
} | ||
|
||
impl MapBuilder for ForwardedRequestContextBuilder { | ||
type Out = ForwardedRequestContext; | ||
fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> { | ||
Ok(match k { | ||
"destination_duration" => Deserialize::begin(&mut self.destination_duration), | ||
"destination_ip_address" => Deserialize::begin(&mut self.destination_ip_address), | ||
|
||
_ => <dyn Visitor>::ignore(), | ||
}) | ||
} | ||
|
||
fn deser_default() -> Self { | ||
Self { | ||
destination_duration: Deserialize::default(), | ||
destination_ip_address: Deserialize::default(), | ||
} | ||
} | ||
|
||
fn take_out(&mut self) -> Option<Self::Out> { | ||
Some(Self::Out { | ||
destination_duration: self.destination_duration?, | ||
destination_ip_address: self.destination_ip_address.take()?, | ||
}) | ||
} | ||
} | ||
|
||
impl<'a> Map for Builder<'a> { | ||
fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> { | ||
self.builder.key(k) | ||
} | ||
|
||
fn finish(&mut self) -> Result<()> { | ||
*self.out = self.builder.take_out(); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl ObjectDeser for ForwardedRequestContext { | ||
type Builder = ForwardedRequestContextBuilder; | ||
} | ||
|
||
impl FromValueOpt for ForwardedRequestContext { | ||
fn from_value(v: Value) -> Option<Self> { | ||
let Value::Object(obj) = v else { | ||
return None; | ||
}; | ||
let mut b = ForwardedRequestContextBuilder::deser_default(); | ||
for (k, v) in obj { | ||
match k.as_str() { | ||
"destination_duration" => { | ||
b.destination_duration = Some(FromValueOpt::from_value(v)?) | ||
} | ||
"destination_ip_address" => { | ||
b.destination_ip_address = Some(FromValueOpt::from_value(v)?) | ||
} | ||
|
||
_ => {} | ||
} | ||
} | ||
b.take_out() | ||
} | ||
} | ||
}; |
183 changes: 183 additions & 0 deletions
183
generated/async_stripe_forwarding/src/forwarded_request_details.rs
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,183 @@ | ||
/// Details about the request forwarded to the destination endpoint. | ||
#[derive(Clone, Debug)] | ||
#[cfg_attr(feature = "serialize", derive(serde::Serialize))] | ||
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] | ||
pub struct ForwardedRequestDetails { | ||
/// The body payload to send to the destination endpoint. | ||
pub body: String, | ||
/// The headers to include in the forwarded request. | ||
/// Can be omitted if no additional headers (excluding Stripe-generated ones such as the Content-Type header) should be included. | ||
pub headers: Vec<async_stripe_forwarding::ForwardedRequestHeader>, | ||
/// The HTTP method used to call the destination endpoint. | ||
pub http_method: ForwardedRequestDetailsHttpMethod, | ||
} | ||
#[doc(hidden)] | ||
pub struct ForwardedRequestDetailsBuilder { | ||
body: Option<String>, | ||
headers: Option<Vec<async_stripe_forwarding::ForwardedRequestHeader>>, | ||
http_method: Option<ForwardedRequestDetailsHttpMethod>, | ||
} | ||
|
||
#[allow(unused_variables, clippy::match_single_binding, clippy::single_match)] | ||
const _: () = { | ||
use miniserde::de::{Map, Visitor}; | ||
use miniserde::json::Value; | ||
use miniserde::{make_place, Deserialize, Result}; | ||
use stripe_types::miniserde_helpers::FromValueOpt; | ||
use stripe_types::{MapBuilder, ObjectDeser}; | ||
|
||
make_place!(Place); | ||
|
||
impl Deserialize for ForwardedRequestDetails { | ||
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor { | ||
Place::new(out) | ||
} | ||
} | ||
|
||
struct Builder<'a> { | ||
out: &'a mut Option<ForwardedRequestDetails>, | ||
builder: ForwardedRequestDetailsBuilder, | ||
} | ||
|
||
impl Visitor for Place<ForwardedRequestDetails> { | ||
fn map(&mut self) -> Result<Box<dyn Map + '_>> { | ||
Ok(Box::new(Builder { | ||
out: &mut self.out, | ||
builder: ForwardedRequestDetailsBuilder::deser_default(), | ||
})) | ||
} | ||
} | ||
|
||
impl MapBuilder for ForwardedRequestDetailsBuilder { | ||
type Out = ForwardedRequestDetails; | ||
fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> { | ||
Ok(match k { | ||
"body" => Deserialize::begin(&mut self.body), | ||
"headers" => Deserialize::begin(&mut self.headers), | ||
"http_method" => Deserialize::begin(&mut self.http_method), | ||
|
||
_ => <dyn Visitor>::ignore(), | ||
}) | ||
} | ||
|
||
fn deser_default() -> Self { | ||
Self { | ||
body: Deserialize::default(), | ||
headers: Deserialize::default(), | ||
http_method: Deserialize::default(), | ||
} | ||
} | ||
|
||
fn take_out(&mut self) -> Option<Self::Out> { | ||
Some(Self::Out { | ||
body: self.body.take()?, | ||
headers: self.headers.take()?, | ||
http_method: self.http_method?, | ||
}) | ||
} | ||
} | ||
|
||
impl<'a> Map for Builder<'a> { | ||
fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> { | ||
self.builder.key(k) | ||
} | ||
|
||
fn finish(&mut self) -> Result<()> { | ||
*self.out = self.builder.take_out(); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl ObjectDeser for ForwardedRequestDetails { | ||
type Builder = ForwardedRequestDetailsBuilder; | ||
} | ||
|
||
impl FromValueOpt for ForwardedRequestDetails { | ||
fn from_value(v: Value) -> Option<Self> { | ||
let Value::Object(obj) = v else { | ||
return None; | ||
}; | ||
let mut b = ForwardedRequestDetailsBuilder::deser_default(); | ||
for (k, v) in obj { | ||
match k.as_str() { | ||
"body" => b.body = Some(FromValueOpt::from_value(v)?), | ||
"headers" => b.headers = Some(FromValueOpt::from_value(v)?), | ||
"http_method" => b.http_method = Some(FromValueOpt::from_value(v)?), | ||
|
||
_ => {} | ||
} | ||
} | ||
b.take_out() | ||
} | ||
} | ||
}; | ||
/// The HTTP method used to call the destination endpoint. | ||
#[derive(Copy, Clone, Eq, PartialEq)] | ||
pub enum ForwardedRequestDetailsHttpMethod { | ||
Post, | ||
} | ||
impl ForwardedRequestDetailsHttpMethod { | ||
pub fn as_str(self) -> &'static str { | ||
use ForwardedRequestDetailsHttpMethod::*; | ||
match self { | ||
Post => "POST", | ||
} | ||
} | ||
} | ||
|
||
impl std::str::FromStr for ForwardedRequestDetailsHttpMethod { | ||
type Err = (); | ||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
use ForwardedRequestDetailsHttpMethod::*; | ||
match s { | ||
"POST" => Ok(Post), | ||
_ => Err(()), | ||
} | ||
} | ||
} | ||
impl std::fmt::Display for ForwardedRequestDetailsHttpMethod { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
f.write_str(self.as_str()) | ||
} | ||
} | ||
|
||
impl std::fmt::Debug for ForwardedRequestDetailsHttpMethod { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
f.write_str(self.as_str()) | ||
} | ||
} | ||
#[cfg(feature = "serialize")] | ||
impl serde::Serialize for ForwardedRequestDetailsHttpMethod { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
serializer.serialize_str(self.as_str()) | ||
} | ||
} | ||
impl miniserde::Deserialize for ForwardedRequestDetailsHttpMethod { | ||
fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor { | ||
crate::Place::new(out) | ||
} | ||
} | ||
|
||
impl miniserde::de::Visitor for crate::Place<ForwardedRequestDetailsHttpMethod> { | ||
fn string(&mut self, s: &str) -> miniserde::Result<()> { | ||
use std::str::FromStr; | ||
self.out = | ||
Some(ForwardedRequestDetailsHttpMethod::from_str(s).map_err(|_| miniserde::Error)?); | ||
Ok(()) | ||
} | ||
} | ||
|
||
stripe_types::impl_from_val_with_from_str!(ForwardedRequestDetailsHttpMethod); | ||
#[cfg(feature = "deserialize")] | ||
impl<'de> serde::Deserialize<'de> for ForwardedRequestDetailsHttpMethod { | ||
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||
use std::str::FromStr; | ||
let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?; | ||
Self::from_str(&s).map_err(|_| { | ||
serde::de::Error::custom("Unknown value for ForwardedRequestDetailsHttpMethod") | ||
}) | ||
} | ||
} |
Oops, something went wrong.