@cimulate/search-sdk

中文文档
2.0.0发布于 2026/06/04MITTypeScriptESM + CJS近 30 天下载 2845

A lightweight API client SDK for Cimulate Search functionality

原始使用文档
文档目录9 节
  1. Features
  2. Why Fetch?
  3. Installation
  4. Quick Start
  5. API Methods
  6. Search Examples
  7. Facet, Suggestion, and Rerank Examples
  8. Session and Event Management
  9. Error Handling

Cimulate Search API Client

TypeScript client for interacting with the Cimulate Search API (v1.4.0).

Features

  • Strongly typed request and response objects
  • Automatic retries with exponential backoff
  • Comprehensive error handling
  • Reconnection logic for handling network issues
  • Zero dependencies (uses native Fetch API)
  • Logging capabilities

Why Fetch?

This client uses the native Fetch API because it provides zero dependencies, uses modern standards, offers a promise-based interface, and is available in all modern browsers and Node.js (v18+) environments.

Installation

npm install @cimulate/search-sdk

Quick Start

import { CimulateSearchClient } from '@cimulate/search-sdk';
import { SearchRequest } from '@cimulate/search-sdk';

// Initialize with API key or token
const client = new CimulateSearchClient({
  apiKey: 'your-api-key-here',
  // OR token: 'your-bearer-token',
  baseURL: 'https://prod.search.cimulate.ai/api/v1',
  options: {
    maxRetries: 5,        // Default: 3
    baseDelay: 500,       // Default: 300ms
    timeout: 30000,       // Default: 10000ms
    enableLogging: true   // Default: false
  }
});

// Connect and verify API credentials
await client.connect();
const version = await client.getVersion();
console.log(`API Version: ${version.version}`);

// Perform a search
const results = await client.search({ query: 'running shoes' });
console.log(`Found ${results.total_hits} products`);

API Methods

The client provides methods for all Cimulate Search API endpoints:

  • getVersion(): Get the API version
  • search(request): Perform a search
  • getFacets(request): Get facet data
  • getSuggestions(request): Get search suggestions
  • rerankProducts(request): Rerank search results
  • getProductsByIds(request): Get products by IDs
  • createSession(request): Create a user session
  • getSessionById(id): Get session details
  • updateSessionById(id, request): Update a session
  • deleteSessionById(id): Delete a session
  • createEvent(sessionId, request): Create session event
  • getAllEventsBySessionId(sessionId): Get all session events
  • getEventById(sessionId, eventId): Get specific event
  • deleteEventById(sessionId, eventId): Delete event
  • getRecommendations(request): Get recommendations
  • getRecommendationsGroups(): Get available recommendation groups

Search Examples

import { SearchRequest } from '@cimulate/search-sdk';

// Simple search
const basicSearch: SearchRequest = {
  query: 'running shoes'
};

// Advanced search with filters and facets
const advancedSearch: SearchRequest = {
  query: 'running shoes',
  page: 1,
  page_size: 20,
  include_facets: true,
  range_filters: [
    {
      field: 'price',
      max: 200,
      min: 50
    }
  ],
  facet_filters: {
    category: ["shoes", "clothing"],
    brand: ["Nike", "Adidas", "Puma"],
    color: ["red", "black", "white"]
  },
  sorting_options: ["newest"],
  session_data: {
    ga_session_id: "ga-session-123",
    session_id: "user-session-123",
    sfcc_sid: "sfcc-sid-456"
  }
};

Facet, Suggestion, and Rerank Examples

// Facets request
const facetRequest = {
  query: 'running shoes',
  max_size: 10,
  range_filters: [{ field: 'price', max: 200, min: 50 }],
  facet_filters: { category: ["shoes", "clothing"] }
};

// Suggestions request
const suggestRequest = {
  query: 'run',
  size: 5
};

// Rerank request
const rerankRequest = {
  query: 'Lil Wayne',
  results: [{ productId: '448479100' }],
  referrer: 'search_page',
  pinned_ranks: { "246675600": 1 }
};

// Get products by ID
const idRequest = {
  ids: ['478942125']
};

Session and Event Management

// Create a session
const session = await client.createSession({
  data: { 
    products_in_cart: 3,
    ga_session_id: "ga-session-123",
    ga_pseudo_user_id: "ga-user-123"
  },
  metadata: { source: 'web', device: 'mobile' }
});

// Session operations
const sessionDetails = await client.getSessionById(session.id);
await client.updateSessionById(session.id, {
  data: { products_in_cart: 5 },
  metadata: { last_page: 'checkout' }
});

// Event operations
const event = await client.createEvent(session.id, {
  name: 'product_view',
  data: { product_id: '473174149', time_spent: 45 },
  metadata: { referrer: 'search' }
});
const events = await client.getAllEventsBySessionId(session.id);
await client.deleteEventById(session.id, event.id);

Error Handling

import { CimulateSearchClient } from '@cimulate/search-sdk';
import { CimulateSearchClientError, CimulateError } from '@cimulate/search-sdk';

try {
  const results = await client.search({ query: 'running shoes' });
} catch (error) {
  // If it's already one of our error types, use it directly
  if (CimulateSearchClientError.isCimulateError(error)) {
    console.error("Search client error", error.getDetailMessage());
    throw error; // Re-throw if needed
  }
}

版本与发布记录

@cimulate/search-sdk 共发布 10 个版本,首次发布于 2025/04/16;过去 12 个月发布了 2 个版本。

版本发布日期距今
2.0.0latest2026/06/045 个月前
1.3.02026/05/275 个月前
1.2.12025/10/311 年前
1.1.02025/09/241.1 年前
1.0.52025/06/031.4 年前
1.0.42025/04/161.6 年前

关于 @cimulate/search-sdk 的常见问题

@cimulate/search-sdk 是什么?

A lightweight API client SDK for Cimulate Search functionality

如何安装 @cimulate/search-sdk?

在项目目录运行 npm install @cimulate/search-sdk,或使用 pnpm add / yarn add / bun add。

@cimulate/search-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cimulate/search-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cimulate/search-sdk 可以商用吗?

@cimulate/search-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cimulate/search-sdk 的下载量有多少?

根据 npm 官方下载统计,@cimulate/search-sdk 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,845 次,日均约 95 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cimulate/search-sdk 还在维护吗?

最新版本 2.0.0 发布于 2026/06/04(5 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 2 个;首次发布于 2025/04/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。