@treasurenet/tngateway-client
v0.1.0
Published
Treasurenet OAuth2 client for TN Gateway
Downloads
76
Readme
@treasurenet/tngateway-client
Treasurenet Gateway Client for Node.js services.
Features
- OAuth2 client-credentials token fetch and cache
- Auto inject
Authorizationand optionalx-request-id getData(method, url, data)compatibility methodprobeToken()health probe helper
Install
npm i @treasurenet/tngateway-clientUsage
const { createTnGatewayClient } = require('@treasurenet/tngateway-client');
const client = createTnGatewayClient({
accessTokenUrl: process.env.TNGATEWAY_ACCESS_TOKEN_URL,
clientId: process.env.TNGATEWAY_CLIENT_ID,
clientSecret: process.env.TNGATEWAY_CLIENT_SECRET,
scope: process.env.TNGATEWAY_SCOPE,
baseUrl: process.env.TNGATEWAY_API_URL,
});
const healthy = await client.probeToken();
const list = await client.getData('get', '/auction/list', { page: 1, pageSize: 20 });API
createTnGatewayClient(options)
Create a new gateway client instance.
client.getData(method, url, data, options?)
Compatibility method with legacy signature:
method:'get' | 'post'url: absolute URL or path (path needsbaseUrlin options)data: request params/bodyoptions.requestId: addx-request-idoptions.headers: merge extra headers
Returns upstream response data, false when authorization is unavailable, and undefined for unsupported method.
client.probeToken()
Returns true if token can be fetched, otherwise false.
client.getAuthorization(forceRefresh?)
Return cached/fresh authorization string.
