Git Product home page Git Product logo

push-api-client.js's Introduction

@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.

push-api-client.js's People

Contributors

renovate[bot] avatar actions-user avatar olamothe avatar y-lakhdar avatar louis-bompart avatar dmbrooke avatar cyb3rjerry avatar jplachance avatar jdevost avatar jonapich avatar

Stargazers

Sergey Korsik avatar  avatar Tom Carrio avatar Michael Beemer avatar

Watchers

James Cloos avatar  avatar Felix Perron-Brault avatar  avatar Kostas Georgiou avatar  avatar

push-api-client.js's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: renovate.json
Error type: The renovate configuration file contains some invalid settings
Message: Invalid schedule: 'Invalid schedule: Failed to parse "schedule:earlyMonday"'

[Bug]: Support 429 too many requests in the SDK

Current Behavior

Currently we will get an error when the API starts sending 429 (with a retry period).

Expected Behavior

Automatically wait the RETRY_period specified by the API

Steps To Reproduce

No response

Environment

Node Version
OS Version
...

Debug logs

No response

Anything else?

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.