{"id":15503,"library":"addsearch-js-client","title":"AddSearch JavaScript Client","description":"The `addsearch-js-client` package provides a JavaScript client library for interacting with the AddSearch Search API and Indexing API. It allows developers to easily integrate search functionalities like keyword search, search suggestions, and custom field autocompletion into their web applications or Node.js environments. The current stable version is 1.2.3. The package appears to have a regular release cadence, with multiple minor and patch updates released within recent months, often addressing dependency updates, security vulnerabilities, and new features like AI answers streaming. Key differentiators include its focus on a comprehensive search-as-a-service platform, offering features like fuzzy matching, configurable search operators, and specific indexing capabilities alongside standard search. It supports both browser and Node.js environments and ships with TypeScript types, ensuring type safety for TypeScript projects. The library aims to simplify the integration of complex search features into various JavaScript applications.","status":"active","version":"1.2.3","language":"javascript","source_language":"en","source_url":"git://github.com/AddSearch/js-client-library","tags":["javascript","addsearch","search","search api","autocomplete","instant search","predictive search","search suggestions","typescript"],"install":[{"cmd":"npm install addsearch-js-client","lang":"bash","label":"npm"},{"cmd":"yarn add addsearch-js-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add addsearch-js-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for making HTTP requests to the AddSearch API.","package":"axios","optional":false},{"reason":"Likely used for handling POST request payloads, especially in Node.js environments.","package":"form-data","optional":false}],"imports":[{"note":"The primary client class is exported as a default module for ESM environments. Named imports for AddSearchClient are incorrect.","wrong":"import { AddSearchClient } from 'addsearch-js-client';","symbol":"AddSearchClient","correct":"import AddSearchClient from 'addsearch-js-client';"},{"note":"For CommonJS environments, the client is available as a default export via require(). Destructuring is not applicable here.","wrong":"const { AddSearchClient } = require('addsearch-js-client');","symbol":"AddSearchClient (CommonJS)","correct":"const AddSearchClient = require('addsearch-js-client');"},{"note":"TypeScript types are shipped with the package. You can import specific types like SearchResult or SuggestionResult for stronger type checking in your applications.","symbol":"Type definitions","correct":"import AddSearchClient, { type SearchResult, type SuggestionResult } from 'addsearch-js-client';"}],"quickstart":{"code":"import AddSearchClient from 'addsearch-js-client';\n\n// Replace 'YOUR_PUBLIC_SITEKEY' with your actual 32-character AddSearch Sitekey\nconst SITEKEY = process.env.ADDSEARCH_SITEKEY ?? 'YOUR PUBLIC SITEKEY';\n\nif (SITEKEY === 'YOUR PUBLIC SITEKEY') {\n  console.warn('WARNING: Replace YOUR_PUBLIC_SITEKEY with your actual AddSearch Sitekey to make this example work.');\n}\n\n// Create client with your SITEKEY\nconst client = new AddSearchClient(SITEKEY);\n\n// Define a callback function to handle search results\nconst handleSearchResults = (res) => {\n  console.log('Search Results:', res);\n  if (res.hits && res.hits.length > 0) {\n    console.log(`Found ${res.hits.length} results. First result title:`, res.hits[0].title);\n  } else {\n    console.log('No results found for the keyword.');\n  }\n};\n\n// Execute a search query for 'keyword'\nclient.search('keyword', handleSearchResults);\n\n// Optionally, fetch search suggestions\nconst handleSuggestions = (res) => {\n  console.log('Search Suggestions:', res);\n};\nclient.suggestions('auto', handleSuggestions);\n\n// Optionally, fetch custom field autocompletion results\nconst handleAutocomplete = (res) => {\n  console.log('Autocomplete Results:', res);\n};\nclient.autocomplete('custom_fields.category', 'pro', handleAutocomplete);","lang":"typescript","description":"This quickstart initializes the AddSearch client, performs a basic keyword search, and demonstrates fetching search suggestions and custom field autocompletion results. It includes a placeholder for your AddSearch Sitekey and uses environment variables for secure key handling."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 20.0.0 or newer (e.g., using `nvm install 20` and `nvm use 20`).","message":"The package requires Node.js version 20.0.0 or higher. Older Node.js environments will fail to run the library.","severity":"breaking","affected_versions":"<1.0.0 (Implicitly, as it appeared in the metadata recently), >=1.0.0"},{"fix":"Review the `sc-11931` change in the changelog and test your POST request implementations thoroughly after upgrading to ensure compatibility with the new handling mechanism.","message":"Version 1.1.0 introduced changes to how POST request payloads are handled. Existing integrations making POST requests might require adjustments.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Upgrade to version 1.0.4 or newer to benefit from improved cookie error handling. Ensure any custom cookie management in your application correctly encodes/decodes special characters.","message":"Earlier versions (before v1.0.4) had issues with error handling when cookies contained URI-incompatible characters, potentially leading to unexpected failures or malformed requests.","severity":"gotcha","affected_versions":"<1.0.4"},{"fix":"Immediately upgrade to version 1.2.2 or later to mitigate the vulnerability.","message":"A security vulnerability (CVE-2026-25639) was addressed in version 1.2.2. Older versions are susceptible.","severity":"breaking","affected_versions":"<1.2.2"},{"fix":"Immediately upgrade to version 1.2.3 or later to ensure the latest security fixes are applied.","message":"Another security vulnerability (CVE-2025-62718) was addressed in version 1.2.3, affecting internal tools and related components. Older versions are potentially vulnerable.","severity":"breaking","affected_versions":"<1.2.3"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure you are using `import AddSearchClient from 'addsearch-js-client';` for ES Modules or `const AddSearchClient = require('addsearch-js-client');` for CommonJS environments.","cause":"Attempting to use `AddSearchClient` without correctly importing or requiring it, or using the wrong import syntax for the environment (e.g., CommonJS `require` in an ESM module).","error":"ReferenceError: AddSearchClient is not defined"},{"fix":"Verify your AddSearch public sitekey is correct and provided as a string argument to the `AddSearchClient` constructor. It must be exactly 32 characters long.","cause":"The `AddSearchClient` constructor was called with an invalid, missing, or improperly formatted 32-character public sitekey.","error":"Error: Invalid Sitekey"},{"fix":"Double-check your import statement for `AddSearchClient` and ensure that `new AddSearchClient(SITEKEY)` is correctly executed before calling methods like `search`, `suggestions`, or `autocomplete`.","cause":"This typically occurs if `client` is not an instance of `AddSearchClient`, often due to an incorrect import or module loading issue, or attempting to call a method that does not exist on the client object.","error":"TypeError: client.search is not a function"}],"ecosystem":"npm"}