0.5.4 • Published 1 month ago

@mojaloop/participants-bc-client-lib v0.5.4

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 month ago

Mojaloop vNext Participants Client Library

Git Commit Git Releases Npm Version NPM Vulnerabilities CircleCI

This is a readonly HTTP client library for the Participants bounded context.

It allows for the following readonly operations:

  • getAllParticipants: get all registered participants.
  • getParticipantsByIds: get multiple participants whose ids match the provided array of Ids.
  • getParticipantById: get a single participant by its Id.
  • getParticipantAccountsById: get the account list of a participant by its Id (This is the only call that includes balances - fetched from the Accounts and Balances Services by the Participants Service).

NOTE: This client requires an instance of a IAuthenticatedHttpRequester with adequate credentials from the Authentication BC to be passed in the constructor

Install

npm install @mojaloop/participants-bc-client-lib

Usage

Configure

"use strict";

import {ILogger, ConsoleLogger} from "@mojaloop/logging-bc-public-types-lib";
import {
	AuthenticatedHttpRequester,
	IAuthenticatedHttpRequester
} from "@mojaloop/security-bc-client-lib";
import {
    AccountsAndBalancesClient,
    IAccountDTO,
    IJournalEntryDTO
} from "@mojaloop/participants-bc-client-lib";

const logger: ILogger = new ConsoleLogger();

// IAuthenticatedHttpRequester consts
const AUTH_TOKEN_ENPOINT = "http://localhost:3201/token";
const USERNAME = "user";                // only needed for user logins (password grant)
const PASSWORD = "superPass";           // only needed for user logins (password grant)
const CLIENT_ID = "security-bc-ui";     // always required
const CLIENT_SECRET = "client_secret";  // only needed for app logins (client_credentials grant)

// create the instance of IAuthenticatedHttpRequester
const authRequester = new AuthenticatedHttpRequester(logger, AUTH_TOKEN_ENPOINT);

// set user credentials example (password grant)
authRequester.setUserCredentials(CLIENT_ID, USERNAME, PASSWORD);

// set app credentials example (client_credentials grant)
// authRequester.setAppCredentials(CLIENT_ID, CLIENT_SECRET);

// ParticipantsHttpClient constants
const PARTICIPANTS_BASE_URL: string = "http://localhost:3010";
const HTTP_CLIENT_TIMEOUT_MS: number = 10_000;

const participantsClient = new ParticipantsHttpClient(logger, PARTICIPANTS_BASE_URL, authRequester);

await participantsClient.getAllParticipants().then(value => {
	console.log(value);
}).catch(reason => {
	if(reason instanceof UnauthorizedError){
		console.log("Invalid credentials");
	}else if(reason instanceof ConnectionRefusedError){
		console.log("Cannot connect to destination endpoint");
	}else if(reason instanceof RequestTimeoutError) {
		console.log("Timeout while waiting for request to finish");
	}else if(reason instanceof MaxRetriesReachedError) {
		console.log("Request max retries reached, giving up");
	}else {
		console.error(reason);
	}
});

See Also

0.5.4

1 month ago

0.5.3

2 months ago

0.5.2

5 months ago

0.3.5

5 months ago

0.5.1

5 months ago

0.1.14

8 months ago

0.1.15

7 months ago

0.3.2

6 months ago

0.3.1

6 months ago

0.3.4

6 months ago

0.3.3

6 months ago

0.1.13

10 months ago

0.1.10

10 months ago

0.1.11

10 months ago

0.1.12

10 months ago

0.1.8

11 months ago

0.1.7

11 months ago

0.1.9

10 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.6

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago