GithubHelp home page GithubHelp logo

useshortcut / shortcut-client-js Goto Github PK

View Code? Open in Web Editor NEW
130.0 31.0 31.0 2.21 MB

The official JavaScript client library for the Shortcut (formerly Clubhouse) REST API.

Home Page: https://useshortcut.github.io/shortcut-client-js/

TypeScript 97.95% EJS 2.05%
nodejs node shortcut shortcut-api shortcut-lib javascript api api-client javascript-client typescript

shortcut-client-js's People

Contributors

adamazing avatar adnanrhussain avatar andrewchilds avatar charpeni avatar danhawkins avatar dependabot[bot] avatar eliperkins avatar iwillig avatar j-martin avatar jeremyheiler avatar joshbeckman avatar maryjenel avatar mattietk avatar mattspitz avatar mikabytes avatar steaks avatar virgofx avatar webfella avatar ybhan avatar yordis avatar

Stargazers

 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar

shortcut-client-js's Issues

search by external ticket url or ID

I was trying to figure out how to check if there's a clubhouse ticket already associated with a github issue.

SearchStories doesn't seem to work - if I give it a github issue ID, it returns lots of unrelated results

Is there a recommended way to do this?

Missing external_links field on type "Story"

The API returns an "external_links" field on Story, but the Typescript type doesn't indicate this. Using ts-ignore allows clients to successfully access the data that is there.

Search by Pull Request

First off, thanks for the great product. We've been a use of your Product for a few years.

Very similar to #70, We'd like to be able to query for tickets based on their associated Pull Requests.

