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

@filefn/client

v0.4.0

Published

FileFn client SDK for browser file uploads

Readme

@filefn/client

Browser client for FileFn uploads, file reads and offline (OPFS) staging.

npm install @filefn/client
import { createFileFnClient } from '@filefn/client';

const files = createFileFnClient({ baseUrl: 'https://api.example.com/files' });

const upload = files.uploadFile({ policy: 'avatars', file });
upload.onProgress((p) => console.log(p.bytesUploaded, '/', p.bytesTotal));
const { fileId, versionId } = await upload.done();

Transport options

createFileFnClient takes the same transport options as @datafn/client:

| Option | Default | Purpose | | --- | --- | --- | | fetch | global fetch | Fetch implementation used for every request: upload init, part sign, part upload, part and upload complete, status, file and artifact reads, delete, and offline sync replay. | | credentials | 'same-origin' | RequestCredentials mode for requests sent to FileFn. | | getAuthHeaders | none | Headers added to every request sent to FileFn. Called for each request and each retry attempt. |

When fetch and getAuthHeaders are both given, the headers from getAuthHeaders are merged onto every request that fetch sends to FileFn (storage part uploads never get them; see Part uploads). Request-specific headers (the JSON Content-Type, signed part headers, x-upload-session-token) are applied after them and replace an auth header with the same name in any letter case. Leaving out every option keeps the previous behavior: the global fetch with same-origin credentials.

The injected fetch is called without a this binding, so window.fetch can be passed directly. If no fetch is given, the global fetch is looked up when each request is sent.

Session cookies with a CSRF header

const files = createFileFnClient({
  baseUrl: 'https://api.example.com/files',
  credentials: 'include', // send the session cookie to a cross-origin API
  getAuthHeaders: () => ({ 'x-csrf-token': readCsrfToken() }),
});

A cross-origin API must answer CORS requests with Access-Control-Allow-Credentials: true, set Access-Control-Allow-Origin to your app's explicit origin (browsers reject * for credentialed requests), and allow the CSRF header.

Bearer token

const files = createFileFnClient({
  baseUrl: 'https://api.example.com/files',
  getAuthHeaders: async () => ({ Authorization: `Bearer ${await session.getAccessToken()}` }),
});

Custom fetch

const files = createFileFnClient({
  baseUrl: '/api/files',
  fetch: (input, init) => appFetch(input, init), // e.g. tracing, a test double, or a platform fetch
});

Part uploads

A part URL returned by the sign endpoint is sent through the same fetch:

  • A proxy upload URL under baseUrl (a root-relative path, which is appended to baseUrl, or an absolute URL with the same origin and path prefix) is a FileFn request. Dot segments (.., including %2e%2e) are resolved before this check, so a path that climbs out of baseUrl is not a FileFn request. It gets the getAuthHeaders headers and the configured credentials. A baseUrl of '/' or '' means the page origin root, so every same-origin path is under it.
  • Any other URL (for example an R2 bucket presigned URL, or a protocol-relative //host/... URL, which is sent to that host) gets only its signed headers and the upload session token, with credentials: 'omit'. Your auth headers and cookies are never sent to storage.

In a browser, baseUrl and the part URL are resolved against the document base URL (which follows <base href>), or the location in a worker, the same way fetch resolves them. The part request is sent to that resolved absolute URL, so the URL that is checked is the URL that is requested. Outside a browser the part URL is sent as given.

Offline replay

With offline: { enabled: true }, uploads staged while offline are replayed by the client that runs the sync, using that client's fetch, credentials and current getAuthHeaders result. Auth headers are never written to OPFS, so an upload staged before a page reload is sent with the fresh token of the client created after it.