coil_customer_sdk/
registry.rs1use std::sync::Arc;
2
3use crate::{
4 BackendError, CheckoutHooks, CmsHooks, CustomerPluginDescriptor, VerifiedWebhookAssetHooks,
5 VerifiedWebhookHooks,
6};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum RegisteredHookKind {
10 Checkout,
11 CmsPagePublish,
12 VerifiedWebhook,
13 VerifiedWebhookAssets,
14}
15
16impl RegisteredHookKind {
17 pub const fn as_str(self) -> &'static str {
18 match self {
19 Self::Checkout => "checkout",
20 Self::CmsPagePublish => "cms.page_publish",
21 Self::VerifiedWebhook => "verified_webhook",
22 Self::VerifiedWebhookAssets => "verified_webhook.assets",
23 }
24 }
25}
26
27pub trait CustomerHookRegistry {
28 fn register_checkout_hooks(
29 &mut self,
30 hooks: Arc<dyn CheckoutHooks>,
31 ) -> Result<(), BackendError>;
32
33 fn register_cms_hooks(&mut self, hooks: Arc<dyn CmsHooks>) -> Result<(), BackendError>;
34
35 fn register_verified_webhook_hooks(
36 &mut self,
37 hooks: Arc<dyn VerifiedWebhookHooks>,
38 ) -> Result<(), BackendError>;
39
40 fn register_verified_webhook_asset_hooks(
41 &mut self,
42 hooks: Arc<dyn VerifiedWebhookAssetHooks>,
43 ) -> Result<(), BackendError>;
44}
45
46pub trait CustomerBackendPlugin: Send + Sync + 'static {
47 fn descriptor(&self) -> CustomerPluginDescriptor;
48
49 fn register(&self, registry: &mut dyn CustomerHookRegistry) -> Result<(), BackendError>;
50}