qstash-js
                                
                                
                                
                                    qstash-js copied to clipboard
                            
                            
                            
                        RFC: Update receiver.ts public method to return payload event
Changes
- renames the 
verifymethod toconstructEvent(similar to stripe's api) - now returns the payload
 
Context
This is useful to provide storngly-typed objects back to the caller. E.g. with tRPC (which validates with zod), I can pass that to an input I've defined previously:
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
  const receiver = new Receiver({
    currentSigningKey: process.env.QSTASH_CURRENT_SIGNING_KEY!,
    nextSigningKey: process.env.QSTASH_NEXT_SIGNING_KEY!,
  });
 // validates but also provides a strongly-typed `event` I can handle just how I expect.
  const event = await receiver.constructEvent(req);
  const ctx = await createTRPCContext({ req, res });
  const caller = appRouter.createCaller(ctx);
  // I've defined the `downloadArticlesOfAssociation` mutation with a zod schema for an input so that I can still rely on my own validation
  return caller.mandate.downloadArticlesOfAssociation({ event });
};
NB: The types here are missing, but it would make for a nicer DX imho
Really good idea
Let's add this along side of verify though in order to not break anyone's code
wdyt?
Also instead of returning any, we can make it generic to allow for better typing
@p6l-richard, like @chronark said it would be better to add this as an addition to verify. If you're open to making these adjustments, everything seems to be in order.