Skip to main content

Get Resources

Get all accessible resources.

const jsc8 = require("jsc8");

// Email and password to authenticate client instance
const email = "nemo@nautilus.com";
const password = "xxxxxx";
const fabric = "_system";
// API key ID
const keyid = "id1";

const client = new jsc8({
url: "https://play.paas.macrometa.io",
fabricName: fabric
});
// Choose one of the following authentication methods and remove the commenting.

// Create an authenticated instance with a JWT token.
// const clientUsingJwt = new jsc8({url: "https://play.paas.macrometa.io" , token: "XXXX" , fabricName: fabric});
// Create an authenticated instance with a API key.
// const clientUsingApiKey = new jsc8({url: "https://play.paas.macrometa.io" , apiKey: "XXXX" , fabricName: fabric });
function messageHandler(error) {
const message = {
"StatusCode ": error.statusCode,
"ErrorMessage ": error.message,
"ErrorNum ": error.errorNum
};
console.log(message);
}
async function main() {
await client
.login(email, password)
.then((e) => console.log("1. User authentication done!"))
.catch((error) => error);

console.log("\n2. Listing accessible databases for Key_ID = " + keyid);
await client
.listAccessibleDatabases(keyid)
.then((databases) => {
console.log(databases.result);
})
.catch((error) => messageHandler(error));

console.log("\n3. Listing accessible streams for Key_ID = " + keyid);
await client
.listAccessibleStreams(keyid, fabric, (full = false))
.then((streams) => {
console.log(streams.result);
})
.catch((error) => messageHandler(error));

console.log("\n4. Listing accessible collections for Key_ID = " + keyid);
await client
.listAccessibleCollections(keyid, fabric, (full = false))
.then((collections) => {
console.log(collections.result);
})
.catch((error) => messageHandler(error));
}

main()
.then()
.catch((error) => console.log(error));