Installation
Install the @apso/sdk package in your JavaScript or TypeScript project.
Requirements
- Node.js 18.0 or higher
- TypeScript 5.0+ (recommended for full type inference)
Install via npm
npm install @apso/sdkInstall via yarn
yarn add @apso/sdkInstall via pnpm
pnpm add @apso/sdkTypeScript Support
The SDK is written in TypeScript and ships with type definitions (dist/index.d.ts). No additional @types packages are needed.
Dependencies
The SDK installs the following runtime dependencies:
| Package | Purpose |
|---|---|
axios | HTTP client (used when client: 'axios' is set) |
@dataui/crud-request | NestJS CRUD query string builder |
@apidevtools/swagger-parser | OpenAPI spec parsing |
openapi-types | OpenAPI type definitions |
Note: When using the default
fetchtransport,axiosis still installed as a dependency but is not loaded at runtime unless you explicitly setclient: 'axios'in your configuration.
Verify Installation
Create a quick test to confirm the SDK is installed correctly:
import { ApsoClientFactory } from '@apso/sdk';
const client = ApsoClientFactory.getClient({
baseURL: 'https://your-service.apso.cloud',
apiKey: 'your-api-key',
});
async function verify() {
try {
const result = await client.entity('Health').findMany();
console.log('SDK connected successfully:', result);
} catch (error) {
console.error('Connection failed:', error);
}
}
verify();Basic Setup
Create a shared client module that you import throughout your application:
import { ApsoClientFactory } from '@apso/sdk';
export const apso = ApsoClientFactory.getClient({
baseURL: process.env.APSO_API_URL!,
apiKey: process.env.APSO_API_KEY!,
});Then use it in your application code:
import { apso } from '../lib/apso';
export async function getActiveUsers() {
return apso.entity('Users')
.where({ status: { $eq: 'Active' } })
.orderBy({ created_at: 'DESC' })
.findMany();
}Framework-Specific Setup
Next.js
For Next.js applications, configure the client in a shared module. Use the APSO_API_URL environment variable (server-only) or NEXT_PUBLIC_APSO_API_URL if you need client-side access:
import { ApsoClientFactory } from '@apso/sdk';
export const apso = ApsoClientFactory.getClient({
baseURL: process.env.APSO_API_URL!,
apiKey: process.env.APSO_API_KEY!,
});Node.js / Express
import { ApsoClientFactory } from '@apso/sdk';
export const apso = ApsoClientFactory.getClient({
baseURL: process.env.APSO_API_URL!,
apiKey: process.env.APSO_API_KEY!,
client: 'axios', // Use axios for Node.js environments
timeout: 10000,
});Testing Setup
For tests, install axios-mock-adapter as a dev dependency to mock HTTP requests:
npm install --save-dev axios-mock-adapter @types/axios-mock-adapterSee the Operations page for complete testing examples.
Updating the SDK
npm update @apso/sdkCheck the current installed version:
npm list @apso/sdkTroubleshooting
āCannot find module ā@apso/sdkāā
Make sure the package is installed in your project (not globally):
npm install @apso/sdkTypeScript Compilation Errors
Ensure your tsconfig.json includes the following settings:
{
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true,
"target": "ES2018"
}
}Network / Connection Errors
If you see ECONNREFUSED or timeout errors:
- Verify your
baseURLis correct and the service is running - Check that your
apiKeyis valid - Confirm that no firewall or proxy is blocking the connection
- Try increasing the
timeoutvalue in your configuration