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

lancer-next-sdk

v1.0.0

Published

Lancer Server SDK for Next.js

Readme

lancer-next-sdk

Lancer Server SDK for Next.js


Overview

lancer-next-sdk is the official server-side SDK for integrating Lancer with Next.js applications. It simplifies handling Lancer webhooks and authentication workflows, ensuring secure and efficient communication between your Next.js backend and Lancer's APIs.


Features

  • Webhook Handling: Securely process and verify Lancer webhook events.
  • Authentication Flows: Authenticate Lancer sessions and manage custom session logic.
  • Next.js Compatibility: Designed for use in Next.js API routes (/api).

Installation

Install the SDK via npm:

npm install lancer-next-sdk

Getting Started

1. Initialize the Lancer SDK

Create a reusable instance of the Lancer class with your webhookSecret for signature verification. Store this in a shared module for easy access across your API routes.

import Lancer from "lancer-next-sdk";

const lancer = new Lancer({
  webhookSecret: "<your-lancer-webhook-secret>",
});

export default lancer;

| Parameter | Type | Required | Description | |-----------------|----------|----------|-------------------------------------------------| | webhookSecret | string | No | Secret key used to verify webhook signatures. |


2. Set Up API Routes

Authentication Endpoint

Use the authenticate method to handle session authentication in a Next.js API route. Implement your custom logic within the handler.

import lancer from "@/lib/lancer";

export const POST = lancer.authenticate(async (token, payload) => {
  console.log("Session Payload:", payload);

  // Custom authentication logic
  return {
    ownerId: "<user-id>", // Replace with actual user/owner ID
    status: 200, // HTTP status code
  };
});

| Parameter | Type | Description | |--------------|--------------------------|------------------------------------------------| | token | string | Lancer session token from the Authorization header. | | payload | SessionRequest | Payload containing session details from Lancer. |

Example Request
POST /api/auth
Authorization: Bearer <token>
{
  "file_size": 10485760,     
  "file_name": "example.txt",
  "max_chunk": 2,            
  "chunk_size": 5242880,     
  "provider": "LOCAL"    
}
Example Response
{
  "ownerId": "user123"
}

Webhook Endpoint

Handle webhook events sent by Lancer with the handleWebhook method. Enable verification to ensure payload integrity using your webhookSecret.

import lancer from "@/lib/lancer";

export const POST = lancer.handleWebhook(async (event) => {
  console.log("Webhook Event: ", event.event);

  console.log("Webhook Data: ", event.data);

  // Handle event data
  return Response.json({}, { status: 200 });
}, true);

| Parameter | Type | Description | |-----------------|---------------------------------------------------|---------------------------------------------------------------| | handler | (event: WebhookEvent) => Promise<Response> | Callback function to process webhook events. | | verification | boolean | Enables payload verification (default: true). |

Verification Workflow
  • The SDK verifies the x-timestamp and x-signature headers.
  • The payload is signed using HMAC SHA-256 and compared to the provided signature.
  • If the verification fails, the SDK responds with 403 Access Restricted.
Example Webhook Payload
{
  "type": "FILE_UPLOAD",
  "data": {
    "id": "session-12345",
    "file_size": 10485760,
    "chunk_size": 5242880,
    "max_chunk": 2,
    "file_name": "example.txt",
    "temp_path": "/tmp/session-12345",
    "owner_id": "user-67890",
    "current_chunk": 0,
    "provider": "LOCAL"
  }
}

Important

Add the authentication endpoints & webhook handling payload to lancer config file as auth-endpoint & webhook-endpoint


Security Best Practices

  1. Protect Your Webhook Secret: Ensure your webhookSecret is stored securely in environment variables.
  2. Verify Signatures: Always enable verification for sensitive webhook endpoints.
  3. Rate Limit Your API: Use rate-limiting middleware to prevent abuse.

License

MIT License © 2025 Weekend Dev Labs