Skip to content

Nirmitee-tech/abdm-sdk-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ABDM Node.js SDK

npm version License: MIT TypeScript

Node.js SDK for Ayushman Bharat Digital Mission (ABDM) API. This SDK provides a simple and type-safe way to interact with ABDM's healthcare APIs.

✨ Features

  • TypeScript Support: Full TypeScript support with type definitions
  • Comprehensive API Coverage: Covers all major ABDM APIs
  • Promise-based: All API calls return Promises
  • Configurable: Customize HTTP client and other options
  • Well-tested: Comprehensive test suite
  • Production-ready: Used in production by Nirmitee

πŸ“¦ Installation

# Using npm
npm install @nirmitee/abdm-sdk-node

# Using yarn
yarn add @nirmitee/abdm-sdk-node

# Using pnpm
pnpm add @nirmitee/abdm-sdk-node

πŸ”§ Prerequisites

  • Node.js 16.0.0 or higher
  • TypeScript 4.0.0 or higher (for TypeScript projects)
  • Valid ABDM API credentials

πŸš€ Quick Start

πŸ§‘β€πŸ’» Usage Example: Generate and Verify Aadhaar OTP

import { ABDMClient } from '@nirmitee/abdm-sdk-node';

const client = new ABDMClient({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret'
});

async function generateAndVerifyAadhaarOTP() {
  try {
    // Step 1: Generate Aadhaar OTP
    const generateResponse = await client.generateAadhaarOTP({
      aadhaar: '123456789012',
      txnId: '' // Leave blank or omit; will be generated by the API if not provided
    });
    console.log('Aadhaar OTP sent:', generateResponse);

    // Extract txnId from the response
    const txnId = generateResponse?.data?.txnId; // Adjust based on actual response structure

    // Step 2: Prompt user to enter the OTP received on their mobile and the mobile number used for Aadhaar
    const otp = '123456'; // TODO: Replace with actual OTP input from user
    const mobile = '9876543210'; // TODO: Replace with the mobile number used for Aadhaar authentication

    // Step 3: Verify Aadhaar OTP
    const verifyResponse = await client.verifyAadhaarOTP({
      txnId, // Use txnId from generateAadhaarOTP response
      otp,
      mobile // Mobile number must be entered by the user
    });
    console.log('Aadhaar OTP verified:', verifyResponse);
    return verifyResponse;
  } catch (error) {
    console.error('Error in Aadhaar OTP flow:', error);
    throw error;
  }
}

generateAndVerifyAadhaarOTP();

πŸ“š API Reference

Available Services

  • auth: Authentication and user management

    • generateAadhaarOTP(): Generate OTP for Aadhaar authentication
    • verifyAadhaarOTP(): Verify Aadhaar OTP
    • generateMobileOTP(): Generate OTP for mobile authentication
    • verifyMobileOTP(): Verify mobile OTP
    • getAuthToken(): Get authentication token
  • consent: Consent management

    • createConsent(): Create a new consent
    • getConsentStatus(): Get consent status
    • revokeConsent(): Revoke consent
  • health: Health record and facility services

    • addUpdateHealthFacilityServices(data): Add or update health facility services
    • getHealthFacility(facilityId): Get health facility details
    • listHealthFacilities(): List all health facilities
    • updateHealthFacilityStatus(facilityId, active): Update health facility status (active/inactive)
    • getHealthRecords(patientId, token, options): Fetch health records
    • getHealthRecord(recordId, token): Get health record by ID
    • getABHAProfile(abhaNumber, token): Get ABHA profile
    • updateABHAProfile(profileData, token): Update ABHA profile
    • getLinkedAddresses(abhaNumber, token): Get linked ABHA addresses
    • createConsent(consentRequest, token): Create a new consent request
    • getConsent(consentId, token): Get consent details

Configuration Options

interface ABDMConfig {
  clientId: string;
  clientSecret: string;
  // baseUrl: string;
  timeout?: number; // Request timeout in milliseconds (default: 30000)
  maxRetries?: number; // Maximum retry attempts (default: 3)
  retryDelay?: number; // Delay between retries in ms (default: 1000)
  debug?: boolean; // Enable debug logging (default: false)
}

πŸ§‘β€πŸ’» Usage Example: Add or Update Health Facility Services

import { ABDMClient } from '@nirmitee/abdm-sdk-node';

const client = new ABDMClient({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret'
});

async function addOrUpdateFacility() {
  try {
    const data = {
      // Fill with HealthFacilityRequest fields
    };
    const response = await client.health.addUpdateHealthFacilityServices(data);
    console.log('Facility add/update response:', response);
  } catch (error) {
    console.error('Error adding/updating facility:', error);
  }
}

addOrUpdateFacility();

πŸ›  Development

  1. Clone the repository

    git clone https://github.com/Nirmitee-tech/abdm-sdk-node.git
    cd abdm-sdk-node
  2. Install dependencies

    npm install
  3. Build the project

    npm run build
  4. Run tests

    # Run all tests
    npm test
    
    # Run unit tests
    npm run test:unit
    
    # Run integration tests
    npm run test:integration
    
    # Run tests with coverage
    npm run test:coverage
  5. Lint and format code

    # Lint code
    npm run lint
    
    # Format code
    npm run format

πŸ›  Troubleshooting SSL/Crypto Issues

Node.js & OpenSSL Requirements

  • Node.js 16.0.0 or higher is required.
  • OpenSSL 1.x or 3.x is required (Node.js uses OpenSSL under the hood).

Common Errors & Solutions

  • Encryption failed: unsupported or Failed to create public key object: Your Node.js or OpenSSL version may be too old or incompatible. Upgrade Node.js to the latest LTS version.

  • OpenSSL legacy provider required: On Node.js 17+ with OpenSSL 3, you may need to run your app with:

    node --openssl-legacy-provider your-app.js
  • Insecure SSL warning in production: Never set NODE_TLS_REJECT_UNAUTHORIZED=0 or use rejectUnauthorized: false in production. This is only for sandbox/testing.

Still Stuck?

  • Check your Node.js version: node -v
  • Check your OpenSSL version: node -p "process.versions.openssl"
  • If you see errors, upgrade Node.js or consult the SDK documentation/issues.

🀝 Contributing

Contributions are welcome! Please read our contributing guidelines before submitting pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.

πŸ“ž Contact

Nirmitee - https://nirmitee.io/get-in-touch/

Project Link: https://github.com/Nirmitee-tech/abdm-sdk-node

πŸ™ Acknowledgments

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors