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

@mwalek/expo-wp-notifications

v1.0.0

Published

Client SDK for Expo WP Notifications WordPress plugin

Downloads

122

Readme

Expo WP Notifications Client SDK

A lightweight TypeScript client for integrating React Native / Expo apps with the Expo WP Notifications WordPress plugin.

Features

  • Zero runtime dependencies
  • Full TypeScript support
  • Automatic heartbeat scheduling
  • Persistent registration state
  • Configurable retry logic
  • Works with Expo and bare React Native

Installation

npm install @mwalek/expo-wp-notifications
# or
yarn add @mwalek/expo-wp-notifications

Quick Start

import { ExpoWPNotifications, createAsyncStorageAdapter } from '@mwalek/expo-wp-notifications';
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Notifications from 'expo-notifications';
import * as Device from 'expo-device';

// Initialize client
const ewpn = new ExpoWPNotifications({
  baseUrl: 'https://yoursite.com',
  storage: createAsyncStorageAdapter(AsyncStorage),
  autoHeartbeat: true, // Send heartbeat every 24h
  debug: __DEV__,
});

// Register for push notifications
async function registerForPushNotifications(userId?: number) {
  // Get Expo push token
  const { data: pushToken } = await Notifications.getExpoPushTokenAsync();

  // Register with WordPress
  const result = await ewpn.register({
    pushToken,
    deviceId: Device.deviceId ?? 'unknown',
    platform: Device.osName?.toLowerCase() as 'ios' | 'android',
    userId,
  });

  if (result.success) {
    console.log('Registered successfully:', result.data.token_id);
  } else {
    console.error('Registration failed:', result.error.message);
  }
}

// Logout (unregister token)
async function logout() {
  await ewpn.unregister();
}

API Reference

new ExpoWPNotifications(config)

Create a new client instance.

const ewpn = new ExpoWPNotifications({
  // Required
  baseUrl: 'https://yoursite.com',

  // Optional
  namespace: 'ewpn/v1',           // REST API namespace
  autoHeartbeat: false,            // Enable automatic heartbeat
  heartbeatInterval: 86400000,     // Heartbeat interval (24h default)
  storage: new MemoryStorage(),    // Storage adapter
  timeout: 30000,                  // Request timeout (30s)
  retries: 3,                      // Retry attempts
  headers: {},                     // Custom headers
  debug: false,                    // Enable debug logging
});

ewpn.register(data)

Register a push token with WordPress.

const result = await ewpn.register({
  pushToken: 'ExponentPushToken[xxx]',
  deviceId: 'unique-device-id',
  platform: 'ios', // 'ios' | 'android' | 'web'
  userId: 123,     // Optional: WordPress user ID
  appId: 'com.example.app', // Optional
  metadata: {},    // Optional: custom data
});

if (result.success) {
  console.log('Token ID:', result.data.token_id);
} else {
  console.error('Error:', result.error.message);
}

ewpn.heartbeat()

Send a heartbeat to confirm the token is still active.

const result = await ewpn.heartbeat();

ewpn.unregister()

Unregister the current device token.

const result = await ewpn.unregister();

ewpn.isRegistered()

Check if the device is registered.

const registered = await ewpn.isRegistered();

ewpn.getRegistrationState()

Get the current registration state.

const state = await ewpn.getRegistrationState();
// { deviceId, pushToken, tokenId, userId, registeredAt }

ewpn.updateUserId(userId)

Update the user ID for the current registration (e.g., after login).

await ewpn.updateUserId(123);

ewpn.startAutoHeartbeat() / ewpn.stopAutoHeartbeat()

Manually control automatic heartbeat.

ewpn.startAutoHeartbeat();
ewpn.stopAutoHeartbeat();

ewpn.destroy()

Cleanup resources (stops heartbeat timer).

ewpn.destroy();

Storage Adapters

AsyncStorage (React Native)

import AsyncStorage from '@react-native-async-storage/async-storage';
import { createAsyncStorageAdapter } from '@mwalek/expo-wp-notifications';

const ewpn = new ExpoWPNotifications({
  baseUrl: 'https://yoursite.com',
  storage: createAsyncStorageAdapter(AsyncStorage),
});

Custom Storage

import type { StorageAdapter } from '@mwalek/expo-wp-notifications';

const customStorage: StorageAdapter = {
  getItem: async (key) => { /* ... */ },
  setItem: async (key, value) => { /* ... */ },
  removeItem: async (key) => { /* ... */ },
};

Complete Example

import { useEffect, useState } from 'react';
import { ExpoWPNotifications, createAsyncStorageAdapter } from '@mwalek/expo-wp-notifications';
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Notifications from 'expo-notifications';
import * as Device from 'expo-device';

// Create singleton instance
export const ewpn = new ExpoWPNotifications({
  baseUrl: 'https://twala.shop',
  storage: createAsyncStorageAdapter(AsyncStorage),
  autoHeartbeat: true,
  debug: __DEV__,
});

// Hook for notification setup
export function useNotifications(userId?: number) {
  const [isRegistered, setIsRegistered] = useState(false);

  useEffect(() => {
    async function setup() {
      // Request permissions
      const { status } = await Notifications.requestPermissionsAsync();
      if (status !== 'granted') return;

      // Get push token
      const { data: pushToken } = await Notifications.getExpoPushTokenAsync();

      // Register with WordPress
      const result = await ewpn.register({
        pushToken,
        deviceId: Device.deviceId ?? `device-${Date.now()}`,
        platform: Device.osName?.toLowerCase() as 'ios' | 'android',
        userId,
      });

      setIsRegistered(result.success);
    }

    setup();

    return () => {
      ewpn.destroy();
    };
  }, [userId]);

  return { isRegistered };
}

// Logout function
export async function logout() {
  await ewpn.unregister();
  // ... other logout logic
}

Error Handling

All methods return a Result type:

type Result<T> =
  | { success: true; data: T }
  | { success: false; error: { code: string; message: string } };

Common error codes:

  • not_registered - No token registered (call register first)
  • invalid_token - Push token format is invalid
  • network_error - Network request failed
  • timeout - Request timed out
  • api_error - Server returned an error

License

MIT