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 🙏

© 2026 – Pkg Stats / Ryan Hefner

encapsula-client

v0.1.0

Published

Frontend decoder client for Encapsula API response encryption.

Readme

encapsula-client

Frontend decoder client for Encapsula API response encryption.

Automatically detects and decrypts AES-256-GCM encrypted API responses returned by the Encapsula Laravel middleware.

Installation

npm install encapsula-client

Quick Start

import { decodeEncapsulaResponse } from 'encapsula-client';

const response = await fetch('/api/users');
const body = await response.json();
const users = await decodeEncapsulaResponse(body, {
  key: import.meta.env.VITE_ENCAPSULA_KEY,
});

API

decodeEncapsulaResponse<T>(data, options): Promise<T>

Decodes an Encapsula encrypted envelope. If the data is not encrypted, returns it unchanged.

const data = await decodeEncapsulaResponse(responseBody, { key: 'base64-key' });

isEncapsulaEnvelope(data): boolean

Check whether a value is an encrypted Encapsula envelope.

if (isEncapsulaEnvelope(responseBody)) {
  // Handle encrypted response
}

attachEncapsulaAxiosInterceptor(instance, options): number

Attach a response interceptor to an Axios instance. Returns the interceptor ID.

import axios from 'axios';
import { attachEncapsulaAxiosInterceptor } from 'encapsula-client';

const api = axios.create({ baseURL: '/api' });
attachEncapsulaAxiosInterceptor(api, {
  key: import.meta.env.VITE_ENCAPSULA_KEY,
});

const { data } = await api.get('/users'); // Decrypted automatically

createEncapsulaFetch(options): fetchFn

Create a fetch wrapper that decrypts responses automatically.

import { createEncapsulaFetch } from 'encapsula-client';

const apiFetch = createEncapsulaFetch({
  key: import.meta.env.VITE_ENCAPSULA_KEY,
});

const users = await apiFetch('/api/users');

Vanilla JavaScript

For projects without npm, copy examples/vanilla-js/encapsula-helper.js into your project:

<script src="encapsula-helper.js"></script>
<script>
  fetch('/api/users')
    .then(r => r.json())
    .then(data => Encapsula.decode(data, 'your-base64-key'))
    .then(users => console.log(users));
</script>

Framework Examples

Environment Variables

| Framework | Variable | |---|---| | Vite / Vue / Nuxt | VITE_ENCAPSULA_KEY | | Create React App | REACT_APP_ENCAPSULA_KEY | | Next.js | NEXT_PUBLIC_ENCAPSULA_KEY | | Node.js | ENCAPSULA_KEY |

Generate a key with the Laravel backend:

php -r "echo base64_encode(random_bytes(32));"

Error Handling

try {
  const data = await decodeEncapsulaResponse(body, { key });
} catch (error) {
  // Possible errors:
  // - Invalid key length
  // - Decryption failed (wrong key or corrupted payload)
  // - Decrypted payload is not valid JSON
  console.error(error.message);
}

Unencrypted responses pass through unchanged — no error is thrown.

Publishing

npm install
npm run typecheck
npm test
npm run build
npm login
npm publish

Security Notes

  • HTTPS is still required. This package does not replace TLS.
  • Not a replacement for authentication or authorization. Use proper auth to control API access.
  • Frontend keys are visible in built frontend apps. Do not make misleading security claims.
  • Authenticated users can access decrypted data in their browser. This prevents casual network tab inspection, not determined access.
  • Do not hardcode production keys in committed source. Use environment variables.

License

MIT