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

@walkeros/server-core

v0.4.2

Published

Server-specific utilities for walkerOS

Readme

Server Core Utilities for walkerOS

Source CodeNPM Package

Server core utilities are Node.js-specific functions designed for server-side walkerOS implementations. These utilities handle server communication, cryptographic hashing, and other backend operations.

Installation

Import server utilities from the @walkeros/server-core package:

import { sendServer, getHashServer } from '@walkeros/server-core';

Server Communication

sendServer

sendServer(url: string, data?: SendDataValue, options?: SendServerOptions): Promise<SendResponse> sends HTTP requests using Node.js built-in modules (http/https).

// Simple POST request
const response = await sendServer('https://api.example.com/events', {
  name: 'page view',
  data: { url: '/home' },
});

// With custom options
const response = await sendServer(url, data, {
  method: 'PUT',
  headers: {
    Authorization: 'Bearer token',
    'Content-Type': 'application/json',
  },
  timeout: 10000, // 10 seconds
});

if (response.ok) {
  console.log('Data sent successfully:', response.data);
} else {
  console.error('Send failed:', response.error);
}

SendServerOptions

interface SendServerOptions {
  headers?: Record<string, string>; // Custom HTTP headers
  method?: string; // HTTP method (default: 'POST')
  timeout?: number; // Request timeout in milliseconds (default: 5000)
}

SendResponse

interface SendResponse {
  ok: boolean; // Indicates if the request was successful (2xx status)
  data?: unknown; // Parsed response data (if available)
  error?: string; // Error message (if request failed)
}

Cryptographic Operations

getHashServer

getHashServer(str: string, length?: number): Promise<string> generates SHA-256 hashes using Node.js crypto module.

// Generate full SHA-256 hash
const fullHash = await getHashServer('[email protected]');
// Returns full 64-character hash

// Generate shortened hash for anonymization
const userFingerprint = await getHashServer(
  userAgent + language + ipAddress + date.getDate(),
  16,
);
// Returns 16-character hash like '47e0bdd10f04ef13'

// User identification while preserving privacy
const anonymousId = await getHashServer(`${userEmail}${deviceId}${salt}`, 12);

This function is commonly used for:

  • User Anonymization: Creating privacy-safe user identifiers
  • Fingerprinting: Generating device/session fingerprints
  • Data Deduplication: Creating consistent identifiers
  • Privacy Compliance: Hashing PII for GDPR/CCPA compliance

Usage Examples

Event Processing Pipeline

import { sendServer, getHashServer } from '@walkeros/server-core';

async function processUserEvent(event, userInfo) {
  // Anonymize user identification
  const anonymousUserId = await getHashServer(
    `${userInfo.email}${userInfo.deviceId}`,
    16,
  );

  // Prepare event with anonymized data
  const processedEvent = {
    ...event,
    user: {
      ...event.user,
      id: anonymousUserId,
    },
  };

  // Send to analytics service
  const result = await sendServer(
    'https://analytics.example.com/collect',
    processedEvent,
    {
      headers: {
        'X-API-Key': process.env.ANALYTICS_API_KEY,
      },
      timeout: 8000,
    },
  );

  return result;
}

Privacy-Safe Session Tracking

async function createSessionId(request) {
  const fingerprint = [
    request.headers['user-agent'],
    request.ip.replace(/\.\d+$/, '.0'), // Anonymize IP
    new Date().toDateString(), // Daily rotation
  ].join('|');

  return await getHashServer(fingerprint, 20);
}

Error Handling

Server utilities include comprehensive error handling:

try {
  const response = await sendServer(url, data, { timeout: 5000 });

  if (response.ok) {
    // Success - response.data contains the result
    console.log('Success:', response.data);
  } else {
    // Request completed but with error status
    console.warn('Request failed:', response.error);
  }
} catch (error) {
  // Network error, timeout, or other exception
  console.error('Network error:', error.message);
}

Performance Considerations

Timeout Configuration

Configure appropriate timeouts based on your use case:

// Fast analytics endpoint
await sendServer(url, data, { timeout: 2000 });

// Critical business data
await sendServer(url, data, { timeout: 15000 });

Batch Processing

For high-volume scenarios, consider batching:

const events = [
  /* ... multiple events ... */
];

const response = await sendServer(
  '/api/events/batch',
  {
    events,
    timestamp: Date.now(),
  },
  {
    timeout: 10000,
  },
);

Connection Reuse

The underlying Node.js HTTP agent automatically reuses connections for better performance with multiple requests to the same host.

Security Notes

  • HTTPS Only: Use HTTPS URLs in production for encrypted transmission
  • API Keys: Store sensitive credentials in environment variables
  • Timeout Limits: Set reasonable timeouts to prevent hanging requests
  • Hash Salting: Use application-specific salts when hashing sensitive data
// Good security practices
const apiKey = process.env.ANALYTICS_API_KEY;
const saltedHash = await getHashServer(`${userData}${process.env.HASH_SALT}`);

await sendServer('https://secure-api.example.com/events', data, {
  headers: {
    Authorization: `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
  },
  timeout: 5000,
});

Integration with Core

Server utilities work seamlessly with Core Utilities:

import { getMappingValue, anonymizeIP } from '@walkeros/core';
import { sendServer, getHashServer } from '@walkeros/server-core';

async function processServerSideEvent(rawEvent, clientIP) {
  // Use core utilities for data processing
  const processedData = await getMappingValue(rawEvent, mappingConfig);
  const safeIP = anonymizeIP(clientIP);

  // Use server utilities for transmission
  const sessionId = await getHashServer(`${safeIP}${userAgent}`, 16);

  return await sendServer(endpoint, {
    ...processedData,
    sessionId,
    ip: safeIP,
  });
}

For platform-agnostic utilities, see Core Utilities.

Contribute

Feel free to contribute by submitting an issue, starting a discussion, or getting in contact.

License

This project is licensed under the MIT License.