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

moonmail-js-sdk

v1.0.20

Published

MoonMail JS SDK

Readme

MoonMail JS SDK

Install

npm i moonmail-js-sdk --save

or

yarn add moonmail-js-sdk

or load from CDN

https://js.moonmail.io/sdk/latest/moonmail.umd.js

Intitialize

import {MoonMail} from 'moonmail-js-sdk';

const moonmail = new MoonMail({
  accountId: 'YOUR_ACCOUNT_ID',
  // OPTIONAL - Default Contact Information
  contact: {
    address: '[email protected]', // The unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.
    attributes: {
      // Custom attributes that your app reports to MoonMail. You can use these attributes as selection criteria when you create a segment.
      hobbies: ['piano', 'hiking'],
    },
    demographic: {
      appVersion: 'xxxxxxx', // The version of the application associated with the contact
      locale: 'xxxxxx', // The contact locale in the following format: The ISO 639-1 alpha-2 code, followed by an underscore, followed by an ISO 3166-1 alpha-2 value
      make: 'xxxxxx', // The manufacturer of the contact device, such as Apple or Samsung.
      model: 'xxxxxx', // The model name or number of the contact device, such as iPhone.
      modelVersion: 'xxxxxx', // The model version of the contact device.
      platform: 'xxxxxx', // The platform of the contact device, such as iOS or Android.
      platformVersion: 'xxxxxx', // The platform version of the contact device.
      timezone: 'xxxxxx', // The timezone of the contact. Specified as a tz database value, such as Americas/Los_Angeles.
    },
    location: {
      city: 'xxxxxx', // The city where the contact is located.
      country: 'xxxxxx', // The two-letter code for the country or region of the contact. Specified as an ISO 3166-1 alpha-2 code, such as "US" for the United States.
      latitude: 0, // The latitude of the contact location, rounded to one decimal place.
      longitude: 0, // The longitude of the contact location, rounded to one decimal place.
      postalCode: 'xxxxxx', // The postal code or zip code of the contact.
      region: 'xxxxxx', // The region of the contact location. For example, in the United States, this corresponds to a state.
    },
    metrics: {
      // Custom metrics that your app reports to MoonMail.
    },
    /** Indicates whether a user has opted out of receiving messages with one of the following values:
     * ALL - User has opted out of all messages.
     * NONE - Users has not opted out and receives all messages.
     */
    optOut: 'ALL',
    // Customized userId
    userId: 'XXXXXXXXXXXX',
    // User attributes
    userAttributes: {
      interests: ['football', 'basketball', 'AWS'],
      // ...
    },
  },
});

Update contact

moonmail
  .updateContact({
    address: '[email protected]', // The unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.
    attributes: {
      // Custom attributes that your app reports to MoonMail. You can use these attributes as selection criteria when you create a segment.
      hobbies: ['piano', 'hiking'],
    },
    demographic: {
      appVersion: 'xxxxxxx', // The version of the application associated with the contact
      locale: 'xxxxxx', // The contact locale in the following format: The ISO 639-1 alpha-2 code, followed by an underscore, followed by an ISO 3166-1 alpha-2 value
      make: 'xxxxxx', // The manufacturer of the contact device, such as Apple or Samsung.
      model: 'xxxxxx', // The model name or number of the contact device, such as iPhone.
      modelVersion: 'xxxxxx', // The model version of the contact device.
      platform: 'xxxxxx', // The platform of the contact device, such as iOS or Android.
      platformVersion: 'xxxxxx', // The platform version of the contact device.
      timezone: 'xxxxxx', // The timezone of the contact. Specified as a tz database value, such as Americas/Los_Angeles.
    },
    location: {
      city: 'xxxxxx', // The city where the contact is located.
      country: 'xxxxxx', // The two-letter code for the country or region of the contact. Specified as an ISO 3166-1 alpha-2 code, such as "US" for the United States.
      latitude: 0, // The latitude of the contact location, rounded to one decimal place.
      longitude: 0, // The longitude of the contact location, rounded to one decimal place.
      postalCode: 'xxxxxx', // The postal code or zip code of the contact.
      region: 'xxxxxx', // The region of the contact location. For example, in the United States, this corresponds to a state.
    },
    metrics: {
      // Custom metrics that your app reports to Amazon Pinpoint.
    },
    /** Indicates whether a user has opted out of receiving messages with one of the following values:
     * ALL - User has opted out of all messages.
     * NONE - Users has not opted out and receives all messages.
     */
    optOut: 'ALL',
    // Customized userId
    userId: 'XXXXXXXXXXXX',
    // User attributes
    userAttributes: {
      interests: ['football', 'basketball', 'AWS'],
      // ...
    },
  })
  .then(() => {});

Trigger event

Metric values must be a Number type such as a float or integer. Attribute values must have the type String or be an array of strings.

moonmail.triggerEvent('Customer.Purchase');

// With event attributes and metrics
moonmail.triggerEvent({
  eventType: 'Customer.Purchase',
  attributes: {category: 'VIP'},
  metrics: {amount: 1000}, //
});

// Multiple events
moonmail.triggerEvent(['Customer.NewOrder', 'Customer.Purchase']);

moonmail.triggerEvent([
  'Customer.NewOrder',
  {
    eventType: 'Customer.Purchase',
    attributes: {category: 'VIP'},
    metrics: {amount: 1000},
  },
]);

// Update contact attributes and metrics
moonmail.triggerEvent('Auth.OTP', {
  attributes: {OTP: '12345'},
  metrics: {logins: 3},
});

Change default contact

You can pass the same parameters to configure method as when you initialize MoonMail

This will override default contact

moonmail.configure({contact: {address: '[email protected]', attributes: {foo: 'bar'}}});

Troubleshoot

Need help? Contact MoonMail's Support team at: [email protected]