pub struct NodeApiKey { /* private fields */ }Expand description
Safe API key wrapper.
This wrapper prevents accidental logging or printing of API keys.
The key value is hidden from toString() and debug output.
const key = new NodeApiKey('sk-secret-key');
console.log(key.toString()); // "[REDACTED]"
console.log(key.exposeSecretForApiCall()); // "sk-secret-key"Implementations§
Source§impl NodeApiKey
impl NodeApiKey
Source§impl NodeApiKey
impl NodeApiKey
pub fn into_reference( val: NodeApiKey, env: Env, ) -> Result<Reference<NodeApiKey>>
pub fn into_instance(self, env: Env) -> Result<ClassInstance<NodeApiKey>>
Source§impl NodeApiKey
impl NodeApiKey
Sourcepub fn new(key: String) -> Self
pub fn new(key: String) -> Self
Create a new API key from a string.
Security Note: Prefer loading keys from CredentialStore
rather than hardcoding them.
Sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Returns “[REDACTED]” - safe for logging.
This method intentionally hides the key value to prevent accidental exposure in logs.
Sourcepub fn expose_secret_for_api_call(&self) -> String
pub fn expose_secret_for_api_call(&self) -> String
Get the actual key value.
Warning: Only use this when actually sending to an API. The verbose method name is intentional to discourage casual use.
Sourcepub fn starts_with(&self, prefix: String) -> bool
pub fn starts_with(&self, prefix: String) -> bool
Check if the key starts with a prefix (e.g., “sk-ant-” for Anthropic).
Trait Implementations§
Source§impl Debug for NodeApiKey
impl Debug for NodeApiKey
Source§impl FromNapiMutRef for NodeApiKey
impl FromNapiMutRef for NodeApiKey
Source§unsafe fn from_napi_mut_ref(
env: napi_env,
napi_val: napi_value,
) -> Result<&'static mut Self>
unsafe fn from_napi_mut_ref( env: napi_env, napi_val: napi_value, ) -> Result<&'static mut Self>
Safety Read more
Source§impl FromNapiRef for NodeApiKey
impl FromNapiRef for NodeApiKey
Source§unsafe fn from_napi_ref(
env: napi_env,
napi_val: napi_value,
) -> Result<&'static Self>
unsafe fn from_napi_ref( env: napi_env, napi_val: napi_value, ) -> Result<&'static Self>
Safety Read more
Source§impl FromNapiValue for &NodeApiKey
impl FromNapiValue for &NodeApiKey
Source§unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
Safety Read more
fn from_unknown(value: JsUnknown) -> Result<Self, Error>
Source§impl FromNapiValue for &mut NodeApiKey
impl FromNapiValue for &mut NodeApiKey
Source§unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
Safety Read more
fn from_unknown(value: JsUnknown) -> Result<Self, Error>
Source§impl ToNapiValue for NodeApiKey
impl ToNapiValue for NodeApiKey
Source§unsafe fn to_napi_value(env: napi_env, val: NodeApiKey) -> Result<napi_value>
unsafe fn to_napi_value(env: napi_env, val: NodeApiKey) -> Result<napi_value>
Safety Read more
Source§impl TypeName for &NodeApiKey
impl TypeName for &NodeApiKey
Source§impl TypeName for &mut NodeApiKey
impl TypeName for &mut NodeApiKey
Source§impl TypeName for NodeApiKey
impl TypeName for NodeApiKey
Source§impl ValidateNapiValue for &NodeApiKey
impl ValidateNapiValue for &NodeApiKey
Source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more
Source§impl ValidateNapiValue for &mut NodeApiKey
impl ValidateNapiValue for &mut NodeApiKey
Source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more
Auto Trait Implementations§
impl Freeze for NodeApiKey
impl RefUnwindSafe for NodeApiKey
impl Send for NodeApiKey
impl Sync for NodeApiKey
impl Unpin for NodeApiKey
impl UnwindSafe for NodeApiKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more