Node JS SDK

Overview

Node JS SDk has all the necessary methods to access the Catalyst Components and services. It allows you to declare and define Catalyst components whose behavior are predefined. For example, each Catalyst component has its equivalent NodeJS object in SDK and API equivalents are called methods in NodeJS.

Include Catalyst SDK in Project

If you choose install dependencies option in the CLI while initializing a Node.js function, the Node.js SDK will automatically be included in the generated sample boilerplate code. However, you can also manually include it in your project, by executing the following command from the function’s root directory in the CLI:

    
copy
npm install zcatalyst-sdk-node

You can also install a specific supported version in this way:

    
copy
npm install zcatalyst-sdk-node@2.1.1

Initialize the SDK

Catalyst Node.js SDK must be initialized which would return an object. You can access the catalyst components of the current project thrugh this returned object. The different initialization methods for different type of functions are as given below.

    
SDK Initialization in Advanced I/O Functions with the Basic Template
copy
var catalyst = require('zcatalyst-sdk-node'); module.exports = (req, res) => { var app = catalyst.initialize(req); //This app variable is used to access the catalyst components. //You can refer the SDK docs for code samples. //Your business logic comes here }
View more
    
SDK Initialization in Advanced I/O Functions with Express.js
copy
var catalyst = require('zcatalyst-sdk-node'); const express = require('express'); const expressApp = express(); expressApp.get('/',(req,res)=> { var app = catalyst.initialize(req); //This app variable is used to access the catalyst components. //You can refer the SDK docs for code samples. //Your business logic comes here }); module.exports=expressApp;
View more
    
SDK Initialization in BasicIO Functions
copy
const catalyst = require('zcatalyst-sdk-node'); module.exports = (context, basicIO) => { const app = catalyst.initialize(context); //This app variable is used to access the catalyst components. //You can refer the SDK docs for code samples. //Your business logic comes here }
View more
    
SDK Initialization in Event Functions
copy
const catalyst = require('zcatalyst-sdk-node'); module.exports = (event, context) => { const app = catalyst.initialize(context); //This app variable is used to access the catalyst components. //You can refer the SDK docs for code samples. //Your business logic comes here }
View more
    
SDK Intialization in Cron Functions
copy
const catalyst = require('zcatalyst-sdk-node'); module.exports = (cronDetails, context) => { const app = catalyst.initialize(context); //This app variable is used to access the catalyst components. //You can refer the SDK docs for code samples. //Your business logic comes here }
View more

Now you can access the components using the initialized variable.

Initialize SDK With Scopes

Catalyst allows you to initialize the SDK in a project using the following scopes:

  • Admin: You have unrestricted access to all the components and their respective functionalities. For example, you have complete access to the Data Store to perform all operations like Read, Write, Delete, etc.

  • User: You can restrict access to components, and specific functionalities. For example, you can provide Read access alone to Data Store.

Note:
  • It is not mandatory for you to initialize the projects with scopes. By default, a project that is initialized will have Admin privileges.

  • Ensure you have initialized the Catalyst SDK with the appropriate scope while you engineer your business logic. The permissions you define for your scope control your end-user’s actions.

  • Scopes only apply to operations related Data Store, File Store, and ZCQL.

  • Depending on how you engineer your business logic, you can decide if your end-users can perform Admin or User actions. This is decided based on the role assigned to your end-user when they sign up to your application in Catalyst Authentication. The permissions for the roles can be configured in the Scopes & Permissions section of the Data Store and File store.

The SDK snippets below will allow you to initialize the SDK using either Admin or User scope, and perform a SELECT query in the Data Store:

  • Initialize the SDK with Admin Scope
    
copy
const catalyst = require('zcatalyst-sdk-node'); module.exports = async (req, res) => { const app = catalyst.initialize(req); const adminApp = catalyst.initialize(req, { scope: 'admin'}); // catalyst app object with admin scope await adminApp.zcql().executeZCQLQuery('select * from test'); }
  • Initialize the Catalyst project with User Scope
    
copy
const catalyst = require('zcatalyst-sdk-node'); module.exports = async (req, res) => { const app = catalyst.initialize(req); const userApp = catalyst.initialize(req, { scope: 'user'}); // catalyst app object with user scope await userApp.zcql().executeZCQLQuery('select * from test'); }

Last Updated 2023-10-04 14:50:53 +0530 +0530