@constructor-io/constructorio-client-javascript

中文文档
2.94.1发布于 2026/11/10MITTypeScriptESM + CJS近 30 天下载 9.5万

Constructor.io JavaScript client

原始使用文档
文档目录8 节
  1. Documentation
  2. 1. Install
  3. 2. Retrieve an API key
  4. 3. Implement the Client
  5. 4. Retrieve Results
  6. AI Shopping Agent and Product Insights Agent
  7. Dispatched events
  8. Development / npm commands

Constructor.io JavaScript Client

npm MIT licensed Minzipped Size

A JavaScript client for Constructor.io. Constructor.io provides search as a service that optimizes results using artificial intelligence (including natural language processing, re-ranking to optimize for conversions, and user personalization).

This client is intended for use in a browser environment but can also be used in React Native based mobile applications. Additional information about utilization in a React Native context can be found on the Wiki. If you want a JavaScript client for server side integrations please use @constructor-io/constructorio-node

Documentation

Full API documentation is available on Github Pages

1. Install

This package can be installed via npm: npm i @constructor-io/constructorio-client-javascript. Once installed, simply import or require the package into your repository.

Alternatively, a bundled version consisting of a single JavaScript file is published within the ./dist folder on Github. This can be utilized within a browser context if hosted locally - please do not link directly to the Github hosted version.

Important: this library should only be used in a client-side context where standard HTTP request headers are populated by the client (User-Agent, Referer, etc.).

2. Retrieve an API key

You can find this in your Constructor.io dashboard. Contact sales if you'd like to sign up, or support if you believe your company already has an account.

3. Implement the Client

Once imported, an instance of the client can be created as follows:

const ConstructorioClient = require('@constructor-io/constructorio-client-javascript');

const constructorio = new ConstructorioClient({
    apiKey: 'YOUR API KEY',
});

4. Retrieve Results

After instantiating an instance of the client, seven modules will be exposed as properties to help retrieve data or send behavioral events: search, browse, autocomplete, recommendations, quizzes, agent, and tracker.

AI Shopping Agent and Product Insights Agent

  • agent retrieves AI Shopping Agent (ASA) results as a stream.
  • agent.pia retrieves Product Insights Agent (PIA) questions and answers.
  • tracker has the trackAgent* methods for ASA events and the trackProductInsightsAgent* methods for PIA events.

Note:

  1. The assistant namespace is deprecated. Use agent instead.

  2. agent receives results through the browser EventSource interface. React Native does not include EventSource. If you use agent in React Native, add an EventSource polyfill.

Dispatched events

Modules may dispatch custom events on the browser window with response data when a request has been completed. The event name follows the following structure: cio.client.[moduleName].[methodName].completed. Example consuming code can be found below:

window.addEventListener('cio.client.search.getSearchResults.completed', (event) => {
  // `event.detail` will be response data
}, false);

Development / npm commands

npm run prepare       # one-time after cloning: install husky git hooks (pre-push lint)
npm run lint          # run lint on source code and tests
npm run test          # run tests
npm run coverage      # run tests and serves coverage reports from localhost:8081
npm run docs          # output documentation to `./docs` directory

npm version <patch|minor|major> --ignore-scripts=false   # bump version (see note below)

Note: .npmrc sets ignore-scripts=true for supply-chain safety, so lifecycle scripts do not run automatically. This affects two workflows:

  • husky git hooks: run npm run prepare once after cloning to enable the pre-push lint hook.
  • npm version: the version lifecycle script (which regenerates src/version.js, docs, and the ./dist bundle and stages them into the release commit) is skipped. Always pass --ignore-scripts=false when bumping the version so these artifacts are regenerated.

版本与发布记录

@constructor-io/constructorio-client-javascript 共发布 274 个版本,首次发布于 2019/09/21;过去 12 个月发布了 42 个版本。

版本发布日期距今
2.94.1latest2026/11/10今天
2.94.02026/10/021 个月前
2.93.12026/09/141 个月前
2.93.02026/08/282 个月前
2.92.02026/08/282 个月前
2.91.12026/08/252 个月前

其他发布通道:beta → 2.30.0-beta.0。

关于 @constructor-io/constructorio-client-javascript 的常见问题

@constructor-io/constructorio-client-javascript 是什么?

Constructor.io JavaScript client

如何安装 @constructor-io/constructorio-client-javascript?

在项目目录运行 npm install @constructor-io/constructorio-client-javascript,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@babel/runtime(^7.19.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@constructor-io/constructorio-client-javascript 支持 TypeScript 吗?

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

@constructor-io/constructorio-client-javascript 支持 ESM 还是 CommonJS?

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

@constructor-io/constructorio-client-javascript 可以商用吗?

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

@constructor-io/constructorio-client-javascript 的下载量有多少?

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

@constructor-io/constructorio-client-javascript 还在维护吗?

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