npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@elastic/workplace-search-node

v0.4.0

Published

Elastic Workplace Search client for Node.js

Downloads

39

Readme

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!