Socket
Socket
Sign inDemoInstall

@sajari/sdk-node

Package Overview
Dependencies
143
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @sajari/sdk-node

> Node.js SDK for Sajari APIs


Version published
Weekly downloads
254
increased by46.82%
Maintainers
4
Created
Weekly downloads
 

Readme

Source

@sajari/sdk-node

Node.js SDK for Sajari APIs

Getting Started

Installation

This is a Node.js module available through the npm registry. It can be installed using the npm or yarn command line tools.

npm install @sajari/sdk-node --save # yarn add @sajari/sdk-node

Tests

npm install
npm test

Examples

Creating a schema

const { Client, FieldMode, schema } = require("@sajari/sdk-node");

// create client
const client = new Client("<project>", "<collection>", {
	key: "<key from console>",
	secret: "<secret from console>"
});

const fields = [
	schema.field.boolean("my-boolean-field", {
		// Set this field to be required.
		// FieldMode options are defined here,
		// https://sajari-sdk-node.netlify.com/enums/fieldmode.html
		mode: FieldMode.Required 
	}),
	schema.field.string("text")
]

client.schema().add(...fields).catch(error => {/* handle error ... */})

Adding a record

const { Client } = require("@sajari/sdk-node");

// create client
const client = new Client("<project>", "<collection>", {
	key: "<key from console>",
	secret: "<secret from console>"
});

// get the pipeline client
const pipeline = client.pipeline("<your pipeline name>")

const record = {
	"my-boolean-field": true,
	"text": "hello"
}

pipeline.add({}, record)
	.then(key => {/* handle key ... */})
	.catch(error => {/* handle error ... */})

Performing a search

const { Client, DefaultSession, TrackingType } = require("@sajari/sdk-node");

const client = new Client("<project>", "<collection>", {
	key: "<key from console>",
	secret: "<secret from console>"
});

const session = new DefaultSession(TrackingType.None);
const pipeline = client.pipeline("<your pipeline name>");
const values = { q: "hello" };

pipeline.search(values, session.next(values))
	.then(response => {/* handle response ... */})
	.catch(error => {/* handle error ... */})

License

MIT

FAQs

Last updated on 28 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc