upstash / qstash-js

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

feat: change import paths #90

Closed ogzhanolguncu closed 1 month ago

ogzhanolguncu commented 1 month ago

This PR

linear[bot] commented 1 month ago

DX-889 QStash SDK revisit/review/improve

MeshanKhosla commented 1 month ago

Looks like this does cause existing imports to be broken. Followed the Nextjs quickstart and got this after step 5.

Package path ./dist/nextjs is not exported from package 

Also getting this type error

Argument of type '(request: Request) => Promise<Response>' is not assignable to parameter of type '((request: Request) => VerifySignatureAppRouterResponse) | ((request: NextRequest) => VerifySignatureAppRouterResponse)'.
  Type '(request: Request) => Promise<Response>' is not assignable to type '(request: Request) => VerifySignatureAppRouterResponse'.
    Type 'Promise<Response>' is not assignable to type 'VerifySignatureAppRouterResponse'.
      Type 'Promise<Response>' is not assignable to type 'Promise<NextResponse<unknown>>'.
Type 'Response' is missing the following properties from type 'NextResponse<unknown>': cookies, [INTERNALS]

for

import { verifySignatureAppRouter } from "@upstash/qstash/nextjs";

async function handler(request: Request) {
  const data = await request.json();

  for (let i = 0; i < 10; i++) {
    await fetch('https://firstqstashmessage.requestcatcher.com/test', {
      method: 'POST',
      body: JSON.stringify(data),
      headers: { 'Content-Type': 'application/json' }
    });
    await new Promise(resolve => setTimeout(resolve, 500));
  }

  return Response.json({ success: true });
}

export const POST = verifySignatureAppRouter(handler);
ogzhanolguncu commented 1 month ago

Looks like this does cause existing imports to be broken. Followed the Nextjs quickstart and got this after step 5.

Package path ./dist/nextjs is not exported from package 

Also getting this type error

Argument of type '(request: Request) => Promise<Response>' is not assignable to parameter of type '((request: Request) => VerifySignatureAppRouterResponse) | ((request: NextRequest) => VerifySignatureAppRouterResponse)'.
  Type '(request: Request) => Promise<Response>' is not assignable to type '(request: Request) => VerifySignatureAppRouterResponse'.
    Type 'Promise<Response>' is not assignable to type 'VerifySignatureAppRouterResponse'.
      Type 'Promise<Response>' is not assignable to type 'Promise<NextResponse<unknown>>'.
Type 'Response' is missing the following properties from type 'NextResponse<unknown>': cookies, [INTERNALS]

for

import { verifySignatureAppRouter } from "@upstash/qstash/nextjs";

async function handler(request: Request) {
  const data = await request.json();

  for (let i = 0; i < 10; i++) {
    await fetch('https://firstqstashmessage.requestcatcher.com/test', {
      method: 'POST',
      body: JSON.stringify(data),
      headers: { 'Content-Type': 'application/json' }
    });
    await new Promise(resolve => setTimeout(resolve, 500));
  }

  return Response.json({ success: true });
}

export const POST = verifySignatureAppRouter(handler);

Yeah, sadly this change is breaking existing imports. And, I'll check nextjs import and make sure it works like this: @upstash/qstash/nextj

ytkimirti commented 1 month ago

@MeshanKhosla imports should be fixed now, if there is anything wrong ping me