diff --git a/.changeset/sour-boxes-jump.md b/.changeset/sour-boxes-jump.md new file mode 100644 index 000000000..1ccf38780 --- /dev/null +++ b/.changeset/sour-boxes-jump.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +Add additional params to the queue override diff --git a/packages/open-next/src/adapters/logger.ts b/packages/open-next/src/adapters/logger.ts index fe471e832..24a3750b7 100644 --- a/packages/open-next/src/adapters/logger.ts +++ b/packages/open-next/src/adapters/logger.ts @@ -1,4 +1,4 @@ -import { isOpenNextError } from "utils/error"; +import { isOpenNextError } from "utils/error.js"; export function debug(...args: any[]) { if (globalThis.openNextDebug) { diff --git a/packages/open-next/src/core/routing/cacheInterceptor.ts b/packages/open-next/src/core/routing/cacheInterceptor.ts index 5c1bdce85..bb8814f12 100644 --- a/packages/open-next/src/core/routing/cacheInterceptor.ts +++ b/packages/open-next/src/core/routing/cacheInterceptor.ts @@ -63,7 +63,12 @@ async function computeCacheControl( url = `${NextConfig.basePath}${url}`; } await globalThis.queue.send({ - MessageBody: { host, url }, + MessageBody: { + host, + url, + eTag: etag, + lastModified: lastModified ?? Date.now(), + }, MessageDeduplicationId: hash(`${path}-${lastModified}-${etag}`), MessageGroupId: generateMessageGroupId(path), }); diff --git a/packages/open-next/src/core/routing/util.ts b/packages/open-next/src/core/routing/util.ts index 5e15e5c54..b24f896c4 100644 --- a/packages/open-next/src/core/routing/util.ts +++ b/packages/open-next/src/core/routing/util.ts @@ -324,11 +324,11 @@ export async function revalidateIfRequired( // For some weird cases, lastModified is not set, haven't been able to figure out yet why // For those cases we add the etag to the deduplication id, it might help - const etag = headers.etag ?? headers.ETag ?? ""; + const eTag = `${headers.etag ?? headers.ETag ?? ""}`; await globalThis.queue.send({ - MessageBody: { host, url: revalidateUrl }, - MessageDeduplicationId: hash(`${rawPath}-${lastModified}-${etag}`), + MessageBody: { host, url: revalidateUrl, eTag, lastModified }, + MessageDeduplicationId: hash(`${rawPath}-${lastModified}-${eTag}`), MessageGroupId: generateMessageGroupId(rawPath), }); } catch (e) { diff --git a/packages/open-next/src/types/overrides.ts b/packages/open-next/src/types/overrides.ts index 388448be0..4ea257270 100644 --- a/packages/open-next/src/types/overrides.ts +++ b/packages/open-next/src/types/overrides.ts @@ -20,6 +20,8 @@ export interface QueueMessage { MessageBody: { host: string; url: string; + lastModified: number; + eTag: string; }; MessageGroupId: string; } diff --git a/packages/tests-unit/tests/core/routing/util.test.ts b/packages/tests-unit/tests/core/routing/util.test.ts index b3d721b56..6377371c5 100644 --- a/packages/tests-unit/tests/core/routing/util.test.ts +++ b/packages/tests-unit/tests/core/routing/util.test.ts @@ -668,7 +668,12 @@ describe("revalidateIfRequired", () => { await revalidateIfRequired("localhost", "/path", headers); expect(sendMock).toHaveBeenCalledWith({ - MessageBody: { host: "localhost", url: "/path" }, + MessageBody: { + host: "localhost", + url: "/path", + eTag: expect.any(String), + lastModified: expect.any(Number), + }, MessageDeduplicationId: expect.any(String), MessageGroupId: expect.any(String), }); @@ -682,7 +687,12 @@ describe("revalidateIfRequired", () => { await revalidateIfRequired("localhost", "/path", headers); expect(sendMock).toHaveBeenCalledWith({ - MessageBody: { host: "localhost", url: "/path" }, + MessageBody: { + host: "localhost", + url: "/path", + eTag: expect.any(String), + lastModified: expect.any(Number), + }, MessageDeduplicationId: expect.any(String), MessageGroupId: expect.any(String), });