algolia-sdk-patterns

Featured

Apply production-ready algoliasearch v5 patterns: singleton client, typed search, error handling, and batch operations. Use when implementing Algolia integrations, refactoring SDK usage, or establishing team coding standards. Trigger: "algolia SDK patterns", "algolia best practices", "algolia code patterns", "idiomatic algolia".

AI & Automation 2,266 stars 315 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Algolia SDK Patterns ## Overview Production-ready patterns for `algoliasearch` v5. Key architectural change from v4: all methods live on the client directly — no more `client.initIndex()`. Index name is passed as a parameter to every call. ## Prerequisites - `algoliasearch` v5+ installed - Completed `algolia-install-auth` setup - TypeScript project (patterns work in JS too, you just lose type safety) ## Instructions ### Pattern 1: Typed Singleton Client ```typescript // src/algolia/client.ts import { algoliasearch, type Algoliasearch } from 'algoliasearch'; let _client: Algoliasearch | null = null; export function getClient(): Algoliasearch { if (!_client) { const appId = process.env.ALGOLIA_APP_ID; const apiKey = process.env.ALGOLIA_ADMIN_KEY; if (!appId || !apiKey) { throw new Error( 'ALGOLIA_APP_ID and ALGOLIA_ADMIN_KEY must be set. ' + 'Get them from dashboard.algolia.com > Settings > API Keys' ); } _client = algoliasearch(appId, apiKey); } return _client; } // For testing: reset singleton export function resetClient(): void { _client = null; } ``` ### Pattern 2: Typed Search Results ```typescript // src/algolia/types.ts // Define your record shape — extends Algolia's Hit type interface Product { objectID: string; name: string; category: string; price: number; description: string; image_url: string; } // src/algolia/search.ts import { getClient } from './client'; export async function sea...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
7 months ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category