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

m4g-sdk

v3.0.3

Published

SDK para integración de resultados y contexto de juego con Supabase

Readme

m4g-sdk

Librería TypeScript para la gestión de partidas, movimientos y resultados de juegos multijugador o single player, integrando Supabase como backend.

Características

  • Creación y gestión de partidas (matches)
  • Registro de movimientos y resultados de jugadores
  • Soporte para modos PvP y Single Player (SP)
  • Prevención de envíos duplicados de resultados
  • Integración sencilla con Supabase
  • Utilidad para extraer parámetros de usuario y juego desde la URL

Instalación

npm install m4g-sdk

Asegúrate de tener instaladas las dependencias necesarias:

npm install @supabase/supabase-js uuid
npm install --save-dev @types/uuid

Uso Básico

Inicialización

Antes de usar la librería, inicializa Supabase en tu proyecto:

import { createClient } from '@supabase/supabase-js';

export const supabase = createClient('https://your-project.supabase.co', 'public-anon-key');

Extraer parámetros de la URL

El SDK no obtiene automáticamente el playerId ni el gameId desde la URL.
Para extraerlos, utiliza la función getLaunchContextFromUrl:

import { getLaunchContextFromUrl } from 'm4g-sdk';

const ctx = getLaunchContextFromUrl();
// ctx.playerId, ctx.gameId, ctx.matchId, etc.

Crear una partida usando parámetros de la URL

import { getLaunchContextFromUrl, createMatch } from 'm4g-sdk';

const ctx = getLaunchContextFromUrl(); // Solo extrae gameId, playerId, player2Id

const result = await createMatch({
  gameId: ctx.gameId,
  player1: ctx.playerId,
  player2: ctx.player2Id ?? 'user-2'
});

if (result.ok) {
  // Aquí recibes el matchId generado
  const matchId = result.matchId;
  // ... puedes guardar el matchId en tu estado o contexto
}

Enviar resultado de juego

import { submitGameResult } from 'm4g-sdk';

const result = await submitGameResult({
  matchId: 'match-123',
  playerId: 'user-1',
  score: 100,
  gameMode: 'pvp' // o 'sp'
});

if (result.ok) {
  console.log('Resultado enviado correctamente');
} else {
  console.error('Error al enviar resultado:', result.error);
}

Registrar movimiento en partida

import { submitMatchMovement } from 'm4g-sdk';

const result = await submitMatchMovement({
  matchId: 'match-123',
  playerId: 'user-1',
  moveData: { action: 'move', x: 1, y: 2 }
});

if (result.ok) {
  console.log('Movimiento registrado');
} else {
  console.error('Error al registrar movimiento:', result.error);
}

Enviar puntuación

import { submitGameScore } from 'm4g-sdk';

await submitGameScore({
  matchId,
  playerId,
  score,
});

Finalizar partida

import { endMatch } from 'm4g-sdk';

await endMatch({
  matchId: 'match-123',
  winnerId: 'user-1',
  loserId: 'user-2',
  status: 'finished',
});

Actualizar puntuación de jugador

import { updatePlayerScore } from 'm4g-sdk';

await updatePlayerScore({
  userId: 'user-1',
  gameId: 'game-123',
  score: 150,
});

Tipos principales

  • CreateMatchInput
  • CreateMatchOutput
  • SubmitGameResultInput
  • SubmitGameResultOutput
  • SubmitMatchMovementInput
  • SubmitMatchMovementOutput
  • LaunchContext

Configuración adicional

Si usas TypeScript y tienes problemas con los tipos de uuid, instala los tipos:

npm install --save-dev @types/uuid

Si usas un bundler como tsup y tienes problemas con declaraciones, crea un archivo types/uuid.d.ts con:

declare module 'uuid';

Contribuir

¡Las contribuciones son bienvenidas! Abre un issue o pull request para sugerencias o mejoras.

Licencia

MIT