upstash / qstash-js

Message queue for serverless
https://docs.upstash.com/qstash
MIT License
158 stars 15 forks source link

List schedules API endpoint type doesn't match returned value #26

Closed jasonsilberman closed 1 year ago

jasonsilberman commented 1 year ago

Hi there,

I'm trying to list the jobs I currently have scheduled using the client API like so:

import { Client } from "@upstash/qstash";

const client = new Client({ token: process.env.QSTASH_TOKEN });

export async function listScheduledJobs() {
  return client.schedules.list();
}

The returned response looks like this (slightly redacted):

[
  {
    "scheduleId": "scd_XXXXXX",
    "cron": "0 0 * * *",
    "createdAt": 1674415617650,
    "content": {
      "header": null,
      "body": null
    },
    "destination": {
      "type": "url",
      "url": "https://example.com/messaging-endpoint"
    },
    "settings": {
      "retries": 5
    }
  }
]

This matches the return type described in your API Docs, however, it does not match the Typescript types defined in this package.

export type Schedule = {
  scheduled: string;
  cron: string;
  createdAt: number;
  content: {
    header: Record<string, string[]>;
    body: string;
  };
  destination: {
    type: "topic";
    topicId: string;
    url?: never;
  } | {
    type: "url";
    topicd?: never;
    url: string;
  };
  settings: {
    deadline?: number;
    notBefore?: number;
    retries?: number;
  };
};

The Typescript object is missing scheduleId and has a scheduled property that is missing in the returned response. Additionally, neither of the properties within content are defined as optional or possibly null, even though the API can return null.

It would be great if you could update the types defined in this package to match your API, otherwise I've got to do some not-so-nice overwriting of the types on my end.

Thanks!

chronark commented 1 year ago

👍 I'll do it tomorrow on monday, thanks for reporting this

chronark commented 1 year ago

@jasonsilberman fixed it in v0.3.4

jasonsilberman commented 1 year ago

great, thank you @chronark!