DEV Community

Rowida Najah (MiddleEast)
Rowida Najah (MiddleEast)

Posted on

Internal SDK for TAC Backend Services

Internal SDK for TAC Backend Services

This package provides a standardized, shared Software Development Kit (SDK) for backend services within the TAC. It centralizes API clients, business logic services, and common utilities to promote code reuse and consistency.

Installation

Install the package from the internal package registry:

npm install @pwc-me-operate-internal/tac-internal-sdk
Enter fullscreen mode Exit fullscreen mode

Core Concept: The SDK Factory

The main export is a factory class named SDK. You instantiate this class with a high-level configuration object, and it produces fully configured, performance-optimized API clients and high-level services.

1. Initialization & Usage

Create an instance of the SDK at your application's startup. The constructor accepts a configuration object that defines which APIs your service needs to connect to.

const SDK = require('@pwc-me-operate-internal/tac-internal-sdk')

const sdkConfig = {
  // Config for the Process Backend API
  process: {
    baseURL: process.env.PROCESS_API_BASE_URL,
    apiKey: process.env.PROCESS_API_KEY
  },
  // Config for the Candidate Backend API
  candidate: {
    baseURL: process.env.CANDIDATE_API_BASE_URL,
    apiKey: process.env.CANDIDATE_API_KEY
  },
  // Config for the Org Unit (Admin) API
  orgUnit: {
    baseURL: process.env.ORG_UNIT_API_BASE_URL,
    apiKey: process.env.ORG_UNIT_API_KEY
  },
  // Config for the legacy SUN API
  sun: {
    baseURL: process.env.SUN_API_BASE_URL,
    subscription_key: process.env.SUN_API_SUBSCRIPTION_KEY
  },
  // Optional config for data encryption/decryption
  encryption: {
    secret: process.env.ENCRYPTION_SECRET,
    iv: process.env.ENCRYPTION_IV
  }
}

const sdk = new SDK(sdkConfig)
Enter fullscreen mode Exit fullscreen mode

2. Accessing Services

Services provide high-level business logic and orchestrate calls between different clients. They are the preferred way to interact with the SDK.

- sdk.process: Interacts with the Process and Candidate APIs.
- sdk.orgData: Interacts with the Org Unit API for employee, tower, and grade data.
Enter fullscreen mode Exit fullscreen mode

Example :

// In an Express controller or service file
class MyController {
  constructor(sdk) {
    this.sdk = sdk
  }

  async getDemands(req, res) {
    // Use the ProcessService to fetch demands
    const demands = await this.sdk.process.getDemands({ page: 1, limit: 10 })
    res.json(demands)
  }

  async getEmployee(req, res) {
    // Use the OrgDataService to fetch an employee
    const employee = await this.sdk.orgData.getEmployeeById(req.params.id)
    res.json(employee)
  }
}
Enter fullscreen mode Exit fullscreen mode

Accessing Raw API Clients

For direct, low-level API calls, you can access the configured Axios-based clients.

- sdk.clients.process
- sdk.clients.candidate
- sdk.clients.orgUnit
- sdk.clients.sun
Enter fullscreen mode Exit fullscreen mode

Example

// Get a health check directly from the Process API client
const health = await sdk.clients.process.healthCheck()
Enter fullscreen mode Exit fullscreen mode

Utilities

The SDK package also includes several utility modules attached as static properties to the main SDK export.

SDK.utils

General-purpose helper functions, such as data encryption/decryption.

const { crypto } = SDK.utils

const encrypted = crypto.encrypt('secret-data', sdk.encryptionConfig)
Enter fullscreen mode Exit fullscreen mode

Key Design Features

The SDK is designed to handle best practices for performance and maintainability with:

SDK Client Factory Pattern Components

Performance via Connection Reuse (http.Agent)

For optimal performance in S2S communication, the SDK instantiates a single, shared http.Agent and https.Agent with keepAlive: true, to reduces the overhead of TCP handshakes and improves request latency
due to the expected number of requests


TODO: Future Additions
The following modules are planned but not yet implemented.

SDK.constants
[TODO] This module is a placeholder. It will be populated with shared constants (e.g., enum values, cache keys) as they are standardized across services.

SDK.express
[TODO] This module is a placeholder. It will contain shared Express middleware for common concerns like authentication, authorization, and standardized error handling.

SDK.storage
Utilities for interacting with shared storage solutions GCP bucket.

Top comments (0)