UNPKG

@intelidexer/react-native-chat-screen

Version:

A chat screen for InteliDexer based AI Agents.

125 lines (124 loc) 3.83 kB
"use strict"; // src/config/apiConfig.ts Object.defineProperty(exports, "__esModule", { value: true }); exports.validateApiConfig = exports.createApiClient = exports.ApiClient = void 0; class ApiClient { constructor(config) { this.config = config; } getHeaders() { return { 'Accept': 'application/json', 'Authorization': `Bearer ${this.config.serverToServerToken}`, }; } buildUrl(endpoint) { return `${this.config.baseUrl}/api/${this.config.local}/v2/chatbot${endpoint}`; } /** * Get user profile interests */ async getProfileInterests(page = 1, perPage = 10) { const url = this.buildUrl(`/${this.config.userId}/profile-interests`); const params = new URLSearchParams({ per_page: perPage.toString(), page: page.toString(), }); const response = await fetch(`${url}?${params}`, { method: 'GET', headers: this.getHeaders(), }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return response.json(); } /** * Get all activities */ async getActivities(page = 1, perPage = 10, sortedBy = 'start_date', sortOrder = 'desc') { const url = this.buildUrl('/activities'); const params = new URLSearchParams({ per_page: perPage.toString(), page: page.toString(), sorted_by: sortedBy, sort_order: sortOrder, }); const response = await fetch(`${url}?${params}`, { method: 'GET', headers: this.getHeaders(), }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return response.json(); } /** * Get user's agenda */ async getMyAgenda(page = 1, perPage = 10) { const url = this.buildUrl(`/${this.config.userId}/my-agenda`); const params = new URLSearchParams({ per_page: perPage.toString(), page: page.toString(), }); const response = await fetch(`${url}?${params}`, { method: 'GET', headers: this.getHeaders(), }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return response.json(); } /** * Add activity to user's agenda */ async addToAgenda(activityId) { const url = this.buildUrl(`/${this.config.userId}/activities/${activityId}/add-to-agenda`); const response = await fetch(url, { method: 'POST', headers: this.getHeaders(), }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return response.json(); } /** * Update configuration */ updateConfig(newConfig) { this.config = { ...this.config, ...newConfig }; } /** * Get current configuration */ getConfig() { return { ...this.config }; } } exports.ApiClient = ApiClient; // Default configuration factory function createApiClient(config) { return new ApiClient(config); } exports.createApiClient = createApiClient; // Helper function to validate API configuration function validateApiConfig(config) { const errors = []; if (!config.baseUrl) { errors.push('baseUrl is required'); } if (!config.local) { errors.push('local is required'); } if (!config.userId) { errors.push('userId is required'); } if (!config.serverToServerToken) { errors.push('serverToServerToken is required'); } return errors; } exports.validateApiConfig = validateApiConfig;