1.1.3 • Published 5 days ago
@ledgerswarm/ls_participant_sdk v1.1.3
Ledgerswarm Participant SDK
SDK for triggering actions on LS Participant
Prerequisites
This project requires NodeJS (developed on v18) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.
$ npm -v && node -v
6.4.1
v8.16.0
Table of contents
Getting Started
Set up a new nodejs project in your development environment and install the library as follows
$ npm install @ledgerswarm/ls_participant_sdk
Usage
const participant = require("ls_participant_sdk");
const UnAuthedPart = new participant("localhost");
let res = await UnAuthedPart.auth.authenticate("POST", {
userName: "username",
password: "password",
});
const Part = new participant("localhost", res.token);
/* ------------------------------------------------------------------------
//
// User Tests
//
-------------------------------------------------------------------------- */
console.log("[user.users - GET]");
res = await Part.user.user("GET", "admin");
console.log(res);
console.log("------------------");
console.log("[user.user - POST]");
res = await Part.user.user("POST", "username", {
username: "username",
password: "change-me",
isAdmin: false,
});
console.log(res);
console.log("------------------");
console.log("[user.user - PUT]");
res = await Part.user.user("PUT", "username", {
username: "username",
password: "change-me",
isAdmin: true,
});
console.log(res);
console.log("------------------");
console.log("[user.user - DELETE]");
res = await Part.user.user("DELETE", "username");
console.log(res);
console.log("------------------");
console.log("[user.password]");
res = await Part.user.password("username", { password: "password" });
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Account Tests
//
-------------------------------------------------------------------------- */
console.log("[account.accountIds]");
res = await Part.account.accountIds();
console.log(res);
console.log("------------------");
console.log("[account.assetIds]");
res = await Part.account.assetIds();
console.log(res);
console.log("------------------");
console.log("[account.accountAssetIds]");
res = await Part.account.accountAssetIds("Alice");
console.log(res);
console.log("------------------");
console.log("[account.accountAsset - GET]");
res = await Part.account.accountAsset("GET", "Alice", "EURO");
console.log(res);
console.log("------------------");
console.log("[account.accountAsset - PUT]");
res = await Part.account.accountAsset("GET", "Alice", "BP Shares");
console.log(res);
console.log("------------------");
console.log("[account.accountAsset - POST]");
res = await Part.account.accountAsset("POST", "Alice", "BP Shares", {
amount: 0,
isDelta: true,
reason: "reason",
});
console.log(res);
console.log("------------------");
console.log("[account.accountAsset - DELETE]");
res = await Part.account.accountAsset("DELETE", "Alice", "BP Shares");
console.log(res);
console.log("------------------");
console.log("[account.accountAssetPendingTransactions]");
res = await Part.account.accountAssetPendingTransactions("Alice", "EURO");
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Manifest Tests
//
-------------------------------------------------------------------------- */
console.log("[manifest.approveManifest]");
res = await Part.manifest.approveManifest(1);
console.log(res);
console.log("------------------");
console.log("[manifest.rejectManifest]");
res = await Part.manifest.rejectManifest(1);
console.log(res);
console.log("------------------");
console.log("[manifest.search]");
res = await Part.manifest.search({ swarmId: 1, scope: "ALL" });
console.log(res);
console.log("------------------");
console.log("[manifest.selectManifest]");
res = await Part.manifest.selectManifest(1);
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Auth Tests
//
-------------------------------------------------------------------------- */
console.log("[auth.authenticate]");
res = await UnAuthedPart.auth.authenticate("GET");
console.log(res);
console.log("------------------");
console.log("[auth.authenticate]");
res = await UnAuthedPart.auth.authenticate("POST", {
userName: "username",
password: "password",
});
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Transfer Tests
//
-------------------------------------------------------------------------- */
console.log("[transfer.transfers]");
res = await Part.transfer.transfers();
console.log(res);
console.log("------------------");
console.log("[transfer.search]");
res = await Part.transfer.search({ accountId: "Alice", scope: "ALL" });
console.log(res);
console.log("------------------");
console.log("[transfer.tag]");
res = await Part.transfer.tag(1, { tags: ["tag"] });
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Ping Tests
//
-------------------------------------------------------------------------- */
console.log("[ping.ping]");
res = await Part.ping.ping();
console.log(res);
console.log("------------------");
console.log("[ping.openPing]");
res = await Part.ping.openPing();
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Asset Tests
//
-------------------------------------------------------------------------- */
console.log("[asset.assets]");
res = await Part.asset.assets();
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Kafka Tests
//
-------------------------------------------------------------------------- */
console.log("[kafka.search]");
res = await Part.kafka.search({ swarmId: 1 });
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Rule Tests
//
-------------------------------------------------------------------------- */
console.log("[rule.rule - PUT]");
res = await Part.rule.rule({
id: 1,
name: "new rule",
priority: 0,
text: "description",
});
console.log(res);
console.log("------------------");
console.log("[rule.rule - GET]");
res = await Part.rule.rule();
console.log(res);
console.log("------------------");
console.log("[rule.delete]");
res = await Part.rule.delete(1);
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Propose Tests
//
-------------------------------------------------------------------------- */
console.log("[propose.manifest]");
res = await Part.propose.manifest({
manifestId: "1",
transfers: [
{
amount: 100,
assetId: "EURO",
from: {
account: "Alice",
domain: "AliceBank",
participant: "participant",
},
to: {
account: "Bob",
domain: "BobBank",
participant: "participant",
},
transferId: "2",
},
],
});
console.log(res);
console.log("------------------");