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

eb-patterns

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eb-patterns

JS library to test event bridge patterns synchronously

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

EventBridge TestEventPattern API - Local

This module provides a local, synchronous implementation of the AWS EventBridge testEventPattern API, allowing to test EventBridge event patterns without the need to hit AWS servers. It's designed to be quick, efficient, and easy to integrate.

Features

  • Local Pattern Testing: Test EventBridge patterns synchronously without requiring AWS API calls.
  • Easy Integration: Seamlessly integrates with existing Node.js applications.
  • Comprehensive Pattern Matching: Supports a wide range of pattern matching features including wildcard, nested field matching, and more.

Installation

npm install eb-patterns

Usage

import { testEventPattern } from 'eb-patterns';

const event = { /* your AWS event JSON string */ };
const pattern = { /* your AWS eventPattern JSON string */ };

/* 
  behaves same like AWS` testEventPattern method
  https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EventBridge.html#testEventPattern-property
*/
const result = testEventPattern({ Event: event, EventPattern: pattern });

console.log(result); // true or false based on pattern matching
import { testPattern } from 'eb-patterns';

const data = { contact: { name: 'John', age: 30, nationality: 'DE' } };
const pattern = { contact: { name: ['John'], age: [{ numeric: ['>=', 25] } };

// test any patterns
const result = testPattern(data, pattern);

console.log(result); // true or false based on pattern matching

API Reference

testEventPattern(params)

  • params: An object that contains the parameters for testEventPattern.
  • params.Event: This should resemble an EventBridge event's format. It's a JSON string representing a valid object and must include these properties: id, detail-type, source, account, time, region, detail.
  • params.EventPattern: A JSON string that represents a valid JSON object. It must contain all of the following properties: detail

testPattern(data, pattern)

  • data: The data object to test.
  • pattern: The pattern object against which the event is tested.

Returns true if the event matches the pattern, false otherwise.

Available Patterns

ComparisonExampleRule syntax
Nullfirst_name is null"first_name": [ null ]
Emptylast_name is empty"last_name": [""]
Equalsemail is "j.doe@email.com""email": [ "j.doe@email.com" ]
Equals (ignore case)first_name is "John""first_name": [ { "equals-ignore-case": "john" } ]
Andfist_name is "John" and last_name is "Doe""first_name": [ "John" ], "last_name": ["Doe"]
Orpayment_type is "Invoice" or "SEPA""payment_type": [ "invoice", "sepa"]
Or (multiple fields)first_name is "John", or last_name is "Doe"."$or": [ { "first_name": [ "John" ] }, { "last_name": [ "Doe" ] } ]
Notstatus is anything but "cancelled""status": [ { "anything-but": [ "cancelled" ] } ]
Numeric (equals)price is 100"price": [ { "numeric": [ "=", 100 ] } ]
Numeric (range)price is more than 10, and less than or equal to 20"price": [ { "numeric": [ ">", 10, "<=", 20 ] } ]
Existsproduct_name exists"product_name": [ { "exists": true } ]
Does not existproduct_name does not exist"product_name": [ { "exists": false } ]
Begins withproduct_name starts with PRO-"product_name": [ { "prefix": "PRO-" } ]
Ends withfilename ends with a .png extension"filename": [ { "suffix": ".png" } ]
Wildcardsearch a string using a wildcard"email": [ { "wildcard": "*@doe.com" } ]
Wildcard in keywildcard in the pattern key"person.*.key": [ { "exists": true } ]

Keywords

FAQs

Package last updated on 08 Mar 2024

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