@ikonintegration/ikapi

4.0.0-alpha19 • Public • Published

IKApi Node.js Package

Ikon nodejs API foundation

Overall

  • npm npm npm (tag) Libraries.io dependency status for latest release, scoped npm package
  • GitHub commit activity
  • GitHub last commit

Samples

  • Router
import * as Config from './routes/tenant/config.js';

const routes = [
  { route: '/tenant/config', method: 'GET', handler: Config.get },
];
//Main handler
export const handler = async (event, context) => {
  (await (new IKAPI.IKRouter(routes, {
    database: {
      type: 'DDB | SQL', -- fallback to DDB if not set
      //DDB Specific
      region: IBEWCoreGlobals.DatabaseRegion,
      tableName: IBEWCoreGlobals.DatabaseTableName,
      //SQL Specific
      host: '127.0.0.1', database: 'DB',
      port: 3307, user: 'root', password: 'IDK'
    },
    //Cache
    cache: {
      type: 'REDIS',
      host: '127.0.0.1',
      password: '22P',
      user: '22U',
      enableTLS: true,
    },
    //IKValidator
    validation: {
      additionalTypes: { TYPE: (val) => { return validate(val); } }
    },
    //Logger
    logger: {
      //takes precende over process.env.LOG_LEVEL
      level: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR',
      enableSensitiveFiltering: false, //defaults to false
      sensitiveFilteringKeywords: [], //replaced default blacklist set
    },
    //Queue
    publisher: { region: 'SNS-REGION' },
    //Resources tracker
    resourcesTracker: { //by default, it will auto track (lambda, ecs, ddb)
      busName: 'busName',
      region: 'region',
      appName: 'appName',
    }
  };)).handleEvent(event, context));
}
```

- Mailer

```
const mailer = new IKAPI.IKMailer(LMCoreGlobals.SESSender, LMCoreGlobals.SESRegion);
```

- Process

```
export const main = async () => {
  const interval = (Docket.Globals.ExtractorPollerInterval * 1000);
  console.debug('Using interval of', interval);
  //init authorization
  await (new Docket.Core({},  Docket.Globals.AccessLevel.ANY)).authenticate(async (core) => {
    await (new IKAPI.IKProcess(Docket.Globals.API_Config, interval)).execute( async (process) => {
      await pull(core);
    });
  });
};
```

- Event Process (Queue/SQS)

```
//Main handler
export const handler = async (event, context) => {
  //Start event processor, if any event failed, execution will stop!
  await (new IKAPI.IKEventProcessor(event, context, Docket.Globals.API_Config)).processEvent( async (transaction, recordContent) => {
    //init authorization
    return await (new Docket.Core(transaction,  Docket.Globals.AccessLevel.ANY)).authenticate(async (core) => {
      core.queue.publishOnTopic(event, Docket.Globals.SNSTopic_ExtractorNotification);
      return IKAPI.IKSuccessResponse();
    });
  });
};
```

- Transaction

```
//Main handler
export const handler = async (event, context) => {
  //Start event processor, if any event failed, execution will stop!
  await (new IKAPI.IKTransaction(event, context, Docket.Globals.API_Config)).execute( async (transaction) => {
    //init authorization
    return await (new Docket.Core(transaction,  Docket.Globals.AccessLevel.ANY)).authenticate(async (core) => {
      const queue = event.queue;
      //Get from specified queue
      if (!queue) throw new Error(`Empty queue URL! - ${queue}`);
      //Success :)
      return IKAPI.IKSuccessResponse();
    });
  });
};
```

- Dynamo Streams

```
//Main handler
export const handler = async (event, context) => {
  //Start event processor, if any event failed, execution will stop!
  await (new IKAPI.IKDynamoStream(event, context, Docket.Globals.API_Config)).processEvent( async (transaction, recordContent) => {
    //Check if is deletion
    if (!_isDynamoDeletion(recordContent)) return (new IKAPI.IKSuccessNoContentResponse());
    //init authorization
    return await (new Docket.Core(transaction,  Docket.Globals.AccessLevel.ANY)).authenticate(async (core) => {
      return IKAPI.IKSuccessResponse();
    });
  });
};
```

Readme

Keywords

none

Package Sidebar

Install

npm i @ikonintegration/ikapi

Weekly Downloads

138

Version

4.0.0-alpha19

License

ISC

Unpacked Size

99.3 kB

Total Files

37

Last publish

Collaborators

  • vitor-ikon
  • mateus.ikon
  • gwdebes
  • rescio