pdk/lib.rs
1// Copyright (c) 2025, Salesforce, Inc.,
2// All rights reserved.
3// For full license text, see the LICENSE.txt file
4
5//! PDK - Policy Development Kit
6//!
7//! Features
8//! - `ll`: USE AT OWN RISK: low-level items that may change without notice. Exposes the low level implementation details.
9//! - `experimental_metrics`: USE AT OWN RISK: this feature is experimental and might change without notice. Exposes the api for host metrics.
10//! - `script_stream`: Enable the [`Evaluator`](script::Evaluator) to consume streamed payloads.
11
12pub mod classy {
13 //! Classy - an asynchronous policy development kit
14 //!
15 //! An abstraction layer over the proxy_wasm framework that transforms the event oriented framework into an async/await model.
16
17 #[cfg(feature = "ll")]
18 pub use classy::*;
19
20 /// Re-export of the host calls of the proxy_wasm crate.
21 pub use classy::proxy_wasm;
22}
23
24#[cfg(feature = "ll")]
25pub use pdk_macros::{entrypoint, entrypoint_flex};
26
27/// # The PDK High Level Framework.
28///
29/// The PDK High Level Framework is the foundation for writting single-threaded
30/// non-blocking filters as main building block for custom policies.
31///
32/// `pdk::hl` relies on a reduced portion of the Rust async ecosystem, due to the limitations
33/// of the underlying WebAssembly platform and their single-threaded nature.
34/// Despite being single-threaded, `pdk::hl` supports concurrent execution of
35/// multiple incoming HTTP flows (Request/Response pairs).
36pub mod hl {
37 pub use classy::hl::*;
38 pub use pdk_macros::{entrypoint, entrypoint_flex};
39}
40
41pub mod logger {
42 //! Wrapper of the log package to enrich log messages with policy and request metadata.
43 pub use pdk_core::logger::{debug, error, info, trace, warn};
44}
45
46pub mod authentication {
47 //! Utils to access and share authentication data between filters.
48 pub use pdk_core::policy_context::authentication::{
49 Authentication, AuthenticationData, AuthenticationHandler,
50 };
51}
52
53pub mod metadata {
54 //! Exposes metadata for the policy.
55 pub use pdk_core::policy_context::api::*;
56}
57
58pub mod jwt {
59 //! PDK JWT Lib
60 //!
61 //! Library for JWT token validation. It provides JWT handling including
62 //! signature validation, claims parsing and token extraction from HTTP headers.
63 pub use jwt_lib::api::*;
64}
65
66pub mod cache {
67 //! Cache Library
68 //!
69 //! A caching library that provides a simple [`Cache`] trait and a FIFO-based
70 //! in-memory implementation. It is designed to be injected and configured during the policy
71 //! configuration phase and supports both policy-isolated and shared caches across policies.
72 pub use cache_lib::{builder::CacheBuilder, error::CacheError, Cache};
73}
74
75pub mod data_storage {
76 //! Data Storage Library
77 //!
78 //! This library provides data storage functionality with support for:
79 //!
80 //! - Local and distributed data storage
81 //! - Support for CAS (Compare-And-Swap) operations
82 //! - Configurable storage modes (Always, Absent, CAS)
83 //! - Asynchronous API for high-performance applications
84 //!
85 pub use data_storage_lib::*;
86}
87
88pub mod contracts {
89 //! PDK Contracts Lib
90 //!
91 //! Library for validating client credentials against Anypoint Platform API contracts
92 //! in Flex Gateway custom policies. It periodically fetches contracts from the
93 //! platform and keeps a local cache to enable fast authentication and authorization
94 //! decisions within the policy request path.
95 pub use contracts_lib::*;
96}
97
98pub mod cors {
99 //! PDK CORS Lib
100 //!
101 //! Library for validating CORS requests and producing CORS responses in Flex Gateway custom
102 //! policies. It evaluates request headers against a provided configuration and
103 //! returns the appropriate CORS response headers for preflight and main flows.
104 pub use cors_lib::*;
105}
106
107pub mod lock {
108 //! PDK Lock Lib
109 //!
110 //! Primitives for coordinating work among Flex Gateway workers and policies. Generated locks
111 //! expires automatically if not refreshed and are released on drop.
112 pub use lock_lib::*;
113}
114
115pub mod rl {
116 //! PDK Rate Limit Lib
117 //!
118 //! Library which provides rate limiting functionality with support for both local and distributed
119 //! storage backends.
120 pub use rate_limit_lib::*;
121}
122
123pub mod flex_abi {
124 //! PDK Flex ABI
125 //!
126 //! This library provides the Application Binary Interface (ABI) for PDK Flex policies,
127 //! enabling communication between policy implementations and the Flex Gateway runtime.
128 pub use pdk_flex_abi::api;
129 pub use pdk_flex_abi::entrypoint;
130}
131
132pub mod script {
133 //! PDK Script
134 //!
135 //! An interpreter for script expressions and the set of operations and types to interoperate with Rust.
136 pub use pdk_script::*;
137}
138
139pub mod policy_violation {
140 //! Information regarding if a policy from the chain reached a scenario that can be considered
141 //! an expected error. E.g. a policy that checks credentials and they were invalid.
142 pub use pdk_core::policy_context::policy_violation::*;
143}
144
145pub mod serde {
146 //! Serializing and deserializing of service names.
147 pub use pdk_core::client::{
148 deserialize_service, deserialize_service_opt, deserialize_service_opt_vec,
149 deserialize_service_vec, service_name,
150 };
151}
152
153#[doc(hidden)]
154pub mod __internal {
155 //! Internal module for PDK
156 //!
157 //! This module contains internal types and functions that are not intended to be used
158 //! directly by policy authors.
159 //! They are the wrappers needed to declare the contexts for the proxy wasm environment.
160 pub use pdk_core::host::context::root::RootContextAdapter;
161 pub use pdk_core::init::configure;
162}
163
164#[cfg(feature = "ll")]
165pub mod policy_context {
166 //! Policy context related APIs to access Flex policy data.
167 pub use pdk_core::policy_context::*;
168}
169
170#[cfg(feature = "experimental_metrics")]
171pub mod metrics {
172 //! PDK Metrics Lib
173 //!
174 //! USE AT OWN RISK: The metrics lib is experimental and subject to change.
175 //!
176 //! Expose interfaces to handle counters and gauges for custom policies.
177 pub use metrics_lib::*;
178}