@coveo/push-api-client
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

@coveo/push-api-client.js

Coveo Push API client

Installation

npm i @coveo/push-api-client

Features

  • Upload data to both Push and Catalog sources
  • Pre-push document validation
  • Automatic custom field creation
  • Full catalog upload and incremental document update
  • Optimized for large payload uploads

Usage

import {PushSource, DocumentBuilder} from '@coveo/push-api-client';

async function main() {
  const source = new PushSource('my_api_key', 'my_coveo_organization_id');

  const myDocument = new DocumentBuilder(
    'https://my.document.uri',
    'My document title'
  ).withData('these words will be searchable');

  await source.addOrUpdateDocument('my_source_id', myDocument);
}

main();

You can also upload your data into a catalog source

async function main() {
  const source = new CatalogSource('my_api_key', 'my_coveo_organization_id');
  await source
    .batchStreamDocumentsFromFiles('my_source_id', ['path/to/file_or_folder'])
    .batch();
}

main();

See more examples in the ./samples folder.

Proxy configuration

You can use the HTTPS_PROXY or https_proxy environment variable for proxy configuration. Read more about it here.

Exponential backoff retry configuration

By default, the SDK leverages an exponential backoff retry mechanism. Exponential backoff allows for the SDK to make multiple attempts to resolve throttled requests, increasing the amount of time to wait for each subsequent attempt. Outgoing requests will retry when a 429 status code is returned from the platform.

The exponential backoff parameters are as follows:

  • retryAfter - The amount of time, in milliseconds, to wait between throttled request attempts.

    Optional, will default to 5,000.

  • maxRetries - The maximum number of times to retry throttled requests.

    Optional, will default to 10.

  • timeMultiple - The multiple by which to increase the wait time between each throttled request attempt.

    Optional, will default to 2.

You may configure the exponential backoff that will be applied to all outgoing requests. To do so, specify a PlatformOptions object when creating either a CatalogSource or PushSource object:

const catalogSource = new CatalogSource(
  'my_api_key',
  'my_coveo_organization_id',
  {maxRetries: 10, retryAfter: 2000, timeMultiple: 3}
);
const pushSource = new PushSource(
  'my_other_api_key',
  'my_other_coveo_organization_id',
  {maxRetries: 3, retryAfter: 600000}
);

By default, requests will retry a maximum of 10 times, waiting 5 seconds after the first attempt, with a time multiple of 2 (which will equate to a maximum execution time of roughly 1.5 hours).

Local development

  • npm i
  • Copy env.sample to .env, and replace the variables with proper values.
  • npm run dev to compile and run ./src/localtest.ts.
  • npm run test for unit tests.

Commit

Use npm run commit to get a properly formatted commit message which will help control the versioning and CHANGELOG generation.

Release

Run Github action named release, which will bump version, tag and publish to npm.

Readme

Keywords

none

Package Sidebar

Install

npm i @coveo/push-api-client

Weekly Downloads

5,595

Version

4.0.1

License

Apache-2.0

Unpacked Size

417 kB

Total Files

210

Last publish

Collaborators

  • sallain
  • aboissinot
  • mmitiche
  • jkatofsky
  • agong-coveo
  • pixhel
  • ndlr
  • npmcoveo
  • camarois
  • lcoolen
  • coveo-organization
  • coveoit
  • olamothe
  • sssayegh
  • ylakhdar