While there are workarounds (we're currently parsing the PR Description for clubhouse links), it'd be great if this were a native feature of Clubhouse's.

Our usecase is we're doing a site deploy for every incoming PR, and need to post the URL to the ticket (as an external link) so our QA team can verify features.

Improve README

Currently, the README is very sparse and doesn't provide too much information on how to get started.

We should improve this by adding information in the following outline:

  1. Header (# Clubhouse JavaScript SDK or something like that)
    • description ("A library for interacting with the Clubhouse REST API")
  2. Getting Started
    • requirements
    • install instructions
    • how to get an API token
  3. Usage
    • how the thing actually works
  4. Documentation
    • link to https://clubhouse.io/api for complete REST API documentation
    • autogenerated documentation from existing methods?

Using lib in the browser

I had some issues while trying to use the lib in the browser.

Both CRA configuration(webpack based) and a rollup based web config have issues with fetch-everywhere.

It just doesn't work.

Do you want to support browsers with this lib, or you want to limit it to node.js?

Bad request (400) when using the search API

I am using 0.4.0 and I am trying to use the search/stories endpoint, but I am getting a 400 when calling the endpoint with clubhouse-lib. If I use curl or my own python lib (based on requests) everything works fine. The only difference I can see from the request is that the Content-Length header is not set by clubhouse-lib. I might be a red herring.

client.getResource('search/stories', { query: 'owner:jm' }).then(console.log).catch(console.log);

If I can get it working I'll make a PR for it, but for now it's not working. :\

Creating repositories/branches/pull_requests

I'm looking to associate pull requests against stories (through a custom integration, because I'd like some extra control over my workflow).

Currently, it doesn't appear like the API exposes the following, which I think are necessary in order to support that:

  • Create a repository (POST /repositories?)
  • Create a branch (POST /stories/<id>/branches?)
  • Create a pull request (???)

Are those endpoints available (even if just in an unsupported way)? I'm totally willing to poke around until I figure out the endpoints 👍

New release ?

Hi!

Do you plan a new release soon?
There are some useful bug fixes, already merged in main branch (for months).

Thank you 🙏

Any guidance on using File Upload?

Both the docs and this library lack any information on File uploading. It seems to be the only route that still passes the token through as a query parameter, and the files themselves I'm unclear on if they can be urls or not. Addtionally the docs list the files as being prepended with an "@" sign, but do not explain if this is necessary or not. I was hoping to see a reference implementation here to clear it up, but sadly haven't found one. Any work you can do to make this more clear would be much appreciated!

CORS Header ‘Access-Control-Allow-Origin’ Missing Error

👋 Hi Shortcut team,

I am facing a CORS issue when using the @useshortcut/client package with a valid token. I am able to hit your API successfully via Postman and Insomnia, but when using this package on CodeSandbox I get the following error.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.app.shortcut.com/api/v3/projects. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Step to reproduce

The CodeSandbox below was created to show the issue that I am facing.

🔗 https://codesandbox.io/s/useshortcut-client-cors-error-lkde01?file=/src/App.tsx

Type StoryChange does not include new external_links property

Hi there,

I get this type error when building and trying to add a change via clubhouseClient.updateStory that includes external_links as a property, even though this works with type safety off.

Type error: Argument of type '{ external_links: any[]; }' is not assignable to parameter of type 'StoryChange'.
--

I think it's because in Types.ts there's no entry for external_links in the StoryChange type.

Thanks

pip install fails unless requets

If you don't have requests already installed you get the following

Collecting requests==2.23.0
  Using cached requests-2.23.0-py2.py3-none-any.whl (58 kB)
Collecting attrs==19.3.0
  Using cached attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting certifi==2020.4.5.2
  Using cached certifi-2020.4.5.2-py2.py3-none-any.whl (157 kB)
Collecting chardet==3.0.4
  Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting click==7.1.2
  Using cached click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting clubhouse-lib==1.0.0
  Using cached clubhouse-lib-1.0.0.tar.gz (23 kB)
    ERROR: Command errored out with exit status 1:
     command: /home/will/.virtualenvs/clubhub2/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/will/pip-install-uesiswx1/clubhouse-lib/setup.py'"'"'; __file__='"'"'/tmp/will/pip-install-uesiswx1/clubhouse-lib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/will/pip-pip-egg-info-hzuqziq0
         cwd: /tmp/will/pip-install-uesiswx1/clubhouse-lib/
    Complete output (9 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/will/pip-install-uesiswx1/clubhouse-lib/setup.py", line 6, in <module>
        import clubhouse_lib
      File "/tmp/will/pip-install-uesiswx1/clubhouse-lib/clubhouse_lib/__init__.py", line 4, in <module>
        from clubhouse_lib.client import ClubhouseClient
      File "/tmp/will/pip-install-uesiswx1/clubhouse-lib/clubhouse_lib/client.py", line 3, in <module>
        import requests
    ModuleNotFoundError: No module named 'requests'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Seeing on python 3.6 and 3.8.

This happens even if you have requests higher up in requirements.txt than clubhouse_lib.

This prevents using this library on a service like heroku where you have less control and only get one run of pip install.

Response body swallowed on API Error

If you run into an error when accessing the API, this code gets executed:

https://github.com/clubhouse/clubhouse-lib/blob/c6f62deb624c5de83d1a05d42f6ca9579ef2bb5e/src/FetchRequestParser.ts#L10-L17

It seems like ClientError would be called with response and the parsed body, but unfortunately the .catch grabs that error that's thrown, swallows it, and throws another error with a regular POJO instead.

Because the response.body has already been parsed, you can't use the response object on the error to call .json() again to get the value. .clone() also doesn't work because body was already parsed.

It would be really nice to re-throw the original error if the thing that's caught is already a ClientError instance! If you're interested in a fix like that, I would be happy to put together a PR.

The result of this is that it's hard to log the body of the error, in a case where you're using this library in a script and just want to see what went wrong!

Works only against the beta API

As can be seen when actually trying to use it and finding that it connects with missing or broken endpoints
Error: Bad Request at new ClientError ([redacted]/node_modules/clubhouse-lib/build/client_error.js:19:112) at [redacted]/node_modules/clubhouse-lib/build/FetchRequestParser.js:26:29 at processTicksAndRejections (internal/process/task_queues.js:93:5) { response: Body { url: 'https://api.clubhouse.io/api/beta/epics/76?token=redacted', status: 400, statusText: 'Bad Request', headers: Headers { _headers: [Object] }, ok: false, body: PassThrough { _readableState: [ReadableState], readable: false, _events: [Object: null prototype], _eventsCount: 4, _maxListeners: undefined, _writableState: [WritableState], writable: false, allowHalfOpen: true, _transformState: [Object] }, bodyUsed: true, size: 0,

deleteStoryComment throws error on 204 No Content

When making a valid call to deleteStoryComment(storyId, commentId), the comment is removed correctly but the client throws an error:

{ 
  url: 'https://api.clubhouse.io/api/v3/stories/192/comments/222?token=xxxx', 
  status: 204, 
  statusText: 'No Content', 
  headers: [Headers], 
  counter: 0 } 
}, 
body: {}

The issue is in src/FetchRequestParser.ts where json() is being run before status code is checked.

Getting 403 - CORS error, when using library outside of localhost.

I was playing around with clubhouse api and this library to make simple app for exporting clubhouse data to CSV. It works fine when I was testing on localhost, but when I pushed to gh-pages, all fetch requests are returning with 403 error.
https://igordmitriev.github.io/clubhouse-export/

Is there anything I can do about it?

I was trying to fork library and add { mode: 'no-cors' } to fetch. It did not help much.

Fetch API cannot load https://api.clubhouse.io/api/beta/members?token=_hidden_. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://igordmitriev.github.io' is therefore not allowed access. The response had HTTP status code 403. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Swagger schema issue

Per the swagger file, in the definitions:

"Group": {
      "description": "A Group.",
      "type": "object",
      "properties": {
         //...
       },
      "required": [
        "app_url",
        "description",
        "archived",
        "entity_type",
        "color",
        "num_stories_started",
        "mention_name",
        "name",
        "color_key",
        "num_stories",
        "num_epics_started",
        "id",
        "display_icon",
        "member_ids",
        "story_workflow_ids",
        "workflow_ids"
      ]
    }

But then when I query the API, some "required" attributes are nil. color for example is not required, because most (to not say all) of the groups have an color_key, which I guess replaces the color

I don't know when Creating a new group, but by definition, on how open-api generator build a client on top of the swagger files, it errors out because no color is present (API returns null), but the attribute is "required"

I'ts only one issue I found. I will keep posting here if I found others

Error: Error: Response for preflight has invalid HTTP status code 401(Solved)

Nodejs v14.19.1
Typescript v4.7.4
Quokkajs

Steps

  • wrote a script
  • ran with quokkajs
  • encountered issue Error: Error: Response for preflight has invalid HTTP status code 401

I just wanted to open an issue, and also post the solution I found.
This was the comment, that pointed me to the solution
axios/axios#2061 (comment)

const shortcut = new ShortcutClient(SHORTCUT_API_TOKEN, {
  adapter: require('axios/lib/adapters/http'),     // <- add this
});

🚀 Complete rewrite for v1

Good news, everyone!

We heard you about missing endpoints and outdated types. We started this library based on our internal usages, especially for the mobile application. Unfortunately, we started moving to GraphQL and this library didn't receive all the attention it should and that's unfortunate. We want this library to follow closely our latest changes so we can all profit from this library and build awesome things with the Shortcut REST API.

So, we are working on a new and updated Swagger / OpenAPI schema that will expose our endpoints and their expected types. Then, from that Swagger schema, we rewrote entirely this library so we could generate a TypeScript client and all their associated entities. No more manual updates! 👏

The Swagger file will be available here (additional changes will land soon): https://shortcut.com/api/rest/v3#Swagger-OpenAPI-file.

We're still working on some tweaks, but we will soon be ready to publish a beta version of the complete rewrite as v1. ⚠️ We'll also publish it under a new name and not clubhouse-lib as formerly known.

👀 If you are curious and are not afraid of WIP, you can have a peek on next branch.

Unable to update labels for a story

I am getting a 400 Bad request for updateStory in the following:

labels = await client.listLabels()
client.updateStory(story_id, { labels: [labels[0]] })

I was able to remove label by sending empty array labels: [] in params but I am not able to add a label
I tried passing the exact parameters as in API which is name, description, external_id, color but it doesn't make any difference

Is there something I am doing wrong?

Possibly mention webpack providing fetch-everywhere in readme

Hey Clubhouse, just a heads up / possible documentation request.

I found that in order to actually use the fetch-everywhere dependency, I had to add this to my webpack config:

  plugins: [
    ...
    new webpack.ProvidePlugin({
      'fetch': 'fetch-everywhere'
    }),
   ]

Without it, the fetch calls would fail in the browser. The fetch-everywhere docs don't mention this step either.

This might be obvious to someone who is less new to webpack projects than me, and if so, feel free to ignore. But I mention this in case you think it's worth adding to the readme for others. (Or if there's a better way to include fetch-everywhere in-browser.)

Paginator

Hi,

Could you add the recommended way how to play with paginator? Many SDKs don't offer much more than building simple requests, but they expect the SDK to facilitate a certain abstraction. You can use async generators to make remote data "native" (see example iterator in GitHub SDK https://octokit.github.io/rest.js/v18#pagination , alternatively paginator in AWS SDK - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#paginators ).

Available https://github.com/useshortcut/shortcut-client-js/tree/main/examples does not even attempt to reach that.

API response requires to the following URL, which is quite raw, and using raw API requests undermines the sense of the SDK.

Kind regards

`create` not callable from Typescript

I wanted to use this library from Typescript and it seems the typings do not allow Clubhouse.create to be called like in the example in the README.

This is my work around:

import Clubhouse from 'clubhouse-lib';
import {create} from 'clubhouse-lib';

export function generateClubHouseReport(apiKey: string) {
    const client = create(apiKey); // Compiles
    const fail = Clubhouse.create(apiKey); // Does not
}

This doesn't seem intentional.

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.