SDK Installation
Install and configure the 4Quays SDK in your application
The 4Quays SDK provides a simple interface for protecting and unprotecting payloads. This guide covers installation and configuration.
Installation
Install the SDK using your preferred package manager:
# npm npm install @4quays/sdk # yarn yarn add @4quays/sdk # pnpm pnpm add @4quays/sdk
Basic Configuration
Import and initialize the SDK:
import { FourQ } from '@4quays/sdk';
const fourq = new FourQ({
endpoint: process.env.FOURQ_ENDPOINT,
apiKey: process.env.FOURQ_API_KEY,
});
Configuration Options
The SDK accepts the following configuration:
| Option | Type | Required | Description |
|---|---|---|---|
endpoint | string | No | 4Quays API endpoint. Omit for passthrough mode. |
apiKey | string | No | Your API key. Required when endpoint is set. |
timeout | number | No | Request timeout in milliseconds (default: 30000) |
retries | number | No | Number of retry attempts (default: 3) |
Environment Variables
We recommend using environment variables for configuration:
# .env FOURQ_ENDPOINT=https://api.4quays.com FOURQ_API_KEY=sk_live_xxxxxxxxxxxxx
const fourq = new FourQ({
endpoint: process.env.FOURQ_ENDPOINT,
apiKey: process.env.FOURQ_API_KEY,
});
TypeScript Support
The SDK is written in TypeScript and includes full type definitions:
import { FourQ, ProtectResult, UnprotectResult } from '@4quays/sdk';
const fourq = new FourQ({
endpoint: process.env.FOURQ_ENDPOINT,
apiKey: process.env.FOURQ_API_KEY,
});
// Types are inferred
const result: ProtectResult = await fourq.protect(
{ amount: 1000 },
'PAYMENT-POLICY'
);
Framework-Specific Setup
Next.js
Create a singleton instance:
// lib/fourq.ts
import { FourQ } from '@4quays/sdk';
export const fourq = new FourQ({
endpoint: process.env.FOURQ_ENDPOINT,
apiKey: process.env.FOURQ_API_KEY,
});
Use in API routes or server actions:
// app/api/transfer/route.ts
import { fourq } from '@/lib/fourq';
export async function POST(request: Request) {
const payload = await request.json();
const protected = await fourq.protect(payload, 'TRANSFER-POLICY');
// Send to external service...
}
Express
Initialize at app startup:
// app.js
const express = require('express');
const { FourQ } = require('@4quays/sdk');
const app = express();
const fourq = new FourQ({
endpoint: process.env.FOURQ_ENDPOINT,
apiKey: process.env.FOURQ_API_KEY,
});
app.post('/transfer', async (req, res) => {
const protected = await fourq.protect(req.body, 'TRANSFER-POLICY');
// Send to external service...
});
NestJS
Create a provider:
// fourq.provider.ts
import { Provider } from '@nestjs/common';
import { FourQ } from '@4quays/sdk';
export const FourQProvider: Provider = {
provide: 'FOURQ',
useFactory: () => {
return new FourQ({
endpoint: process.env.FOURQ_ENDPOINT,
apiKey: process.env.FOURQ_API_KEY,
});
},
};
Verifying Installation
Test your installation with a health check:
const health = await fourq.checkHealth();
console.log(health);
// { connected: true, latencyMs: 45, mode: 'production' }
In passthrough mode (no endpoint configured):
const health = await fourq.checkHealth();
console.log(health);
// { connected: false, latencyMs: 0, mode: 'passthrough' }
What's Next
- Protect & Unprotect — Use the core APIs
- Development vs Production — Understand the two modes