simple-rule-notification
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Simple Rule Notification

Interpret some simples rules in json to generate notifications

About The Project

A way for persist some configurable rules for use in some data in frontend.

Usage

Install the package from npm:

npm i simple-rule-notification

Import the package:

const srn = require("simple-rule-notification");

Retrieve the following rules from backend:

const operacaoGrupo = {
    id: 1,
    acaoEnum: "CRIAR_REGISTRO_ATIVIDADE_NOTIFICACAO",
    operacaoRaiz: {
        id: 2,
        nomeCampo: "ocorrencia",
        comparadorEnum: "IGUAL",
        valor: "valor_esperado",
        proximaOperacao: null,
        operadorProximaOperacao: null,
    },
    tituloPadrao: "Ocorrência no Campo",
    mensagemPadrao: "O campo ocorrência foi preenchido.",
    tipoMensagem: "INFO",
    quantidadeDiasEntreDatasChave: null,
    respostasPadrao: null,
};

Then build a strategy and execute it, passing the data:

const data = {
    respostas: {
        ocorrencia: "valor_esperado",
    },
};
const applicableRule = srn.buildAcaoStrategy(operacaoGrupo, data).executar();

In this case the return will be:

{ "tipo": "CRIAR_REGISTRO_ATIVIDADE_NOTIFICACAO" }

If the entry has the following value:

const data = {
    respostas: {
        ocorrencia: "valor_nao_esperado",
    },
};

The return will be:

null;

Unit tests - Jest

npm test
--------------|---------|----------|---------|---------|-------------------
File          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|-------------------
All files     |     100 |      100 |     100 |     100 |
 functions.ts |     100 |      100 |     100 |     100 |
 index.ts     |     100 |      100 |     100 |     100 |
--------------|---------|----------|---------|---------|-------------------

Mutation Test - Striker

npx stryker run

Package Sidebar

Install

npm i simple-rule-notification

Weekly Downloads

4

Version

1.0.1

License

ISC

Unpacked Size

8.75 kB

Total Files

8

Last publish

Collaborators

  • gleytonclima