objective-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

Objective TypeScript SDK

The Objective TypeScript SDK provides a powerful and easy-to-use interface for interacting with the Objective API, allowing you to manage object stores and indexes efficiently. This document outlines the installation process, initialization of the Objective class, and details the available methods for working with object stores and indexes.

To get an API Key, visit our website.

To view our official API documentation, visit our docs.

Installation

To install the SDK, run the following command in your project directory:

npm install objective-sdk

or if you use yarn:

yarn add objective-sdk

or if you use pnpm:

pnpm install objective-sdk

Initialization

To start using the SDK, you need to initialize the Objective class. This requires an API key which can be provided directly or through environment variables.

import { ObjectiveClient } from "objective-sdk"

const objective = new ObjectiveClient({
  apiKey: "Your API Key Here",
  baseURL: "https://api.objective.inc/v1", // Optional
  timeout: 600000, // Optional, in milliseconds
  maxRetries: 2, // Optional
  defaultHeaders: { "Custom-Header": "Value" }, // Optional
})

Object Store Methods

The SDK provides methods to interact with object stores, allowing you to create, find, get, delete, upsert, and partially update objects.

objective.objectStore.create(object)
objective.objectStore.getObjects({
  limit: 20, // Amount of results to return - optional. Default is 10.
  cursor: "1234", // A base64 encoded, URL-safe string to navigate to the next or previous page. - optional
  include_metadata: true, // - Includes metadata, such as the count of total objects in the object store. - optional. Default is false.
  include_object: true, // Include the object in the response. - optional. Default is false.
})
objective.objectStore.getObject(objectId)
objective.objectStore.delete(objectId)
objective.objectStore.upsert(objectId, object)
objective.objectStore.updatePartial(objectId, object)

Index Methods

The SDK also provides methods to manage indexes, including creating indexes, finding multiple indexes, and retrieving or deleting a single index.

objective.indexes.create({
  configuration: {
    index_type: {
      name: "multimodal",
    },
    fields: {
      searchable: {
        allow: ["title", "description"],
        deny: ["image_url"],
      },
      crawlable: {
        allow: ["image_url"],
      },
      filterable: {
        allow: ["price"],
      },
      types: {
        price: "float",
      },
    },
  },
})
objective.indexes.getIndexes({
  limit: 20, // Amount of indexes to return - optional. Default is 10.
  cursor: "1234", // A base64 encoded, URL-safe string to navigate to the next or previous page. - optional
})
objective.indexes.index.status(indexId)
objective.indexes.index.delete(indexId)
objective.indexes.index.search(indexId, {
  query: "Shirts", // Required
  limit: 10, // Optional. Default is 10.
  filter_query: "", // Optional.
  offset: 10, // Optional. Default is 0.
  object_fields: "name,description", // Optional
})

Conclusion

The Objective TypeScript SDK simplifies the process of interacting with the Objective API, providing a comprehensive set of methods for managing object stores and indexes. By following the installation and initialization steps outlined above, you can quickly integrate Objective's capabilities into your TypeScript applications.

Readme

Keywords

none

Package Sidebar

Install

npm i objective-sdk

Weekly Downloads

52

Version

1.0.7

License

ISC

Unpacked Size

181 kB

Total Files

8

Last publish

Collaborators

  • lancehasson
  • jodaiber
  • davidpobjective