Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@input-output-hk/mailchimp-subscribe

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@input-output-hk/mailchimp-subscribe

i18n friendly mailchimp subscriber

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by500%
Maintainers
3
Weekly downloads
 
Created
Source

Mailchimp subscribe library

An internationalization friendly mailchimp subscribe library. Subscribe emails to your mailing lists.

Mailchimp Subscribe issues Fork Mailchimp Subscribe Mailchimp Subscribe stars Mailchimp Subscribe license CircleCI build Test coverage


Contents

  1. Features
  2. Install
  3. Finding mailchimp values
  4. Examples
  5. Contributing

Features

  • Error codes and success codes for i18n
  • Custom fields

Install

npm install --save @input-output-hk/mailchimp-subscribe

or

yarn add @input-output-hk/mailchimp-subscribe

Finding Mailchimp values

Finding the 'uID' value

Mailchimp audience sign up forms instructions Mailchimp audience embedded forms instructions Mailchimp audience embedded forms uid instructions

Finding the 'audienceID' value

Mailchimp audience sign up forms instructions Mailchimp audience name and defaults Mailchimp audience id instructions

Finding the 'listName' value

Mailchimp audience sign up forms instructions Mailchimp audience embedded forms instructions Mailchimp audience embedded forms uid instructions

Examples

Basic supporting localization

import subscribe, { SUCCESS_CODES, ERROR_CODES } from '@input-output-hk/mailchimp-subscribe'

async function submitForm (email) {
  try {
    const result = await subscribe({
      email,
      uID: 'XXXXXXXXX',
      audienceID: 'XXXXXXXXX',
      listName: 'XXXXXX.XXXX'
    })

    const successCode = result.getCode()
    switch (successCode) {
      case SUCCESS_CODES.CONFIRM_EMAIL_ADDRESS:
        // Successfully subscribed, user needs to confirm email
        return '' // Use the code to return a localized string message
      case SUCCESS_CODES.GENERIC:
        // Successfully subscribed, default code
        return '' // Use the code to return a localized string message
    }
  } catch (error) {
    // Original message returned from mailchimp
    const message = error.message
    const errorCode = error.getCode()

    switch (successCode) {
      case ERROR_CODES.INVALID_EMAIL:
        // Email invalid
        return '' // Use the code to return a localized string message

      case ERROR_CODES.INVALID_EMAIL_DOMAIN:
        // Domain section of email invalid
        return '' // Use the code to return a localized string message

      case ERROR_CODES.INVALID_EMAIL_USERNAME:
        // Username section of email invalid
        return '' // Use the code to return a localized string message

      case ERROR_CODES.EMAIL_ALREADY_SUBSCRIBED:
        // Email is already subscribed to mailing list
        // Additional context is available here
        // Link to manage the subscription for the email address
        const manageSubscriptionLink = error.getContext().manageSubscriptionLink
        return '' // Use the code to return a localized string message

      case ERROR_CODES.TIMEOUT:
        // Request timed out
        return '' // Use the code to return a localized string message

      case ERROR_CODES.GENERIC:
        // Generic error code, server errors etc.
        return '' // Use the code to return a localized string message
    }
  }
}

Basic without localization

import subscribe from '@input-output-hk/mailchimp-subscribe'

async function submitForm (email) {
  try {
    await subscribe({
      email,
      uID: 'XXXXXXXXX',
      audienceID: 'XXXXXXXXX',
      listName: 'XXXXXX.XXXX'
    })

    return true
  } catch (error) {
    // handle error
    // error.message is the message returned from Mailchimp if the error originated on mailchimp
    return false
  }
}

Custom fields

import subscribe from '@input-output-hk/mailchimp-subscribe'

async function submitForm (email) {
  try {
    await subscribe({
      email,
      uID: 'XXXXXXXXX',
      audienceID: 'XXXXXXXXX',
      listName: 'XXXXXX.XXXX',
      customFields: {
        MY_FIELD: 'value',
        MY_SECOND_FIELD: 'value_2'
      }
    })

    return true
  } catch (error) {
    // handle error
    // error.message is the message returned from Mailchimp if the error originated on mailchimp
    return false
  }
}

Specifiying a timeout

import subscribe from '@input-output-hk/mailchimp-subscribe'

async function submitForm (email) {
  try {
    await subscribe({
      email,
      uID: 'XXXXXXXXX',
      audienceID: 'XXXXXXXXX',
      listName: 'XXXXXX.XXXX',
      // 6000ms
      timeout: 6000
    })

    return true
  } catch (error) {
    // handle error
    // error.message is the message returned from Mailchimp if the error originated on mailchimp
    return false
  }
}

Contributing

Contributions are welcome, see contributing for more info.

Keywords

FAQs

Package last updated on 03 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc