Skip to content

@happ-integ/integ-api ​

Клиент для Happ Integ API.

Установка ​

bash
pnpm add @happ-integ/integ-api

Использование ​

Инициализация ​

typescript
import { IntegApiClient } from "@happ-integ/integ-api";

const api = new IntegApiClient("https://api.integ.happ.tools", env.INTEG_API_TOKEN);

Интеграции ​

typescript
// Создать или обновить интеграцию
const integration = await api.upsertIntegration("sofa");

// Получить все интеграции
const integrations = await api.getIntegrations();

Credentials ​

typescript
// Получить credentials
const creds = await api.getCredentials("sofa");

// Установить credentials
await api.setCredentials("sofa", {
	NETHUNT_API_KEY: "xxx",
	NETHUNT_EMAIL: "xxx",
});

// Удалить credentials
await api.deleteCredentials("sofa");

Handlers ​

typescript
// Получить handlers
const handlers = await api.getHandlers("sofa");

// Создать handler
const handler = await api.createHandler("sofa", {
	name: "init",
	event: "sofa/init",
	description: "Initialize integration",
});

// Обновить handler
await api.updateHandler("sofa", "init", {
	description: "Updated",
});

// Удалить handler
await api.deleteHandler("sofa", "init");

Логирование ​

typescript
// Получить логи
const logs = await api.getLogs("sofa");

// Фильтр
const errorLogs = await api.getLogs("sofa", {
	level: "error",
	limit: 100,
});

API ​

IntegApiClient ​

typescript
new IntegApiClient(apiUrl: string, accessToken: string)

Методы Интеграции ​

upsertIntegration(name): Promise<Integration> ​

getIntegrations(): Promise<Integration[]> ​

Методы Credentials ​

getCredentials(integrationName): Promise<Credential> ​

setCredentials(integrationName, data): Promise<Credential> ​

deleteCredentials(integrationName): Promise<void> ​

Методы Handlers ​

getHandlers(integrationName): Promise<Handler[]> ​

createHandler(integrationName, params): Promise<Handler> ​

updateHandler(integrationName, handlerName, params): Promise<Handler> ​

deleteHandler(integrationName, handlerName): Promise<void> ​

Методы Логирование ​

getLogs(integrationName, options?): Promise<any[]> ​

getLog(logId): Promise<any> ​

Типы ​

typescript
interface Integration {
	id: string;
	name: string;
	createdAt: string;
	updatedAt: string;
}

interface Credential {
	integrationName: string;
	key: string;
	encryptedValue: string;
}

interface Handler {
	integrationName: string;
	name: string;
	event: string;
	description?: string;
}

Access Token ​

Получить из настроек Integ API.

INTEG_API_TOKEN=xxxxx
INTEG_API_URL=https://api.integ.happ.tools

Когда использовать ​

  • ✅ Управление интеграциями
  • ✅ Хранение credentials
  • ✅ Centralised logging