nitro-loyalty-sdk
v1.0.3
Published
[](https://www.npmjs.com/package/nitro-loyalty-sdk) [](LICENSE)
Maintainers
Readme
Nitro Loyalty
A simple Node.js SDK for interacting with the Nitro Loyalty API, allowing you to retrieve and manage loyalty data programmatically.
Features
- Easy integration with Nitro Loyalty API
- Handles authentication using API keys
- Fully async/await compatible
- Returns JSON responses
Installation
Install via npm:
npm install nitro-loyaltySetup Environment Variables
Your Nitro Loyalty API requires public and secret keys. The recommended way to store them is in environment variables.
1. Create a .env file
In the root of your project, create a .env file:
NITRO_LOYALTY_PUBLIC_KEY=your_public_key_here
NITRO_LOYALTY_SECRET_KEY=your_secret_key_hereReplace the placeholders with your actual API keys.
2. Install dotenv
Install the dotenv package to load your environment variables:
npm install dotenv3. Load .env in your code
At the top of your main file (e.g., index.js):
require("dotenv").config();Usage
const nitro = require("nitro-loyalty");
async function run() {
const result = await nitro.getPoints("user123");
console.log(result);
const updateResult = await nitro.updatePoints(
"user123",
50,
"txn456",
"store789",
200
);
console.log(updateResult);
}
run();API Functions
1. updatePoints(userId, points, transactionId, location, amount)
Updates a user's loyalty points in Nitro Loyalty.
Parameters:
| Name | Type | Required | Description |
| --------------- | ------ | -------- | ----------------------------------------- |
| userId | string | Yes | Unique identifier of the user |
| points | number | Yes | Number of points to add or subtract |
| transactionId | string | Yes | Unique transaction identifier |
| location | string | Yes | Location for the transaction |
| amount | number | Yes | Monetary value associated with the points |
Returns:
- Success:
{
"success": true,
"message": "Points updated successfully",
"data": { "userId": "12345", "points": 100 }
}- Error:
{
"success": false,
"error": "Error message here"
}Usage Example:
const nitro = require("nitro-loyalty");
async function updateUserPoints() {
const result = await nitro.updatePoints(
"user123",
50,
"txn456",
"store789",
200
);
console.log(result);
}
updateUserPoints();2. getPoints(userId)
Retrieves the current loyalty points of a user.
Parameters:
| Name | Type | Required | Description |
| -------- | ------ | -------- | ----------------------------- |
| userId | string | Yes | Unique identifier of the user |
Returns:
- Success:
{
"success": true,
"data": { "userId": "12345", "points": 150 }
}- Error:
{
"success": false,
"error": "Error message here"
}Usage Example:
const nitro = require("nitro-loyalty");
async function getUserPoints() {
const result = await nitro.getPoints("user123");
console.log(result);
}
getUserPoints();Notes
- Both functions require
NITRO_LOYALTY_PUBLIC_KEYenvironment variable. - HMAC signatures are generated automatically for authentication.
- Errors may occur if API keys are missing, invalid, or if the API returns a server error.
License
MIT © Haider Ali
