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

lunar-apollo-protobuf

v1.0.2

Published

A javascript based lunar apollo protobufs decoder/encoder

Downloads

366

Readme

lunar-apollo-protobuf

Node.js protobufjs based encoder/decoder for Lunar Client apollo messages

  • Uses proto files from https://buf.build/lunarclient/apollo

Installation

npm i lunar-apollo-protobuf

Then, you can just import it as you would in any project like so:

// in CommonJS
const { LunarProtoUtils } = require('lunar-apollo-protobuf');
// or in ESM
import { LunarProtoUtils } from 'lunar-apollo-protobuf'; 

/** 
 * @type {Buffer} Buffer containing a full lunarclient.apollo message
 * IE the data in a plugin packet with the channel `lunar:apollo`
 */
const buffer = null;

/** May throw if the buffer is not a valid message or is not structured correctly */
const decoded = LunarProtoUtils.decodeMessage(buffer);

if(decoded['@name'] === 'PlayerHandshakeMessage') {
    console.log(`Client is using lunar ${decoded?.lunarClientVersion?.semver}`);
    const message = LunarProtoUtils.create('OverrideServerRichPresenceMessage', {
        gameName: "Visual Studio Code",
        gameState: "Editing index.ts",
        gameVariantName: "Coding...",
        teamMaxSize: 1,
        teamCurrentSize: 1
    });
    message.mapName = "Package/lunar-apollo-protobuf";
    /** Fake function accepting a buffer to send to the client using the `lunar:apollo` channel */
    sendLunarApolloMessageToClient(LunarProtoUtils.encodeMessage(message));
}

...or in typescript

import { LunarProtoUtils } from 'lunar-apollo-protobuf'; 

/** 
 * Buffer containing a full lunarclient.apollo message
 * IE the data in a plugin packet with the channel `lunar:apollo`
 */
const buffer: Buffer = null;

/** May throw if the buffer is not a valid message or is not structured correctly */
const decoded = LunarProtoUtils.decodeMessage(buffer);

if(decoded['@name'] === 'PlayerHandshakeMessage') {
    console.log(`Client is using lunar ${decoded?.lunarClientVersion?.semver}`);
    const message = LunarProtoUtils.create('OverrideServerRichPresenceMessage', {
        gameName: "Visual Studio Code",
        gameState: "Editing index.ts",
        gameVariantName: "Coding...",
        teamMaxSize: 1,
        teamCurrentSize: 1
    });
    message.mapName = "Package/lunar-apollo-protobuf";
    /** Fake function accepting a buffer to send to the client using the `lunar:apollo` channel */
    sendLunarApolloMessageToClient(LunarProtoUtils.encodeMessage(message));
};

There are two main ways of using this library to create/verify the same message, consider this:

import type { LunarProtoMessage, LunarProtoMessageClassByName } from "lunar-apollo-protobuf";
import { LunarProtoUtils } from "lunar-apollo-protobuf";

// Just calling `LunarProtoMessage.lookupType(message['@name'])` would do the same
// thing in this specific case but this is to demonstrate using the exported types
function getInstancingType<T extends LunarProtoMessage>(message: T): LunarProtoMessageClassByName<T['@name']> {
    const messageClass = LunarProtoUtils.lookupType(message['@name']);
    return messageClass as LunarProtoMessageClassByName<T['@name']>;
};

// * An already decoded message or created message
const myMessage: LunarProtoMessage = null; 

const messageClass = getInstancingType(myMessage);

// Creating a new message
const newMessage = messageClass.create({ /** */ });
// Which could also be written as this
const newMessage = LunarProtoUtils.create(myMessage['@name'], { /** */ });

// Though with `messageClass`, you can follow up calls without having to supply the type name again
const errorMessage = messageClass.verify(newMessage);
// ...instead off
const errorMessage = LunarProtoUtils.verify(myMessage['@name'], newMessage);

if(errorMessage) {
    console.error('newMessage is invalid!', errorMessage);
}

...or in CommonJS using jsdoc:

const { LunarProtoUtils } = require("lunar-apollo-protobuf");

/**
 * @typedef {import('lunar-apollo-protobuf').LunarProtoMessage} LunarProtoMessage
*/
/**
 * @template {import("lunar-apollo-protobuf").LunarProtoMessageName} T
 * @typedef {import('lunar-apollo-protobuf').LunarProtoMessageClassByName<T>} LunarProtoMessageClassByName
 */

/**
 * @template {LunarProtoMessage} T
 * @param {T} message 
 * @returns {LunarProtoMessageClassByName<T['@name']>}
 */
function getInstancingType(message) {
    const messageClass = LunarProtoUtils.lookupType(message['@name']);
    return /** @type {LunarProtoMessageClassByName<T['@name']>} */ (messageClass);
};

// ...
// The rest is similar
// ...

Building from source

git clone https://github.com/Oxtaly/lunar-apollo-protobuf.git
cd ./lunar-apollo-protobuf
npm i
npx tsc

Then run the setup script to download the .proto files and automatically bundle them

npm run setup

Additional thanks

This project makes use of the protobuf decoder by pawtip to decode the protobuf message type from the initial message buffer; It was also very useful during the debugging process thanks to their very nice to use website