objective-sdk
v1.0.11
Published
This is the official Typescript library for the Objective APIs. It provides convenient methods for using Objective's APIs.
Downloads
1,091
Keywords
Readme
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.
Create an Object
objective.objectStore.create(object)
Find Multiple Objects
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.
})
Get a Single Object
objective.objectStore.getObject(objectId)
Delete a Single Object
objective.objectStore.delete(objectId)
Upsert an Existing Object
objective.objectStore.upsert(objectId, object)
Partially Update an 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.
Create an 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",
},
},
},
})
Find Multiple Indexes
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
})
Retrieve the Status for a Single Index
objective.indexes.index.status(indexId)
Delete an Index
objective.indexes.index.delete(indexId)
Search an Index
objective.indexes.index.search(indexId, {
query: "Shirts", // Required
limit: 10, // Optional. Default is 10.
filter_query: "", // Optional.
ranking_expr: "", // 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.