Code Monkey home page Code Monkey logo

workplace-search-node's Introduction

⚠️ This client is deprecated ⚠️

As of Enterprise Search version 8.2.0, we are directing users to the new Enterprise Search Node Client and deprecating this client.

Our development effort on this project will be limited to bug fixes. All future enhancements will be focused on the Enterprise Search Node Client.

Thank you! - Elastic

CircleCI build

A first-party Node.js client for Elastic Workplace Search.

Contents


Getting started 🐣

With npm:

npm install @elastic/workplace-search-node

or clone locally:

git clone [email protected]:elastic/workplace-search-node.git
cd workplace-search-node
npm install

Usage

Create a new instance of the Elastic Workplace Search Client with your access token:

const WorkplaceSearchClient = require('@elastic/workplace-search-node')
const accessToken = '' // your access token
const client = new WorkplaceSearchClient(accessToken)

Change API endpoint

const client = new WorkplaceSearchClient(
  accessToken,
  'https://your-server.example.com/api/ws/v1'
)

Indexing Documents

This example shows how to use the indexDocuments method:

const contentSourceKey = '' // your content source key
const documents = [
  {
    id: 1234,
    title: '5 Tips On Finding A Mentor',
    body:
      'The difference between a budding entrepreneur who merely shows promise and one who is already enjoying some success often comes down to mentoring.',
    url: 'https://www.shopify.com/content/5-tips-on-finding-a-mentor'
  },
  {
    id: 1235,
    title: 'How to Profit from Your Passions',
    body:
      'Want to know the secret to starting a successful business? Find a void and fill it.',
    url: 'https://www.shopify.com/content/how-to-profit-from-your-passions'
  }
]

client
  .indexDocuments(contentSourceKey, documents)
  .then(results => {
    // handle results
  })
  .catch(error => {
    // handle error
  })

Destroying Documents

const contentSourceKey = '' // your content source key
const documentIds = [1234, 1235]

client
  .destroyDocuments(contentSourceKey, documentIds)
  .then(destroyDocumentsResults => {
    // handle destroy documents results
  })
  .catch(error => {
    // handle error
  })

Listing all permissions

const contentSourceKey = '' // your content source key
const pageParams = { currentPage: 2, pageSize: 20 } // optional argument

client
  .listAllPermissions(contentSourceKey, pageParams)
  .then(response => {
    // handle response
  })
  .catch(error => {
    // handle error
  })

Getting user permissions

const contentSourceKey = '' // your content source key
const user = 'enterprise_search' // username

client
  .getUserPermissions(contentSourceKey, user)
  .then(response => {
    // handle response
  })
  .catch(error => {
    // handle error
  })

Updating user permissions

const contentSourceKey = '' // your content source key
const user = 'enterprise_search' // username
const permissions = { permissions: ['permission1', 'permission2'] } // permissions to assign to the user

client
  .updateUserPermissions(contentSourceKey, user, permissions)
  .then(response => {
    // handle response
  })
  .catch(error => {
    // handle error
  })

Adding user permissions

const contentSourceKey = '' // your content source key
const user = 'enterprise_search' // username
const permissions = { permissions: ['permission2'] } // permissions to add to the user

client
  .addUserPermissions(contentSourceKey, user, permissions)
  .then(response => {
    // handle response
  })
  .catch(error => {
    // handle error
  })

Remove user permissions

const contentSourceKey = '' // your content source key
const user = 'enterprise_search' // username
const permissions = { permissions: ['permission2'] } //permissions to remove from the user

client
  .removeUserPermissions(contentSourceKey, user, permissions)
  .then(response => {
    // handle response
  })
  .catch(error => {
    // handle error
  })

Running tests

Run tests via npm:

$ npm test

FAQ 🔮

Where do I report issues with the client?

If something is not working as expected, please open an issue.

Contribute 🚀

We welcome contributors to the project. Before you begin, a couple notes...

License 📗

Apache 2.0 © Elastic

Thank you to all the contributors!

workplace-search-node's People

Contributors

delvedor avatar goodroot avatar jasonstoltz avatar richkuz avatar tehsven avatar yakhinvadim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

workplace-search-node's Issues

search function missing

I noticed that the client has no search function. It could for example look like this:
client.search(contentSourceKey, query, options)

Is there a reason it is missing? Will it be implemented in future versions?

Add a linter

Other than the unit/integration test, use a linter drastically improve the code and helps catch errors in advance, it also makes easier review community pull request :)

I would recommend standardjs, but any linter would work :)

Avoid using a lockfile

Lockfiles are very useful when working with big applications, but are not published on npm.
Which means that your users, you, and your CI, might use different versions of dependencies if you use lockfiles.

As a rule of thumb, I would suggest to always avoid the use of lockfiles on modules that will be published on npm in the future :)

Avoid using request module

The request module went in maintenance mode, therefore it would be better to move to an actively maintained module.
Given that you support a pure promise API and you don't need to support callbacks, I would recommend got, it offers the same features with a native promise API.

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.