@emdgroup/metering-sdk
v1.0.1
Published
Downloads
1
Readme
Platform Core Components: Metering SDK
Table of Contents
Installation
Install globally...npm install -g @emdgroup/metering-sdk
...or as a local dependencyyarn add @emdgroup/metering-sdk
Getting Started
See our OpenAPI docs for response descriptions and further information.
Typescript examples
import { KeysApi } from '@emdgroup/metering-sdk';
const keysApi = new KeysApi(undefined, basePath);
const txApi = new TransactionsApi(undefined, basePath);
const accessToken = process.env.METERING_ACCESS_TOKEN || '';
const options = {headers: {Authorization: `Bearer ${accessToken}`}};
POST /keys
const { data } = await keysApi.createKey({
keyId: 'someKeyId',
resources: []}, options);
PUT /keys/{keyId}
const { data } = await keysApi.resetKey('someKeyId', {
resources: [
{ resourceId: 'resourceId1', limit: 100 },
{ resourceId: 'resourceId2', accessUntilDate: '2030-01-01' }
]}, options);
GET /keys/{keyId}
const { data } = await keysApi.describeKey('someKeyId', options);
console.log(data);
/**
{
keyId: 'someKeyId',
resources: [{
resourceId: 'resourceId2',
pending: 0,
confirmed: 0,
accessUntilDate: '2030-01-01T00:00:00.000Z'
}, {
resourceId: 'resourceId1',
pending: 0,
confirmed: 0,
limit: 100
}]
}
*/
POST /transactions
const { data: { transactionId } } = await txApi.createTransaction({
keyId: 'someKeyId',
resourceId: 'resourceId1',
quantity: 10}, options);
GET /transactions/{transactionId}
const { data: transaction } = await txApi.describeTransaction(transactionId, options);
console.log(transaction);
/**
{
keyId: 'someKeyId',
resourceId: 'resourceId1',
quantity: 10,
transactionId: <transactionId>,
status: 'PENDING',
expirationDate: '2021-03-24T23:42:31.444Z'
}
*/
POST /transactions/{transactionId}
await txApi.commitTransaction(transactionId, options);
PUT /transactions/{transactionId}
await txApi.updateTransaction(transactionId, { quantity: 5 }, options);
DELETE /transactions/{transactionId}
await txApi.cancelTransaction(transactionId, options);