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

@elastic.io/oih-standard-library

Package Overview
Dependencies
Maintainers
17
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elastic.io/oih-standard-library

Library for OIH standards implementation

  • 1.0.0-rc7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
decreased by-5.56%
Maintainers
17
Weekly downloads
 
Created
Source

CircleCI

OIH Standard Library

Table of Contents

Actions

Upsert Object

Lookup Object (at most 1)

Lookup Objects (Plural)

Delete Object

For implementing Delete action in most cases you need to extend from DeleteById or DeleteByUniqueCriteria classes. If you need completely custom behaviour you can extend from Delete class and override process and deleteObject method, in this case following OIH standard is your responsibility.

Delete By ID

Note:

  • Its your responsibility to ensure that deleteObject deletes only 1 object. This implementation assume that id is unique for objectType.
  • If deleteObject method is returning null empty object would be emitted. You can indicate with null that object hasn`t been deleted or found.
  1. Create Action
  2. Create class that extends DeleteById class
  3. Override deleteObject() methods. Example below.
  4. Optional override getType and getId methods. Default implementation expects objectType to be present in input configuration and id in input message.
  5. Create instance of your class and pass logger to constructor. const myDeleteByIDImpl = new MyDeleteByIdImpl(logger);
  6. Export myDeleteByIDImpl.process(msg, cfg, snapshot) as process method. Example below.
Example of Usage

Works in sailor > 2.4.2 Delete Action

const { DeleteById } = require('@elastic.io/oih-standard-library/lib/actions/delete');

class MyDeleteByIDImpl extends DeleteById {


  async deleteObject(id, cfg, msg) { // In most cases you need just id, type and cfg
    const deletedID = await deleteObjectInAPI(id, cfg, msg); // Delete object
    return deletedID; // Return deleted object ID. If you return null, empty object would be emitted.
  }
  // You can also override getType and getId methods if needed
}
   

async function process(msg, cfg, snapshot = {}) {
  const deleteAction = new MyDeleteByIDImpl(this.logger); // Sailor version > 2.4.2
  return deleteAction.process(msg, cfg, snapshot);
}

module.exports.process = process;
Delete By Unique Criteria

Note:

  • If more than 1 object was found with same uniqueCriteria, error would be thrown by this implementation
  • If deleteObject method is returning null empty object would be emitted. You can indicate with null that object hasn`t been deleted or found.
  1. Create Action
  2. Create class that extends DeleteById class
  3. Override findObjectByCriteria and deleteObject() methods. Example below.
  4. Optional override getType and getCriteria methods. Default implementation expects objectType to be present in input configuration. For unique criteria: uniqueCriteria field name in input configuration and value in input message.
  5. Create instance of your class and pass logger to constructor. const myDeleteByCriteriaImpl = new MyDeleteByCriteriaImpl(logger);
  6. Export myDeleteByCriteriaImpl.process(msg, cfg, snapshot) as process method. Example below.
Example of Usage

Works in sailor > 2.4.2 Delete Action

const { DeleteByUniqueCriteria } = require('@elastic.io/oih-standard-library/lib/actions/delete');

class MyDeleteByCriteriaImpl extends DeleteByUniqueCriteria {

  async findObjectByUniqueCriteria(criteria, type, cfg, msg) { // In most cases you need just criteria, type and cfg
     // criteria sructure {
     //  uniqueCriteria: 'fieldName',
     //  value: 'fieldValue', 
     // }
     const object =  await findObjectInAPI(criteria, type, cfg, msg); // objects that match this criteria
     const numberOfObjects =  object.count; // You do not need to check or throw error in this case, action implementation will do this
     return { // return structure must contain object and numberOfObjects found
       object,
       numberOfObjects
     }
  }
  async deleteObject(object, cfg, msg) { // In most cases you need just object, type and cfg
    const deletedID = await deleteObjectInAPI(object, cfg, msg); // Delete object
    return deletedID; // Return deleted object ID if you return null, empty object would be emitted.
  }
  // You can also override getType and getId methods if needed
}
   

async function process(msg, cfg, snapshot = {}) {
  const deleteAction = new MyDeleteByCriteriaImpl(this.logger); // Sailor version > 2.4.2
  return deleteAction.process(msg, cfg, snapshot);
}

module.exports.process = process;

Triggers

Get New and Updated Objects Polling

Webhooks

Keywords

FAQs

Package last updated on 31 Oct 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