Code Monkey home page Code Monkey logo

sdk-js's People

Contributors

arnaudweyts avatar davidcodifly avatar dependabot-preview[bot] avatar dependabot[bot] avatar geoffreydhuyvetters avatar jorensaey avatar jorensaeytl avatar kemosabert avatar lorgan3 avatar lowiebenoot avatar mikeverf avatar mrtus avatar nickwaelkens avatar rathesdot avatar teamleader-iac[bot] avatar timdegroote avatar yorickh avatar

Stargazers

 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

sdk-js's Issues

Node 14: ReferenceError: regeneratorRuntime is not defined

I'm trying to use this package on Node server. After doing npm i @teamleader/api and creating a file with the simplest piece of code:

import API from '@teamleader/api';

When trying to run it I'm getting the following error:

<project_folder>\node_modules\@teamleader\api\dist\cjs\utils\getResponseData.js:17
  regeneratorRuntime.mark(function _callee(response) {
  ^

ReferenceError: regeneratorRuntime is not defined
    at <project_folder>\node_modules\@teamleader\api\dist\cjs\utils\getResponseData.js:17:3
    at Object.<anonymous> (<project_folder>\node_modules\@teamleader\api\dist\cjs\utils\getResponseData.js:46:2)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (<project_folder>\node_modules\@teamleader\api\dist\cjs\utils\checkStatus.js:8:47)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)

Any info on how to solve this?

RFC: pagination

What

How do we handle loading all results of a specific API request via sdk-js?

In some specific cases, we want to be able to fetch all the results without handling the pagination logic yourself or via the UI.

For example, the case of the month view in the calendar. We would need to see all the events there, paginating them wouldn't work in this case.

Situation

Currently, we can receive a maximum of 100 items in 1 request.

We don't have any pagination info in the response, so we would need to fetch the next page sequentially until there the amount of data is smaller than the maximum (could be a lot better).

Proposal

It doesn't make sense to solve this with a plugin since plugins have a data => data signature.

I would propose to move plugins into a general options object and allow for the option to add a fetchAll (feel free to suggest another name).

@nickwaelkens I don't think we can tackle this param in any other way (see discussion in the previous RFC)

Meaning we would need to move the plugins into this object as well.

example:

events.list({ filter: '...' }, { plugins: { response: normalize }, fetchAll: true });

Passing this option would indicate that sdk-js needs to make multiple requests if required & respect the provided plugins.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/check-types.yaml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
.github/workflows/create-tag.yaml
  • peter-murray/workflow-application-token-action v2
  • actions/checkout v4
  • rickstaa/action-contains-tag v1
  • softprops/action-gh-release v1
  • mikepenz/release-changelog-builder-action v4.1.0
  • softprops/action-gh-release v1
.github/workflows/lint.yaml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
.github/workflows/test.yaml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3

Oauth2

Hi,

maybe a newbe question, but how do I autorize my app with teamleader using OAuth2?

Bouke

RFC: side loading

What?

How do we include side loading in sdk-js?

Proposal

This proposal will introduce breaking changes.

Using the example of https://teamleader-engineering.blogin.co/single-post.php?id=54221

Using the projects.list endpoint, triggering a customer side-load.

endpoint:
https://api.teamleader.eu/projects.list?include=customer

result:

{
    "data": [
        {
            "id": "8ef941ad-214f-0721-b818-f678e53a1714",
            "title": "New company website",
            "status": "active",
            "starts_on": "2016-02-04",
            "customer": {
                "type": "company",
                "id": "b5d55370-f649-0bfb-9010-03132f9eaae8"
            }
        },
        {
            "id": "58bcd4da-f68e-053e-9b1c-3cb6c5796867",
            "title": "New company website",
            "status": "active",
            "starts_on": "2016-02-04",
            "customer": {
                "type": "company",
                "id": "0709fc3e-e918-00d5-a113-ba00a33102ca"
            },
        },
        {
            "id": "795be9dd-ee91-070e-b212-5bf5cb1f57d3",
            "title": "azerty",
            "status": "active",
            "starts_on": "2018-09-13",
            "customer": {
                "type": "contact",
                "id": "29c7a647-bbaf-0807-9722-233e34891f11"
            },
        }
    ],
    "includes": {
        "company": [
            {
                "id": "0709fc3e-e918-00d5-a113-ba00a33102ca",
                "name": "Peterson Paper",
            },
            {
                "id": "b5d55370-f649-0bfb-9010-03132f9eaae8",
                "name": "Summers Digital Ltd",
            }
        ],
        "contact": [
            {
                "id": "29c7a647-bbaf-0807-9722-233e34891f11",
                "first_name": "Barry",
                "last_name": "Green",
            },
        ]
    }
}

1 / Triggering a side-load

edited after reading #31 (comment)

We would pass include as the first parameter in the actual function call

projects.list({ include: 'customer' }, { response: normalize });

with extra param

projects.list({ filter: { status: 'active' },  include: 'customer' }, { response: normalize });

include can be a string (1 include) or an array of strings (multiple includes).

2 / Parsing the result

We can handle the way the result is parsed with plugins
I think we should allow for 2 options

2.1 / Return the data normalized (normalize plugin)

Normalize all data under within the specific domain (key / value).

We would need to change the normalize plugin a bit to achieve this output.

{
    "projects": {
        "8ef941ad-214f-0721-b818-f678e53a1714": {
            "id": "8ef941ad-214f-0721-b818-f678e53a1714",
            "title": "New company website",
            "status": "active",
            "starts_on": "2016-02-04",
            "customer": {
                "type": "company",
                "id": "b5d55370-f649-0bfb-9010-03132f9eaae8"
            }
        },
        "58bcd4da-f68e-053e-9b1c-3cb6c5796867": {
            "id": "58bcd4da-f68e-053e-9b1c-3cb6c5796867",
            "title": "New company website",
            "status": "active",
            "starts_on": "2016-02-04",
            "customer": {
                "type": "company",
                "id": "0709fc3e-e918-00d5-a113-ba00a33102ca"
            },
        },
        "795be9dd-ee91-070e-b212-5bf5cb1f57d3": {
            "id": "795be9dd-ee91-070e-b212-5bf5cb1f57d3",
            "title": "azerty",
            "status": "active",
            "starts_on": "2018-09-13",
            "customer": {
                "type": "contact",
                "id": "29c7a647-bbaf-0807-9722-233e34891f11"
            },
        }
    },
    "companies": {
        "0709fc3e-e918-00d5-a113-ba00a33102ca": {
            "id": "0709fc3e-e918-00d5-a113-ba00a33102ca",
            "name": "Peterson Paper",
        },
        "b5d55370-f649-0bfb-9010-03132f9eaae8": {
            "id": "b5d55370-f649-0bfb-9010-03132f9eaae8",
            "name": "Summers Digital Ltd",
        }
    },
    "contacts": {
        "29c7a647-bbaf-0807-9722-233e34891f11": {
            "id": "29c7a647-bbaf-0807-9722-233e34891f11",
            "first_name": "Barry",
            "last_name": "Green",
        }
    }
}

Issue here, the endpoint returns company / contact instead of companies / contacts in the includes key. I could easily extract projects from the domain name.

This would allow destructuring the received data from the response

const { projects, contacts, companies } = await projects.list(undefined, { include: 'customer', plugins: { response: normalize } });

// everything byId.

Changing the plugin would also mean you'd need to change the destructuring if you don't use any side loading.

const { projects } = await projects.list();

Question:

  • How do we handle the singular/plural issue?

2.2 / Return the data merged (merge plugin)

The merge plugin would create this output:

{
    "data": [
        {
            "id": "8ef941ad-214f-0721-b818-f678e53a1714",
            "title": "New company website",
            "status": "active",
            "starts_on": "2016-02-04",
            "customer": {
                "type": "company",
                "id": "b5d55370-f649-0bfb-9010-03132f9eaae8",
                "name": "Summers Digital Ltd"
            }
        },
        {
            "id": "58bcd4da-f68e-053e-9b1c-3cb6c5796867",
            "title": "New company website",
            "status": "active",
            "starts_on": "2016-02-04",
            "customer": {
                "type": "company",
                "id": "0709fc3e-e918-00d5-a113-ba00a33102ca",
                "name": "Peterson Paper"
            }
        },
        {
            "id": "795be9dd-ee91-070e-b212-5bf5cb1f57d3",
            "title": "azerty",
            "status": "active",
            "starts_on": "2018-09-13",
            "customer": {
                "type": "contact",
                "id": "29c7a647-bbaf-0807-9722-233e34891f11",
                "first_name": "Barry",
                "last_name": "Green"
            }
        }
    ]
}

I would keep the types in there for rendering purposes on the FE.

Question:

  • Do we normalize the root level, or keep the response structure (array)? Is this the output we should generate by combining merge & normalize plugin?
{
    "data": {
        "8ef941ad-214f-0721-b818-f678e53a1714": {
            "id": "8ef941ad-214f-0721-b818-f678e53a1714",
            "title": "New company website",
            "status": "active",
            "starts_on": "2016-02-04",
            "customer": {
                "type": "company",
                "id": "b5d55370-f649-0bfb-9010-03132f9eaae8",
                "name": "Summers Digital Ltd"
            }
        },
        "58bcd4da-f68e-053e-9b1c-3cb6c5796867": {
            "id": "58bcd4da-f68e-053e-9b1c-3cb6c5796867",
            "title": "New company website",
            "status": "active",
            "starts_on": "2016-02-04",
            "customer": {
                "type": "company",
                "id": "0709fc3e-e918-00d5-a113-ba00a33102ca",
                "name": "Peterson Paper"
            },
        },
        "795be9dd-ee91-070e-b212-5bf5cb1f57d3": {
            "id": "795be9dd-ee91-070e-b212-5bf5cb1f57d3",
            "title": "azerty",
            "status": "active",
            "starts_on": "2018-09-13",
            "customer": {
                "type": "contact",
                "id": "29c7a647-bbaf-0807-9722-233e34891f11",
                "first_name": "Barry",
                "last_name": "Green"
            },
        }
    }
}

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.