Code Monkey home page Code Monkey logo

sdk-js's People

Contributors

benhinchley avatar chidojiro avatar dependabot[bot] avatar dhowden avatar jasonberry avatar jkaho avatar jonathaningram avatar justinkoke avatar mish15 avatar sajari-ci avatar sampotts avatar tbillington avatar tuanddd avatar wwalser avatar zlatanpham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdk-js's Issues

add explicit error message on permission denied

When getting permission denied (usually because of a search from an unauthorised domain) we should be explicit in letting the user know, as this is not really error but more a misconfiguration.

Refactor fieldFilter to remove constants.

Instead allow things like:

fieldFilter('event', '=', '100')

Could we even make this:

fieldFilter('event =', '100')

The full set of operations would include ^ (prefix), $ (suffix), ~ (contains), !~ (not contains).

Add formatToken function

Add function to generate a usable url from a token so users can use them easier

function formatToken(token) {
  return 'https://www.sajari.com/token/' + token
}

Add write functions to API

Currently only the read functions are supported. Need to add the writes:

  • add other params to query module where applicable
  • add convenience functions if we don't want to use attr()
  • add handlers
  • add warning if basicauth is not set for write requests

doc: update sort method to require array

I'm not really sure that it concern of the JS SDK. but...
When I add sorting to Query like that:

import { Client, Query, Tracking, fieldFilter, anyFilters, allFilters, sort } from 'sajari';

const client = new Client('projectName', 'collectionName');
const query = new Query();
const titleFilter = fieldFilter('title', '~', searchText);
const descriptionFilter = fieldFilter('body', '~', searchText);
const publishFilter = fieldFilter('publishedStatus', '=', 'true');
const sortQuery = sort('title'); // or any other field, or with '-'

query.sort(sortQuery);
query.limit(searchResultsLimit);
query.offset(searchOffset);
query.filter(allFilters([searchQuery, publishFilter]));

client.search(query, new Tracking(), (err, res) => {
...
});

it returns me 400 status code with the message:

Error during search: could not unmarshal request into proto: json: cannot unmarshal object into Go value of type []json.RawMessage

request to the API looks like that:

{
  "request": {
    "searchRequest": {
      "limit": 10,
      "sort": {
        "field": "title",
        "order": "ASC"
      },
      "offset": 0,
      "filter": {
        "combinator": {
          "filters": [
            {
              "combinator": {
                "filters": [
                  {
                    "field": {
                      "field": "title",
                      "value": {
                        "single": ""
                      },
                      "operator": "CONTAINS"
                    }
                  },
                  {
                    "field": {
                      "field": "body",
                      "value": {
                        "single": ""
                      },
                      "operator": "CONTAINS"
                    }
                  }
                ],
                "operator": "ANY"
              }
            },
            {
              "field": {
                "field": "publishedStatus",
                "value": {
                  "single": "true"
                },
                "operator": "EQUAL_TO"
              }
            }
          ],
          "operator": "ALL"
        }
      }
    },
    "tracking": {
      "sequence": 0,
      "query_id": "hjcbokdf7xgmfqhh",
      "data": {
        "sjID": "1502790432164.658192"
      }
    }
  },
  "metadata": {
    "project": [
      "projectName"
    ],
    "collection": [
      "collectionName"
    ],
    "user-agent": [
      "sdk-js-0.19.0"
    ]
  }
}

Without sorting everything is ok.

Creating a query with string argument fails

Creating a query object from api.query fails when a string is used as an argument.

query = api.query("foo");

This does not immediately fail, but causes errors when functions are called on the query object, such as filter, or maxresults.

Add support for timeouts

Currently, no function which makes API request(s) have support for timeout leading to a clogged event loop for clients until the gateway itself sends a 504 Gateway Timeout (which understandably is pretty high for most use cases.)

Ideally, clients should be able to specify the maximum timeout they are willing to tolerate when calling functions from the library which make API requests.

Add support for promises

Following convention, the SDK could check if the success / callback functions were passed down, or else return a Promise.

This makes the sdk super useful on node.js as well.

On a side-note, in node the convention is to have a callback passed as a fn(error, result), and as the last param. Since this doesn't adhere to that, we can't use methods like bluebird.promisifyAll to convert this callback based lib to a promise based one.

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.