JavaScript
The concepts from the .NET section all apply here. This section covers the specifics for the JS/TS SDK.
Install
npm install @wexinc/wex-health-sdkPin to a minor-compatible range so you receive non-breaking updates automatically:
"dependencies": {
"@wexinc/wex-health-sdk": "^1.0.10"
}Configure
Create one Configuration object at startup and pass it to every API class. Do not create a new instance per request — this defeats token caching and issues a fresh OAuth token on every call.
// config.ts
import { Configuration } from '@wexinc/wex-health-sdk';export const sdkConfig = new Configuration({
basePath: 'https://platform.uat.benefits.wexglobal.com',
oauth2Credentials: {
clientId: process.env.WEX_CLIENT_ID!,
clientSecret: process.env.WEX_CLIENT_SECRET!,
accessTokenUrl: process.env.WEX_TOKEN_URL!,
audience: process.env.WEX_AUDIENCE, // optional
scopes: ['claims:read', 'consumers:read'], // optional
},
});Call APIs
import { ClaimsApi, ConsumersApi } from '@wexinc/wex-health-sdk';
import { sdkConfig } from './config';const claimsApi = new ClaimsApi(sdkConfig);
const consumersApi = new ConsumersApi(sdkConfig);
// Single claim — third arg is optional xRequestId for tracing
const { data: claim } = await claimsApi.getClaim(
'person-uuid-here', '11BPEB1210513P0000101', 'my-correlation-id');
// All claims for a participant
const { data: claims } = await claimsApi.getClaimsForParticipant('person-uuid-here');
// Consumer profile
const { data: consumer } = await consumersApi.getConsumer('consumer-uuid-here');Handle Errors
try {
const { data } = await claimsApi.getClaim(personId, claimNumber);
}
catch (error: any) {
if (error.response) {
// error.response.data is typed as ProblemDetails
console.error(`API error ${error.response.status}:`, error.response.data);
} else {
console.error('Network error:', error.message);
}
}
Retry overrides (see Retry Contract for defaults):
const config = new Configuration({ // ...
retryConfig: {
retries: 5,
retryCondition: (err: any) => [500, 502, 503, 408].includes(err.response?.status),
},
});
Logging
Logging is off by default. Pass a logger in the Configuration constructor — setting it after construction will not be picked up by retry callbacks.
import { Configuration, ConsoleLogger, LogLevel } from '@wexinc/wex-health-sdk';const sdkConfig = new Configuration({
// ...
logger: new ConsoleLogger(LogLevel.Information), // use Warning or Information in production
});Log levels: Trace (0) · Debug (1) · Information (2) · Warning (3) · Error (4) · Critical (5) · None (6). Never use Trace in production.
To plug in your own logger (Winston, Pino, etc.), implement the ILogger interface:
import { ILogger, LogLevel } from '@wexinc/wex-health-sdk';class WinstonAdapter implements ILogger {
isEnabled(level: LogLevel) { return level >= LogLevel.Information; }
log(level: LogLevel, message: string, ...args: any[]) {
winston.info(message, ...args);
}
}On this page
- JavaScript