Internal SDK for TAC Backend Services
Source: Dev.to
Overview
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
Creating an SDK Instance
The main export is a factory class named SDK. Instantiate it with a high‑level configuration object, and it will produce fully configured, performance‑optimized API clients and high‑level services.
const SDK = require('@pwc-me-operate-internal/tac-internal-sdk');
const sdkConfig = {
// Process Backend API
process: {
baseURL: process.env.PROCESS_API_BASE_URL,
apiKey: process.env.PROCESS_API_KEY,
},
// Candidate Backend API
candidate: {
baseURL: process.env.CANDIDATE_API_BASE_URL,
apiKey: process.env.CANDIDATE_API_KEY,
},
// Org Unit (Admin) API
orgUnit: {
baseURL: process.env.ORG_UNIT_API_BASE_URL,
apiKey: process.env.ORG_UNIT_API_KEY,
},
// Legacy SUN API
sun: {
baseURL: process.env.SUN_API_BASE_URL,
subscription_key: process.env.SUN_API_SUBSCRIPTION_KEY,
},
// Optional data encryption/decryption
encryption: {
secret: process.env.ENCRYPTION_SECRET,
iv: process.env.ENCRYPTION_IV,
},
};
const sdk = new SDK(sdkConfig);
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.
Example: Using Services in an Express Controller
// 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);
}
}
Direct API Clients
For low‑level calls, you can access the configured Axios‑based clients:
sdk.clients.processsdk.clients.candidatesdk.clients.orgUnitsdk.clients.sun
Example: Health Check via the Process Client
// Get a health check directly from the Process API client
const health = await sdk.clients.process.healthCheck();
Utilities
The SDK includes several utility modules attached as static properties to the main export.
const { crypto } = SDK.utils;
// Example: Encrypt data using the SDK's encryption configuration
const encrypted = crypto.encrypt('secret-data', sdk.encryptionConfig);
Performance Considerations
The SDK is designed with best practices for performance and maintainability:
- A single shared
http.Agentandhttps.Agentis instantiated withkeepAlive: true. - This reduces the overhead of TCP handshakes and improves request latency for server‑to‑server communication.
Future Additions (TODO)
SDK.constantsSDK.expressSDK.storage(e.g., GCP bucket integration)