npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

secure-fetch-sdk

v3.0.0

Published

A lightweight TypeScript SDK for encrypting and obfuscating API requests to protect sensitive URLs, query parameters, route IDs, and request bodies.

Readme

Secure Fetch SDK

A lightweight TypeScript SDK for encrypting and obfuscating API requests to protect sensitive URLs, query parameters, route IDs, and request bodies.


Overview

Secure Fetch SDK helps frontend applications send encrypted requests by:

  • Automatically encrypting URLs, route params, query params, and POST bodies.
  • Hiding sensitive request data from browser network tabs and potential attackers.
  • Supporting all HTTP methods: GET, POST, PUT, PATCH, DELETE, etc.
  • Sending obfuscated URLs instead of clear text ones.
  • Dispatching encrypted payload events for debugging or logging.
  • Working seamlessly with a middleware that decrypts and forwards to backend APIs.

Features

  • Transparent request encryption.
  • Supports multiple encryption layers simultaneously (route, query, body).
  • Easy integration with fetch and XMLHttpRequest.
  • Emits browser events with encrypted payloads for developer tools or extensions.
  • Compatible with JavaScript and TypeScript (ESM modules).
  • No extra server-side changes required.
  • Easy middleware as a proxy.

Installation

npm install secure-fetch-sdk

OR

yarn add secure-fetch-sdk

Usage - Backend (Node.JS)

Usage of middleware in node.js express API:

import express from "express";
import cors from "cors";
import {secureProxyMiddleware, configureSecureEnv} from "secure-fetch-sdk";

const app = express();
app.use(cors());

app.use('/secure', express.text({ type: 'text/plain' }), secureProxyMiddleware);

// pass it via .env not add the secret in plain text
configureSecureEnv("secret-key", true) 

app.get('/api/greet/:name', (req, res) => {
  res.json({ message: `Hello, ${req.params.name}` });
});

app.post('/api/echo', (req, res) => {
  res.json({ you_sent: req.body });
});

const port = 3000;
app.listen(port, () => console.log(`Example backend listening on port ${port}`));

Usage in the frontend

VITE_SHARED_SECRET='secret-key'
VITE_MIDDLEWARE_BASE_URL=http://localhost:3000
VITE_SECURE_DEBUG_MODE=true
import React, { useState } from 'react';
import { configureSecureFetch, secureFetch } from 'secure-fetch-sdk'; // Adjust path accordingly

// Initialize SDK with secret key and middleware base URL
// For Vite, use import.meta.env; for Create React App, use process.env.REACT_APP_*
const SHARED_SECRET = import.meta.env.VITE_SHARED_SECRET;
const MIDDLEWARE_BASE_URL = import.meta.env.VITE_MIDDLEWARE_BASE_URL;
const SECURE_DEBUG_MODE = import.meta.env.VITE_SECURE_DEBUG_MODE;

configureSecureFetch(SHARED_SECRET, `${MIDDLEWARE_BASE_URL}/secure`, SECURE_DEBUG_MODE);

export default function App() {
  const [greeting, setGreeting] = useState(null);
  const [error, setError] = useState(null);
  const [name, setName] = useState('John');

  const fetchGreeting = async () => {
    setError(null);
    setGreeting(null);
    try {
      // Original backend API path you want to call (unencrypted)
      const originalUrl = `${MIDDLEWARE_BASE_URL}/api/greet/${name}`;

      // Use secureFetch to send the request via your encrypted proxy middleware
      const response = await secureFetch(originalUrl, { method: 'GET' });

      if (!response.ok) {
        setError(`HTTP error: ${response.status}`);
        return;
      }

      const data = await response.json();
      setGreeting(data.message);
    } catch (err) {
      setError('Failed to fetch greeting');
      console.error(err);
    }
  };

  return (
    <div style={{ padding: 20 }}>
      <h2>Secure Fetch Demo</h2>
      <input
        value={name}
        onChange={(e) => setName(e.target.value)}
        placeholder="Enter your name"
      />
      <button onClick={fetchGreeting}>Fetch Greeting</button>
      {greeting && <p>Greeting: {greeting}</p>}
      {error && <p style={{ color: 'red' }}>Error: {error}</p>}
    </div>
  );
}

Middleware Integration

To decrypt and forward encrypted requests, use the accompanying middleware service:

Middleware listens for encrypted requests.

Decrypts route, query params, and body.

Forwards request to actual backend.

Returns backend response transparently.

Add this usage and route to ensure a route is called as proxy:

app.use('/secure', express.text({ type: 'text/plain' }), secureProxyMiddleware);

Configuration Options

sharedSecret (string): Secret key for symmetric encryption.

debug (boolean): Show console logs.

Development

The SDK is written in TypeScript, compiled to ESM for modern frontend usage and node js. More information to be available soon.

License

MIT License

Author

Created and Maintained by: Ethern-Myth