Skip to content

Utils and Security

Methods for managing access and settings of WAPI database instance.

Quick Reference

MethodDescription
createAccessTokenCreate a JWT token for use with HTTP api
createApikeyCreate a new API key for accessing WAPI
createIndexCreate a metadata index.
dropIndexDrop a metadata index.
findApikeysSearch for API keys using either a simple filter or queryBuilder
findIndexesSearch for metadata indexes.
getFlagsRetrieve the current state of configurable Flags for your WAPI instance
healthcheckGet information about the health of the API
setFlagsConfigure WAPI instance Flags
updateApikeyUpdate an API key

createAccessToken

Create a JWT token for use with HTTP api

ts
await client.createAccessToken({
  token: {
    type: 'limited',
    scopes: ['getBalance'],
    filters: {
      wallet_foreign: 'user-1-wallet',
      token_foreign: 'EUR',
    },
    expiresIn: 60,
  },
});
ts
{
  authToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoibGltaXRlZCIsImNvbm5lY3Rpb24iOiJ3YXBpX2VlZjE2Mzp0ZXN0Iiwic2NvcGVzIjpbImF1dGhlbnRpY2F0aW9uQ2hlY2siLCJnZXRCYWxhbmNlIl0sImZpbHRlcnMiOnsid2FsbGV0X2ZvcmVpZ24iOiJ1c2VyLTEtd2FsbGV0IiwidG9rZW5fZm9yZWlnbiI6IkVVUiJ9LCJpYXQiOjE3Njk0MzUxODEsImV4cCI6MTc2OTQzODc4MX0.JC92-n35SCx8LWuSVwHToFkDuy-Bs1FUdx3wAPwCEdM'
};

createAccessTokenFnInput

Input for createAccessToken

AttributeTypeRequiredDescription
token{}
options{}Optional flags for input

createAccessTokenFnOutput

Output of createAccessToken

AttributeTypeAlwaysDescription
authTokenstringThe JWT token

createApikey

Create a new API key for accessing WAPI

ts
await client.createApikey({
  type: 'limited',
  description: 'New limited key',
  functions: ['createTransfer', 'findWalletMany'],
  valid_until: moment().add(2, 'hour').toISOString(),
  metadata: {
    myFancyKey: true,
  },
});
ts
{
  apikey: {
    id: 4,
    apikey: '8205f03e54',
    type: 'limited',
    description: 'New limited key',
    metadata: {
      myFancyKey: true
    },
    valid_until: '2026-01-01T10:00:00.000Z',
    status: 'active',
    created_at: '2026-01-01T10:00:00.000Z',
    updated_at: '2026-01-01T10:00:00.000Z',
    functions: [
      'authenticationCheck',
      'healthcheck',
      'createTransfer',
      'findWalletMany'
    ],
    apisecret: '1061a716ac29dcd47d2deae3107c95ce93f34cd690c8eca0'
  }
};

createApikeyFnInput

Input for createApikey

AttributeTypeRequiredDescription
typeApikeyType Type of the Apikey
descriptionstringDescription of the accessKey
functionsFunctions[]Scopes for limited apikey, will be ignored if type is admin
valid_untilstringApiKey expiration datetime
metadata Metadata Custom key/value object
options{}

createApikeyFnOutput

Output of createApikey

AttributeTypeAlwaysDescription
apikey{}

createIndex

Create a metadata index.

ts
await client.createIndex(
  {
    model: 'Transfer',
    metadata_field: 'my.field'
  },
  {
    // GENERALOPTIONS
  },
);
ts
{
  index: {
    model: 'Transfer',
    metadata_field: 'my.field',
    index_size: '8192 bytes'
  }
};

createIndexFnInput

Input for createIndex

AttributeTypeRequiredDescription
modelModel
metadata_fieldstring
options{}Optional flags for input

createIndexFnOutput

Output of createIndex

AttributeTypeAlwaysDescription
index{}

dropIndex

Drop a metadata index.

ts
await client.dropIndex(
  {
    model: 'Token',
    metadata_field: 'meta.field'
  },
  {
    // GENERALOPTIONS
  },
);
ts
{
  index: {
    model: 'Token',
    metadata_field: 'meta.field',
    index_size: '8192 bytes'
  }
};

dropIndexFnInput

Input for dropIndex

AttributeTypeRequiredDescription
modelModel
metadata_fieldstring
options{}Optional flags for input

dropIndexFnOutput

Output of dropIndex

AttributeTypeAlwaysDescription
index{}

findApikeys

Search for API keys using either a simple filter or queryBuilder

ts
await client
  .findApikeys()
  .where({
    status: 'active',
  })
  .where('description', 'like', 'Find test key%')
  .limit(5)
  .offset(0)
  .orderBy(['description', { column: 'id', order: 'desc' }])
  .options({
    tracking_id: 'find-apikeys-test',
    return_metadata_total: true,
  });
ts
{
  apikeys: [
    {
      id: 3,
      apikey: 'findtest1',
      type: 'admin',
      description: 'Find test key 1',
      metadata: {
        even: false,
        index: 1
      },
      valid_until: null,
      scopes: null,
      status: 'active',
      created_at: '2026-01-01T10:00:00.000Z',
      updated_at: '2026-01-01T10:00:00.000Z'
    },
    {
      id: 4,
      apikey: 'findtest2',
      type: 'limited',
      description: 'Find test key 2',
      metadata: {
        even: true,
        index: 2
      },
      valid_until: null,
      scopes: null,
      status: 'active',
      created_at: '2026-01-01T10:00:00.000Z',
      updated_at: '2026-01-01T10:00:00.000Z'
    },
    {
      id: 5,
      apikey: 'findtest3',
      type: 'admin',
      description: 'Find test key 3',
      metadata: {
        even: false,
        index: 3
      },
      valid_until: null,
      scopes: null,
      status: 'active',
      created_at: '2026-01-01T10:00:00.000Z',
      updated_at: '2026-01-01T10:00:00.000Z'
    },
    {
      id: 6,
      apikey: 'findtest4',
      type: 'limited',
      description: 'Find test key 4',
      metadata: {
        even: true,
        index: 4
      },
      valid_until: '2026-01-01T10:00:00.000Z',
      scopes: null,
      status: 'active',
      created_at: '2026-01-01T10:00:00.000Z',
      updated_at: '2026-01-01T10:00:00.000Z'
    },
    {
      id: 8,
      apikey: 'findtest6',
      type: 'limited',
      description: 'Find test key 6',
      metadata: {
        even: true,
        index: 6
      },
      valid_until: null,
      scopes: null,
      status: 'active',
      created_at: '2026-01-01T10:00:00.000Z',
      updated_at: '2026-01-01T10:00:00.000Z'
    }
  ],
  metadata: {
    limit: 5,
    offset: 0,
    total: 8,
    more_rows: true,
    order: [
      {
        field: 'description',
        direction: 'asc'
      },
      {
        field: 'id',
        direction: 'desc'
      }
    ]
  }
};

findApikeysFnInput

Input for findApikeys

AttributeTypeRequiredDescription
typeApikeyType Type of the apikey
statusApikeyStatus Status of the apikey
descriptionstringApikey description
metadata MetadataSearch Metadata filter for custom properties
options{}Optional flags for input

findApikeysFnOutput

Output of findApikeys

AttributeTypeAlwaysDescription
apikeys({})[]Found apikeys
metadata{}Metadata about the search

findIndexes

Search for metadata indexes.

ts
await client
  .findIndexes({
    model: 'Token'
  });
ts
{
  indexes: [
    {
      model: 'Token',
      metadata_field: 'my.new',
      index_size: '8192 bytes'
    },
    {
      model: 'Token',
      metadata_field: 'my.old',
      index_size: '8192 bytes'
    }
  ],
  metadata: {
    total: 2,
    limit: 0,
    offset: 0,
    more_rows: false
  }
};

findIndexesFnInput

Input for findIndexes

AttributeTypeRequiredDescription
modelModel
options{}Optional flags for input

findIndexesFnOutput

Output of findIndexes

AttributeTypeAlwaysDescription
indexes({})[]Found indexes
metadata{}Metadata about the search

getFlags

Retrieve the current state of configurable Flags for your WAPI instance

ts
await client.getFlags();
ts
{
  flags: {
    allow_timestamps: false,
    production: true
  }
};

getFlagsFnInput

Input for getFlags

AttributeTypeRequiredDescription
options{}Optional flags for input

getFlagsFnOutput

Output of getFlags

AttributeTypeAlwaysDescription
flags{}System wide flags

healthcheck

Get information about the health of the API

ts
await client.healthcheck();
ts
{
  status: 'green',
  version: '0.17.4',
  database_size: '9531 kB',
  indexes_size: '576 kB',
  connection_count: 1
};

healthcheckFnInput

Input for healthcheck

AttributeTypeRequiredDescription
options{}Optional flags for input

healthcheckFnOutput

Output of healthcheck

AttributeTypeAlwaysDescription
statusServiceStatus Status of the service
messagestringError message if some error occurred
database_sizestringSize of the database in MB
indexes_sizestringSize of all indexes of database in MB
connection_countnumberNumber of external connections to this database
versionstringVersion the server is running

setFlags

Configure WAPI instance Flags

ts
await client.setFlags(
  {
    production: false,
    allow_timestamps: true,
  },
  {
    tracking_id: 'mylog',
  },
);
ts
{
  flags: {
    allow_timestamps: true,
    production: false
  },
  message: 'flag updated, reconnect to apply'
};

setFlagsFnInput

Input for setFlags

AttributeTypeRequiredDescription
allow_timestampsbooleanAllow setting timestamps in transfer insert/update statements
productionbooleanIs running in production mode?
options{}Optional flags for input

setFlagsFnOutput

Output of setFlags

AttributeTypeAlwaysDescription
flags{}System wide flags
messagestringoptional message

updateApikey

Update an API key

ts
await client.updateApikey(
  {
    apikey: createResponse.apikey.apikey,
    metadata: {
      updated: true,
      customField: 'test-value',
    },
    // status: 'deleted',
    apisecret: true,
  },
  {
    return_when_not_updated: true,
    // GENERALOPTIONS
  },
);
ts
{
  apikey: {
    id: 2,
    apikey: '5bcd795342',
    type: 'admin',
    scopes: null,
    description: 'Key to update',
    metadata: {
      updated: true,
      customField: 'test-value'
    },
    valid_until: null,
    status: 'active',
    created_at: '2026-01-01T10:00:00.000Z',
    updated_at: '2026-01-01T10:00:00.000Z',
    apisecret: 'dfeb989262413cdfc7131bce07a9249b44806400a4a8f7f7'
  },
  updated: true
};

updateApikeyFnInput

Input for updateApikey

AttributeTypeRequiredDescription
apikeystringApikey identifier
metadata Metadata Metadata for the apikey
statusdeletedSet to deleted to remove the apikey
apisecretbooleanSet to true to regenerate the apisecret
options{}Optional flags for input

updateApikeyFnOutput

Output of updateApikey

AttributeTypeAlwaysDescription
apikey{}
updatedbooleanBoolean showing if the Apikey was updated