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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@baumdigital/notification-helper

v1.2.4

Published

Este modulo se encarga de todo lo relacionado a notificaciones push y pinpoint en nodejs.

Downloads

5

Readme

@baumdigital/notification-helper

Este modulo se encarga de todo lo relacionado a notificaciones push y pinpoint en nodejs. #Testing Correr "npm test" para generar reporte de test, se generara una carpeta llamada mochawesome-report, en la cual habra un .html con el reporte del test. Reivsar el reporte del test para ejemplo de utilizacion.

    npm test

Uso

##Funcionalidad

const moment = require("moment");
const NotificationHelper = require("@baumdigital/notification-helper");
const notificationConfig = {
  pinpointAppId: "example-id-51321",
  defaultSegments: {
    // Si estos segmentes no existen los creara y saldran en consola.
    es: {
      idSegment: "exampleidSegmentES",
      idIdioma: "es"
    },
    en: {
      idSegment: "exampleIdSegementEN"
    }
  }
};
const awsSDK = {
  roleArn: "example",
  accessKeyId: "example",
  secretAccessKey: "example",
  region: "example"
};
const options = {
  idiomas: ["es", "en"] // idiomas con los que trabajara el helper
};

const Notification = new NotificationHelper(
  notificationConfig,
  awsSDK,
  options
);

const userAttributes = {
  // userAttributes es un key value de atributos que queramos
  nombre: "Daniel",
  apellido: "Montealegre",
  email: "[email protected]",
  pais: "CR",
  telefono: "222222222",
  genero: "M"
};
// Crea un endpoint nuevo asociado con el id de usuario 1
Notification.UpdateEndpointInfo({
  idUsuario: "1",
  idDevice: "ascmasca-scasocasoc-ascoasca",
  platform: "android",
  idIdioma: "es",
  ifDelete: false,
  attributes: userAttributes
});
// Crea un endpoint nuevo de tipo guest
Notification.UpdateEndpointInfo({
  idDevice: "ascmasca-scasocasoc-ascoasca",
  platform: "android",
  idIdioma: "es",
  ifDelete: false
});
// Actualizada el idioma y los userAttributes de todos los endpoints asociados al id 1
Notification.UpdateUserEnpdointsInfo({
  idUsuario: "1",
  idIdioma: "es",
  attributes: userAttributes
});
const idDevice = "zxczxczxczxv";
const idUsuario = "1";
const tituloObj = {
  es: "titulo example",
  en: "Example title"
};
const mensajeObj = {
  es: "Mensaje de ejemplo",
  en: "Example message"
};
const payload = {
  // es un key value de strings, solo de un nivl de profundidad (no objetos dentro de objeto)
  origin: "example-1",
  idNotification: "1231-1423542"
};
const idIdioma = "es"; // idioma default a utilizar
//Envia un push directo a un idDevice(si no se da un idUsuario) o Se envia a todos los endpoints asociados al id de usuario. Si se envia idDevivce y idUsuario, se toma con mayor prioridad el idUsuario
Notification.enviarNotificationPersonal(
  idDevice,
  idUsuario,
  tituloObj,
  mensajeObj,
  payload,
  idIdioma
);

Notification.enviarEmail(
  ["[email protected]"],
  null,
  { charset: "UTF-8", data: "Test de envio" },
  { charset: "UTF-8", data: "<html> <html>" },
  "[email protected]",
  "[email protected]",
  "[email protected]"
);

const id = "asdasd"; // Un identificador con el que queramos reconocer nuestra campaña en pinpoint
const name = "nombre"; // nombre de la campaña que vamos a crear
const descripcion = "descripcion"; // Descripcion de la campaña que estamos creando
const programaObj = {
  // Es el schedule que va a tener la campaña
  fechaInicio: moment().add("2", "days"),
  fechaFin: moment().add("4", "days"),
  frecuencia: 3, //  1- Una vez 2- Cada Hora 3- Cada día 4- Cada semana 5- Cada mes
  horaInicioBloqueo: "12:00",
  horaFinBloqueo: "20:00"
};
const userAttributes = {
  // filtrar por atributos de usuaio
  nombre: ["daniel", "Juan"],
  genero: ["M"]
};
// Hace un envio masivo en pinpoint mediante campañas, crea una campaña para cada idioma configurado en el options
Notification.enviarNotificacionCampaigns(
  id,
  name,
  descripcion,
  programaObj,
  userAttributes,
  tituloObj,
  mensajeObj,
  payload
);
const idsCampaignPinpoint = [
  { idCampaniaPinpoint: "asdasdasd123", idIdioma: "es" },
  { idCampaniaPinpoint: "asdacvdgd", idIdioma: "en" }
];
// Actualiza campañas en pinpoint si estas aun estan activas o pendientes de envio
Notification.updateNotificacionCampaings({
  id,
  idsCampaignPinpoint,
  name,
  descripcion,
  programaObj,
  userAttributes,
  tituloObj,
  mensajeObj,
  payload
});
const state = "activate"; // 'activate','deactivate'
// Activa o desactiva campañas en pinpoint
Notification.updateCampaignState(idsCampaignPinpoint, state);
// Elimina campañas en pinpoint
Notification.deleteNotificacionCampaings(idsCampaignPinpoint);
// valida si se puede actualizar o no un array de campañas de pinpoin
Notification.validateUpdateCampaignsPinpoint(idsCampaignPinpoint);
// Trae el id de pinpoint del segmento default del idioma dado. Si no existe segmento default para ese idioma se crea uno nuevo y se actualiza la configuracion de la
// instancia de notification. El id es retornado, ya sea el de la configuracion o el creado
Notification.getDefaultSegmentId("es");