peerigon / clockodo

Unofficial JavaScript/TypeScript SDK for Clockodo
MIT License
20 stars 10 forks source link

[Bug] SDK's getServices results in an error @ v23.5.1 #155

Open moritzjacobs opened 5 days ago

moritzjacobs commented 5 days ago

I'm not really familiar with the inner workings of this SDK, I just noticed that something stopped working in my app, so I poked into it:

/v3/services results in { "services": […], filter: … } yet the SDK assumes paging info? See the error below.

If you change the object access to optional chaining it works:

    const remainingPages = Array.from(
      { length: paging?.countPages - 1 }, // added the ? here
      (_, index) => index + 2
    );

Repro:

v23.5.1

import { Clockodo } from "clockodo";

const clockodo = new Clockodo({
  client: {
    name: "Foo Bar",
    email: "foobar@example.com",
  },
  authentication: {
    user: "foobar@example.com",
    apiKey: "…",
  },
});

const main = async () => {
  console.log(await clockodo.getServices());
};

main();
➜  node index.js 
file:///…/node_modules/clockodo/dist/lib/api.js:168
            const remainingPages = Array.from({ length: paging.countPages - 1 }, (_, index) => index + 2);
                                                               ^

TypeError: Cannot read properties of undefined (reading 'countPages')
    at Api.getPagesStreaming_1 (file:///…/node_modules/clockodo/dist/lib/api.js:168:64)
    at getPagesStreaming_1.next (<anonymous>)
    at resume (file:///…/node_modules/clockodo/dist/lib/api.js:28:44)
    at file:///…/node_modules/clockodo/dist/lib/api.js:27:121
    at new Promise (<anonymous>)
    at i.<computed> [as next] (file:///…/node_modules/clockodo/dist/lib/api.js:27:63)
    at Api.<anonymous> (file:///…/node_modules/clockodo/dist/lib/api.js:177:97)
    at Generator.next (<anonymous>)
    at fulfilled (file:///…/node_modules/clockodo/dist/lib/api.js:4:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.14.1
florianwittmann commented 1 day ago

Thanks for reporting @moritzjacobs. We found the underlying problem and are on it to fix it. I will update you as soon as it is fixed.