npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mojaloop/accounts-and-balances-bc-grpc-client-lib

v0.6.2

Published

Accounts and Balances BC - gRPC Client Library

Downloads

59

Readme

Accounts and Balances gRPC Client Library

Git Commit Git Releases Npm Version NPM Vulnerabilities CircleCI

This is the gRPC client library for the Accounts and Balances bounded context.
It allows for the following operations:

  • Create account: create a single account.
  • Create journal entries: create 1 or more journal entries.
  • Get account by id: get an account by id.
  • Get accounts by external id: get all the accounts with a specific external id.
  • Get journal entries by account id: get all the journal entries with a specific account id - either the debited account id or the credited account id.

Install

$ npm install @mojaloop/accounts-and-balances-bc-grpc-client-lib @mojaloop/logging-bc-client-lib

Usage

Configure and Initialize

import {ILogger} from "@mojaloop/logging-bc-public-types-lib";
import {DefaultLogger} from "@mojaloop/logging-bc-client-lib";
import {GrpcClient} from "@mojaloop/accounts-and-balances-bc-grpc-client-lib";

const BOUNDED_CONTEXT_NAME: string = "some-bc";
const SERVICE_NAME: string = "some-svc";
const SERVICE_VERSION: string = "0.0.1";
const ACCOUNTS_AND_BALANCES_GRPC_SERVICE_HOST: string = "localhost";
const ACCOUNTS_AND_BALANCES_GRPC_SERVICE_PORT_NO: number = 5678;
const ACCOUNTS_AND_BALANCES_GRPC_CLIENT_TIMEOUT_MS: number = 5000;

const logger: ILogger = new DefaultLogger(BOUNDED_CONTEXT_NAME, SERVICE_NAME, SERVICE_VERSION);

const grpcClient: GrpcClient = new GrpcClient(
    logger,
    ACCOUNTS_AND_BALANCES_GRPC_SERVICE_HOST,
    ACCOUNTS_AND_BALANCES_GRPC_SERVICE_PORT_NO,
    ACCOUNTS_AND_BALANCES_GRPC_CLIENT_TIMEOUT_MS
);

await grpcClient.init();

Destroy

await grpcClient.destroy();

Create Account

const accountDto: IAccountDto = {
    id: null,
    externalId: null,
    state: AccountState.ACTIVE,
    type: AccountType.POSITION,
    currencyCode: "EUR",
    currencyDecimals: null,
    debitBalance: "0",
    creditBalance: "0",
    timestampLastJournalEntry: null
};

try {
    const accountId: string = await grpcClient.createAccount(accountDto);
} catch (error: unknown) {
    logger.error(error);
}

Create Journal Entries

// Before creating a journal entry, the respective accounts need to be created.

// Account A.
const accountDtoA: IAccountDto = {
    id: null,
    externalId: null,
    state: AccountState.ACTIVE,
    type: AccountType.POSITION,
    currencyCode: "EUR",
    currencyDecimals: null,
    debitBalance: "0",
    creditBalance: "0",
    timestampLastJournalEntry: null
};
const idAccountA: string = await grpcClient.createAccount(accountDtoA);

// Account B.
const accountDtoB: IAccountDto = {
    id: null,
    externalId: null,
    state: AccountState.ACTIVE,
    type: AccountType.POSITION,
    currencyCode: "EUR",
    currencyDecimals: null,
    debitBalance: "0",
    creditBalance: "0",
    timestampLastJournalEntry: null
};
const idAccountB: string = await grpcClient.createAccount(accountDtoB);

// TODO: credit accounts A and B with an hub account.

// Journal entry A.
const journalEntryDtoA: IJournalEntryDto = {
    id: null,
    externalId: null,
    externalCategory: null,
    currencyCode: "EUR",
    currencyDecimals: null,
    amount: "5",
    debitedAccountId: idAccountA,
    creditedAccountId: idAccountB,
    timestamp: null
};

// Journal entry B.
const journalEntryDtoB: IJournalEntryDto = {
    id: null,
    externalId: null,
    externalCategory: null,
    currencyCode: "EUR",
    currencyDecimals: null,
    amount: "5",
    debitedAccountId: idAccountB,
    creditedAccountId: idAccountA,
    timestamp: null
};

try {
    const idsJournalEntries: string[] = await grpcClient.createJournalEntries([journalEntryDtoA, journalEntryDtoB]);
} catch (error: unknown) {
    logger.error(error);
}

Get Account by Id

const accountId: string = "a";

try {
    const accountDto: IAccountDto | null = await grpcClient.getAccountById(accountId);
} catch (error: unknown) {
    logger.error(error);
}

Get Accounts by External Id

const externalId: string = "a";

try {
    const accountDtos: IAccountDto[] = await grpcClient.getAccountsByExternalId(externalId);
} catch (error: unknown) {
    logger.error(error);
}

Get Journal Entries by Account Id

const accountId: string = "a";

try {
    const journalEntryDtos: IJournalEntryDto[] = await grpcClient.getJournalEntriesByAccountId(accountId);
} catch (error: unknown) {
    logger.error(error);
}

See Also