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

@kluglabs/ygg-js

v0.1.2

Published

YGG client-side file upload SDK

Readme

YGG JavaScript Upload Client

A simple client-side JavaScript SDK for uploading files to YGG storage. Requires a public key and JWT token (validated against Supabase JWKS).

Installation

npm install @kluglabs/ygg-js
# or
yarn add @kluglabs/ygg-js

Quick Start

import { upload } from '@kluglabs/ygg-js';

const file = document.querySelector('input[type="file"]').files[0];
const { url, fileId } = await upload(file, {
  key: 'ygg_pub_...',
  authorization: `Bearer ${supabaseJwt}`, // Required: JWT from Supabase
  onProgress: (pct) => console.log(`Progress: ${pct}%`),
});

console.log(`File uploaded: ${url}`);

API Reference

upload(file, options)

Uploads a file to YGG storage.

Parameters:

  • file (File | Blob) - The file to upload
  • options (UploadOptions) - Upload configuration

Returns: Promise<UploadResult>

UploadOptions

{
  key: string;                    // Required: Public key (ygg_pub_...)
  authorization: string;           // Required: "Bearer <jwt>" - JWT validated against Supabase JWKS
  endpoint?: string;               // Optional: API endpoint (default: http://localhost:9000)
  filename?: string;               // Optional: Override filename
  contentType?: string;            // Optional: Override content type
  path?: string;                   // Optional: Logical path
  metadata?: Record<string, string>; // Optional: File metadata
  onProgress?: (pct: number) => void; // Optional: Progress callback (0-100)
  signal?: AbortSignal;            // Optional: Abort signal for cancellation
}

UploadResult

{
  fileId: string;      // Unique file identifier
  url: string;        // URL to access the uploaded file
  size: number;       // File size in bytes
  contentType: string; // MIME type of the file
}

Examples

Basic Upload

import { upload } from '@kluglabs/ygg-js';

const file = document.querySelector('input[type="file"]').files[0];
const { url, fileId } = await upload(file, {
  key: 'ygg_pub_...',
  authorization: `Bearer ${supabaseJwt}`, // Required: JWT from Supabase
});

console.log(`File uploaded: ${url}`);

Upload with Metadata

import { upload } from '@kluglabs/ygg-js';

const result = await upload(file, {
  key: 'ygg_pub_...',
  authorization: `Bearer ${supabaseJwt}`, // Required
  filename: 'custom-name.jpg',
  path: 'uploads/images',
  metadata: {
    userId: 'user_123',
    category: 'profile'
  }
});

Upload with Progress Tracking

import { upload } from '@kluglabs/ygg-js';

const [progress, setProgress] = useState(0);

await upload(file, {
  key: 'ygg_pub_...',
  authorization: `Bearer ${supabaseJwt}`, // Required
  onProgress: (pct) => {
    setProgress(pct);
    console.log(`Upload progress: ${pct}%`);
  }
});

Upload with Abort Signal

import { upload } from '@kluglabs/ygg-js';

const controller = new AbortController();

// Cancel upload
const cancelUpload = () => {
  controller.abort();
};

await upload(file, {
  key: 'ygg_pub_...',
  authorization: `Bearer ${supabaseJwt}`, // Required
  signal: controller.signal
});

Security Considerations

Important: All uploads require JWT validation:

  1. JWT is mandatory - The JWT token is validated against Supabase JWKS for the project/environment associated with the public key
  2. No anonymous uploads - Every upload must include a valid JWT token
  3. Public keys identify project/env - The public key determines which Supabase instance's JWKS to validate against
  4. Use scoped keys - Create public keys with limited permissions when possible
  5. Monitor usage - Track uploads to detect abuse

Error Handling

The upload function throws errors that you can catch:

try {
  const result = await upload(file, { key: 'ygg_pub_...' });
} catch (error) {
  if (error.message.includes('upload_failed')) {
    console.error('Upload failed');
  } else if (error.message === 'aborted') {
    console.log('Upload was cancelled');
  } else {
    console.error('Upload error:', error.message);
  }
}