1.1.1 • Published 9 months ago

c2p-commons v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

c2p-commons

Overview

c2p-commons is a utility package that provides a collection of modules and utilities to facilitate various operations within your application. This package includes functionalities for event bus operations, Firestore interactions, date and time utilities, mathematical calculations, JSON Web Signature handling, custom error handling, and logging.

Installation

To install the c2p-commons package, use npm:

npm install c2p-commons

Usage

To use the modules and utilities provided by c2p-commons, import them into your project as needed. Below are examples of how to import and use some of the key components.

Example

import { AzureEventBus, GoogleFirestore, DateTimeUtils, AntecipationContractCalc, CalculateOperation, CipJwsSignature, NotFoundError, Logger } from 'c2p-commons';

// Using AzureEventBus
const eventBus = new AzureEventBus();
eventBus.publish('eventName', { data: 'eventData' });

// Using GoogleFirestore
const firestore = new GoogleFirestore();
firestore.getDocument('collectionName', 'documentId');

// Using DateTimeUtils
const currentDate = DateTimeUtils.getCurrentDate();
console.log(currentDate);

// Using AntecipationContractCalc
const calcResult = AntecipationContractCalc.calculate({ amount: 1000, rate: 0.05 });
console.log(calcResult);

// Using CalculateOperation
const sum = CalculateOperation.add(5, 10);
console.log(sum);


// Using Logger
Logger.info('This is an info message');
Logger.error('This is an error message');

Modules and Utilities

AzureEventBus

  • Path: ./bus/azure
  • Description: Handles event bus operations for Azure.

GoogleFirestore

  • Path: ./firestore/googleFirestore
  • Description: Manages interactions with Google Firestore.

DateTimeUtils

  • Path: ./utils/DateTimeUtils
  • Description: Provides utility functions for date and time operations.

AntecipationContractCalc

  • Path: ./math/AntecipationContractCalc
  • Description: Performs calculations related to anticipation contracts.

CalculateOperation

  • Path: ./math/CalculateOperation
  • Description: General mathematical operations and calculations.

CipJwsSignature

  • Path: ./utils/CipJwsSignature
  • Description: Handles JWS (JSON Web Signature) operations.

NotFoundError

  • Path: ./exceptions/NotFoundError
  • Description: Custom error class for handling "Not Found" errors.

Logger

  • Path: ./logger
  • Description: Logging utility for the application.

Contributing

Contributions are welcome! Please open an issue or submit a pull request with your changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For any questions or inquiries, please contact the project maintainers.

Usage

require('dotenv').config();

import {
  BufferEnvPresenter,
  EnvBootstrap,
  Environment,
  NumberEnvPresenter,
  TextEnvPresenter,
} from '@heronlabs/presenter-env';

import {Module, Inject} from '@nestjs/common';

export class Configuration {
  public server = {
    port: this.numberEnvPresenter.getValueByKey('API_PORT'),
  };

  public jwt = {
    publicKey: this.bufferEnvPresenter.getValueByKey('JWT_PUBLIC_KEY_PATH'),
    algorithm: this.textEnvPresenter.getValueByKey('JWT_ALGORITHM'),
  };

  constructor(
    @Inject(NumberEnvPresenter) private numberEnvPresenter: Environment<number>,
    @Inject(BufferEnvPresenter) private bufferEnvPresenter: Environment<Buffer>,
    @Inject(TextEnvPresenter) private textEnvPresenter: Environment<string>
  ) {}
}

@Module({
  providers: [Configuration],
  imports: [EnvBootstrap],
})
export class ApiBootstrap {}
1.1.1

9 months ago

1.1.0

9 months ago

1.0.33

10 months ago

1.0.32

10 months ago

1.0.31

10 months ago

1.0.36

10 months ago

1.0.35

10 months ago

1.0.34

10 months ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.11

3 years ago

1.0.30

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago