Solace SempV2 OpenAPI Client for NodeJS

Requirements

  • node 16.x

Install

npm install @solace-labs/sempv2-openapi-node

Configure OpenAPI Object

import { OpenAPI } from "@solace-labs/sempv2-config-openapi-node";

const protocol = "https";
const host = "{service-name}.messaging.solace.cloud";
const post = 943;

OpenAPI.BASE = `${protocol}://${host}:${port}/SEMP/v2/config`;
OpenAPI.USERNAME = '{sempv2 username}';
OpenAPI.PASSWORD = '{sempv2 password}';

Example: Create and Delete a client username

import {
  ClientUsernameService,
  MsgVpnClientUsername,
  MsgVpnClientUsernameResponse,
} from "@solace-labs/sempv2-config-openapi-node";

const msgVpnClientUsername: MsgVpnClientUsername = {
  clientUsername: 'foo',
  password: 'bar'
};
// create
const msgVpnClientUsernameResponse: MsgVpnClientUsernameResponse = await ClientUsernameService.createMsgVpnClientUsername({
  msgVpnName: '{msgVpnName}',
  body: msgVpnClientUsername,
});
console.log(`msgVpnClientUsernameResponse=${JSON.stringify(msgVpnClientUsernameResponse, null, 2)}`);
// delete
await ClientUsernameService.deleteMsgVpnClientUsername({
  msgVpnName: '{msgVpnName}',
  clientUsername: msgVpnClientUsername.clientUsername,
});

Advanced Usage

Use of fetch-with-proxy

Node fetch replaced with fetch-with-proxy.

See node-fetch-with-proxy for details.

Use of a resolver

OpenAPIConfig:

export type OpenAPIConfig = {
  BASE: string | Resolver<string>;
  VERSION: string;
  WITH_CREDENTIALS: boolean;
  CREDENTIALS: 'include' | 'omit' | 'same-origin';
  TOKEN?: string | Resolver<string>;
  USERNAME?: string | Resolver<string>;
  PASSWORD?: string | Resolver<string>;
  HEADERS?: Headers | Resolver<Headers>;
  ENCODE_PATH?: (path: string) => string;
};

Configure OpenAPI Object using a Resolver for the BASE Url:

const getBase = async(): Promise<string> => {
 // set your base ...
 const myBase = ..., or
 const myBase = await ...
 return myBase;
}

// make use of it
OpenAPI.BASE = async() => { return await getBase(); }