@makeswift/runtime 0.23.4-canary.2 → 0.23.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,7 +37,7 @@ async function handler(...args) {
37
37
  const supportsDraftMode = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => true).with(apiRoutePattern, () => false).exhaustive();
38
38
  const supportsWebhook = (0, import_ts_pattern.match)(args).with(routeHandlerPattern, () => true).with(apiRoutePattern, () => false).exhaustive();
39
39
  const body = {
40
- version: "0.23.4-canary.2",
40
+ version: "0.23.4",
41
41
  previewMode: supportsPreviewMode,
42
42
  draftMode: supportsDraftMode,
43
43
  interactionMode: true,
@@ -42,7 +42,7 @@ async function proxyDraftModeRouteHandler(request, _context, { apiKey }) {
42
42
  const draft = await (0, import_headers.draftMode)();
43
43
  draft.enable();
44
44
  const proxyUrl = request.nextUrl.clone();
45
- if (process.env.FORCE_HTTP == null) {
45
+ if (process.env.MAKESWIFT_DRAFT_MODE_PROXY_FORCE_HTTP == null) {
46
46
  proxyUrl.protocol = request.headers.get("x-forwarded-proto") ?? request.nextUrl.protocol;
47
47
  } else {
48
48
  proxyUrl.protocol = "http";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-draft-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { cookies, draftMode } from 'next/headers'\n\nimport { MAKESWIFT_DRAFT_MODE_DATA_COOKIE, MakeswiftDraftData } from '../../draft-mode'\nimport { MakeswiftSiteVersion } from '../../preview-mode'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyDraftModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyDraftModeResponse = ProxyDraftModeError | ProxyResponse\n\ntype ProxyDraftModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<ProxyDraftModeResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function proxyDraftMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>>\nexport default async function proxyDraftMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyDraftMode(\n ...args: ProxyDraftModeHandlerArgs\n): Promise<NextResponse<ProxyDraftModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyDraftModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyDraftModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyDraftModeRouteHandler(\n request: NextRequest,\n _context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>> {\n const secret =\n request.nextUrl.searchParams.get('x-makeswift-draft-mode') ??\n request.headers.get('X-Makeswift-Draft-Mode')\n\n if (secret !== apiKey) return new NextResponse('Unauthorized', { status: 401 })\n\n const draftModeData: MakeswiftDraftData = {\n makeswift: true,\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const draft = await draftMode()\n draft.enable()\n\n const proxyUrl = request.nextUrl.clone() \n \n if (process.env.FORCE_HTTP == null) {\n proxyUrl.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol\n } else {\n proxyUrl.protocol = 'http'\n }\n\n const forwardingHost = request.headers.get('x-forwarded-host') ?? request.headers.get('host') \n if (forwardingHost) {\n proxyUrl.host = forwardingHost\n }\n \n proxyUrl.searchParams.delete('x-makeswift-draft-mode')\n\n const proxyHeaders = new Headers(request.headers)\n proxyHeaders.delete('X-Makeswift-Draft-Mode')\n\n const proxyRequest = new NextRequest(proxyUrl, { headers: proxyHeaders })\n const draftModeCookie = (await cookies()).get('__prerender_bypass')\n if (draftModeCookie) {\n proxyRequest.cookies.set(draftModeCookie)\n proxyRequest.cookies.set(MAKESWIFT_DRAFT_MODE_DATA_COOKIE, JSON.stringify(draftModeData))\n }\n\n draft.disable()\n\n const proxyResponse = await fetch(proxyRequest)\n\n const response = new NextResponse<ProxyResponse>(proxyResponse.body, {\n headers: proxyResponse.headers,\n status: proxyResponse.status,\n })\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (response.headers.has('content-encoding')) {\n response.headers.delete('content-encoding')\n response.headers.delete('content-length')\n }\n\n return response\n}\n\nasync function proxyDraftModeApiRouteHandler(\n _req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n {}: { apiKey: string },\n): Promise<void> {\n const message =\n 'Cannot request draft endpoint from an API handler registered in `pages`. Move your Makeswift API handler to the `app` directory'\n console.error(message)\n return res.status(500).send(message)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA0C;AAC1C,wBAAyB;AACzB,qBAAmC;AAEnC,wBAAqE;AACrE,0BAAqC;AAcrC,MAAM,sBAAsB,CAAC,oBAAE,WAAW,OAAO,GAAG,oBAAE,KAAK,oBAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,oBAAE,KAAK,oBAAE,KAAK,oBAAE,GAAG;AAY5C,eAAO,kBACF,MACmD;AACtD,aAAO,yBAAM,IAAI,EACd,KAAK,qBAAqB,CAAAA,UAAQ,2BAA2B,GAAGA,KAAI,CAAC,EACrE,KAAK,iBAAiB,CAAAA,UAAQ,8BAA8B,GAAGA,KAAI,CAAC,EACpE,WAAW;AAChB;AAEA,eAAe,2BACb,SACA,UACA,EAAE,OAAO,GACsC;AAC/C,QAAM,SACJ,QAAQ,QAAQ,aAAa,IAAI,wBAAwB,KACzD,Q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Ae,8BACb,MACA,KACA,CAAC,GACc;AACf,QAAM,UACJ;AACF,UAAQ,MAAM,OAAO;AACrB,SAAO,IAAI,OAAO,GAAG,EAAE,KAAK,OAAO;AACrC;","names":["args"]}
1
+ {"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-draft-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { cookies, draftMode } from 'next/headers'\n\nimport { MAKESWIFT_DRAFT_MODE_DATA_COOKIE, MakeswiftDraftData } from '../../draft-mode'\nimport { MakeswiftSiteVersion } from '../../preview-mode'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyDraftModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyDraftModeResponse = ProxyDraftModeError | ProxyResponse\n\ntype ProxyDraftModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<ProxyDraftModeResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function proxyDraftMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>>\nexport default async function proxyDraftMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyDraftMode(\n ...args: ProxyDraftModeHandlerArgs\n): Promise<NextResponse<ProxyDraftModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyDraftModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyDraftModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyDraftModeRouteHandler(\n request: NextRequest,\n _context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>> {\n const secret =\n request.nextUrl.searchParams.get('x-makeswift-draft-mode') ??\n request.headers.get('X-Makeswift-Draft-Mode')\n\n if (secret !== apiKey) return new NextResponse('Unauthorized', { status: 401 })\n\n const draftModeData: MakeswiftDraftData = {\n makeswift: true,\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const draft = await draftMode()\n draft.enable()\n\n const proxyUrl = request.nextUrl.clone()\n\n if (process.env.MAKESWIFT_DRAFT_MODE_PROXY_FORCE_HTTP == null) {\n proxyUrl.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol\n } else {\n proxyUrl.protocol = 'http'\n }\n\n const forwardingHost = request.headers.get('x-forwarded-host') ?? request.headers.get('host')\n if (forwardingHost) {\n proxyUrl.host = forwardingHost\n }\n\n proxyUrl.searchParams.delete('x-makeswift-draft-mode')\n\n const proxyHeaders = new Headers(request.headers)\n proxyHeaders.delete('X-Makeswift-Draft-Mode')\n\n const proxyRequest = new NextRequest(proxyUrl, { headers: proxyHeaders })\n const draftModeCookie = (await cookies()).get('__prerender_bypass')\n if (draftModeCookie) {\n proxyRequest.cookies.set(draftModeCookie)\n proxyRequest.cookies.set(MAKESWIFT_DRAFT_MODE_DATA_COOKIE, JSON.stringify(draftModeData))\n }\n\n draft.disable()\n\n const proxyResponse = await fetch(proxyRequest)\n\n const response = new NextResponse<ProxyResponse>(proxyResponse.body, {\n headers: proxyResponse.headers,\n status: proxyResponse.status,\n })\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (response.headers.has('content-encoding')) {\n response.headers.delete('content-encoding')\n response.headers.delete('content-length')\n }\n\n return response\n}\n\nasync function proxyDraftModeApiRouteHandler(\n _req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n {}: { apiKey: string },\n): Promise<void> {\n const message =\n 'Cannot request draft endpoint from an API handler registered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AwB;AAErD,QAAM,eAAe,IAAI,QAAQ,QAAQ,OAAO;AAChD,eAAa,OAAO,wBAAwB;AAE5C,QAAM,eAAe,IAAI,0BAAY,UAAU,EAAE,SAAS,aAAa,CAAC;AACxE,QAAM,mBAAmB,UAAM,wBAAQ,GAAG,IAAI,oBAAoB;AAClE,MAAI,iBAAiB;AACnB,iBAAa,QAAQ,IAAI,eAAe;AACxC,iBAAa,QAAQ,IAAI,oDAAkC,KAAK,UAAU,aAAa,CAAC;AAAA,EAC1F;AAEA,QAAM,QAAQ;AAEd,QAAM,gBAAgB,MAAM,MAAM,YAAY;AAE9C,QAAM,WAAW,IAAI,2BAA4B,cAAc,MAAM;AAAA,IACnE,SAAS,cAAc;AAAA,IACvB,QAAQ,cAAc;AAAA,EACxB,CAAC;AAOD,MAAI,SAAS,QAAQ,IAAI,kBAAkB,GAAG;AAC5C,aAAS,QAAQ,OAAO,kBAAkB;AAC1C,aAAS,QAAQ,OAAO,gBAAgB;AAAA,EAC1C;AAEA,SAAO;AACT;AAEA,eAAe,8BACb,MACA,KACA,CAAC,GACc;AACf,QAAM,UACJ;AACF,UAAQ,MAAM,OAAO;AACrB,SAAO,IAAI,OAAO,GAAG,EAAE,KAAK,OAAO;AACrC;","names":["args"]}
@@ -14,7 +14,7 @@ async function handler(...args) {
14
14
  const supportsDraftMode = match(args).with(routeHandlerPattern, () => true).with(apiRoutePattern, () => false).exhaustive();
15
15
  const supportsWebhook = match(args).with(routeHandlerPattern, () => true).with(apiRoutePattern, () => false).exhaustive();
16
16
  const body = {
17
- version: "0.23.4-canary.2",
17
+ version: "0.23.4",
18
18
  previewMode: supportsPreviewMode,
19
19
  draftMode: supportsDraftMode,
20
20
  interactionMode: true,
@@ -19,7 +19,7 @@ async function proxyDraftModeRouteHandler(request, _context, { apiKey }) {
19
19
  const draft = await draftMode();
20
20
  draft.enable();
21
21
  const proxyUrl = request.nextUrl.clone();
22
- if (process.env.FORCE_HTTP == null) {
22
+ if (process.env.MAKESWIFT_DRAFT_MODE_PROXY_FORCE_HTTP == null) {
23
23
  proxyUrl.protocol = request.headers.get("x-forwarded-proto") ?? request.nextUrl.protocol;
24
24
  } else {
25
25
  proxyUrl.protocol = "http";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-draft-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { cookies, draftMode } from 'next/headers'\n\nimport { MAKESWIFT_DRAFT_MODE_DATA_COOKIE, MakeswiftDraftData } from '../../draft-mode'\nimport { MakeswiftSiteVersion } from '../../preview-mode'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyDraftModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyDraftModeResponse = ProxyDraftModeError | ProxyResponse\n\ntype ProxyDraftModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<ProxyDraftModeResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function proxyDraftMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>>\nexport default async function proxyDraftMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyDraftMode(\n ...args: ProxyDraftModeHandlerArgs\n): Promise<NextResponse<ProxyDraftModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyDraftModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyDraftModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyDraftModeRouteHandler(\n request: NextRequest,\n _context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>> {\n const secret =\n request.nextUrl.searchParams.get('x-makeswift-draft-mode') ??\n request.headers.get('X-Makeswift-Draft-Mode')\n\n if (secret !== apiKey) return new NextResponse('Unauthorized', { status: 401 })\n\n const draftModeData: MakeswiftDraftData = {\n makeswift: true,\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const draft = await draftMode()\n draft.enable()\n\n const proxyUrl = request.nextUrl.clone() \n \n if (process.env.FORCE_HTTP == null) {\n proxyUrl.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol\n } else {\n proxyUrl.protocol = 'http'\n }\n\n const forwardingHost = request.headers.get('x-forwarded-host') ?? request.headers.get('host') \n if (forwardingHost) {\n proxyUrl.host = forwardingHost\n }\n \n proxyUrl.searchParams.delete('x-makeswift-draft-mode')\n\n const proxyHeaders = new Headers(request.headers)\n proxyHeaders.delete('X-Makeswift-Draft-Mode')\n\n const proxyRequest = new NextRequest(proxyUrl, { headers: proxyHeaders })\n const draftModeCookie = (await cookies()).get('__prerender_bypass')\n if (draftModeCookie) {\n proxyRequest.cookies.set(draftModeCookie)\n proxyRequest.cookies.set(MAKESWIFT_DRAFT_MODE_DATA_COOKIE, JSON.stringify(draftModeData))\n }\n\n draft.disable()\n\n const proxyResponse = await fetch(proxyRequest)\n\n const response = new NextResponse<ProxyResponse>(proxyResponse.body, {\n headers: proxyResponse.headers,\n status: proxyResponse.status,\n })\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (response.headers.has('content-encoding')) {\n response.headers.delete('content-encoding')\n response.headers.delete('content-length')\n }\n\n return response\n}\n\nasync function proxyDraftModeApiRouteHandler(\n _req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n {}: { apiKey: string },\n): Promise<void> {\n const message =\n 'Cannot request draft endpoint from an API handler registered in `pages`. Move your Makeswift API handler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Q,OAAO;AAChD,eAAa,OAAO,wBAAwB;AAE5C,QAAM,eAAe,IAAI,YAAY,UAAU,EAAE,SAAS,aAAa,CAAC;AACxE,QAAM,mBAAmB,MAAM,QAAQ,GAAG,IAAI,oBAAoB;AAClE,MAAI,iBAAiB;AACnB,iBAAa,QAAQ,IAAI,eAAe;AACxC,iBAAa,QAAQ,IAAI,kCAAkC,KAAK,UAAU,aAAa,CAAC;AAAA,EAC1F;AAEA,QAAM,QAAQ;AAEd,QAAM,gBAAgB,MAAM,MAAM,YAAY;AAE9C,QAAM,WAAW,IAAI,aAA4B,cAAc,MAAM;AAAA,IACnE,SAAS,cAAc;AAAA,IACvB,QAAQ,cAAc;AAAA,EACxB,CAAC;AAOD,MAAI,SAAS,QAAQ,IAAI,kBAAkB,GAAG;AAC5C,aAAS,QAAQ,OAAO,kBAAkB;AAC1C,aAAS,QAAQ,OAAO,gBAAgB;AAAA,EAC1C;AAEA,SAAO;AACT;AAEA,eAAe,8BACb,MACA,KACA,CAAC,GACc;AACf,QAAM,UACJ;AACF,UAAQ,MAAM,OAAO;AACrB,SAAO,IAAI,OAAO,GAAG,EAAE,KAAK,OAAO;AACrC;","names":["args"]}
1
+ {"version":3,"sources":["../../../../../src/next/api-handler/handlers/proxy-draft-mode.ts"],"sourcesContent":["import { NextApiRequest, NextApiResponse } from 'next'\nimport { NextRequest, NextResponse } from 'next/server'\nimport { P, match } from 'ts-pattern'\nimport { cookies, draftMode } from 'next/headers'\n\nimport { MAKESWIFT_DRAFT_MODE_DATA_COOKIE, MakeswiftDraftData } from '../../draft-mode'\nimport { MakeswiftSiteVersion } from '../../preview-mode'\n\ntype Context = { params: { [key: string]: string | string[] } }\n\ntype ProxyDraftModeError = string\n\ntype ProxyResponse = { __brand: 'ProxyResponse' }\n\nexport type ProxyDraftModeResponse = ProxyDraftModeError | ProxyResponse\n\ntype ProxyDraftModeHandlerArgs =\n | [request: NextRequest, context: Context, params: { apiKey: string }]\n | [req: NextApiRequest, res: NextApiResponse<ProxyDraftModeResponse>, params: { apiKey: string }]\n\nconst routeHandlerPattern = [P.instanceOf(Request), P.any, P.any] as const\nconst apiRoutePattern = [P.any, P.any, P.any] as const\n\nexport default async function proxyDraftMode(\n request: NextRequest,\n context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>>\nexport default async function proxyDraftMode(\n req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n { apiKey }: { apiKey: string },\n): Promise<void>\nexport default async function proxyDraftMode(\n ...args: ProxyDraftModeHandlerArgs\n): Promise<NextResponse<ProxyDraftModeResponse> | void> {\n return match(args)\n .with(routeHandlerPattern, args => proxyDraftModeRouteHandler(...args))\n .with(apiRoutePattern, args => proxyDraftModeApiRouteHandler(...args))\n .exhaustive()\n}\n\nasync function proxyDraftModeRouteHandler(\n request: NextRequest,\n _context: Context,\n { apiKey }: { apiKey: string },\n): Promise<NextResponse<ProxyDraftModeResponse>> {\n const secret =\n request.nextUrl.searchParams.get('x-makeswift-draft-mode') ??\n request.headers.get('X-Makeswift-Draft-Mode')\n\n if (secret !== apiKey) return new NextResponse('Unauthorized', { status: 401 })\n\n const draftModeData: MakeswiftDraftData = {\n makeswift: true,\n siteVersion: MakeswiftSiteVersion.Working,\n }\n\n const draft = await draftMode()\n draft.enable()\n\n const proxyUrl = request.nextUrl.clone()\n\n if (process.env.MAKESWIFT_DRAFT_MODE_PROXY_FORCE_HTTP == null) {\n proxyUrl.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol\n } else {\n proxyUrl.protocol = 'http'\n }\n\n const forwardingHost = request.headers.get('x-forwarded-host') ?? request.headers.get('host')\n if (forwardingHost) {\n proxyUrl.host = forwardingHost\n }\n\n proxyUrl.searchParams.delete('x-makeswift-draft-mode')\n\n const proxyHeaders = new Headers(request.headers)\n proxyHeaders.delete('X-Makeswift-Draft-Mode')\n\n const proxyRequest = new NextRequest(proxyUrl, { headers: proxyHeaders })\n const draftModeCookie = (await cookies()).get('__prerender_bypass')\n if (draftModeCookie) {\n proxyRequest.cookies.set(draftModeCookie)\n proxyRequest.cookies.set(MAKESWIFT_DRAFT_MODE_DATA_COOKIE, JSON.stringify(draftModeData))\n }\n\n draft.disable()\n\n const proxyResponse = await fetch(proxyRequest)\n\n const response = new NextResponse<ProxyResponse>(proxyResponse.body, {\n headers: proxyResponse.headers,\n status: proxyResponse.status,\n })\n\n // `fetch` automatically decompresses the response, but the response headers will keep the\n // `content-encoding` and `content-length` headers. This will cause decoding issues if the client\n // attempts to decompress the response again. To prevent this, we remove these headers.\n //\n // See https://github.com/nodejs/undici/issues/2514.\n if (response.headers.has('content-encoding')) {\n response.headers.delete('content-encoding')\n response.headers.delete('content-length')\n }\n\n return response\n}\n\nasync function proxyDraftModeApiRouteHandler(\n _req: NextApiRequest,\n res: NextApiResponse<ProxyDraftModeResponse>,\n {}: { apiKey: string },\n): Promise<void> {\n const message =\n 'Cannot request draft endpoint from an API handler registered in `pages`. Move your Makeswift API handler to the `app` directory'\n console.error(message)\n return res.status(500).send(message)\n}\n"],"mappings":"AACA,SAAS,aAAa,oBAAoB;AAC1C,SAAS,GAAG,aAAa;AACzB,SAAS,SAAS,iBAAiB;AAEnC,SAAS,wCAA4D;AACrE,SAAS,4BAA4B;AAcrC,MAAM,sBAAsB,CAAC,EAAE,WAAW,OAAO,GAAG,EAAE,KAAK,EAAE,GAAG;AAChE,MAAM,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG;AAY5C,eAAO,kBACF,MACmD;AACtD,SAAO,MAAM,IAAI,EACd,KAAK,qBAAqB,CAAAA,UAAQ,2BAA2B,GAAGA,KAAI,CAAC,EACrE,KAAK,iBAAiB,CAAAA,UAAQ,8BAA8B,GAAGA,KAAI,CAAC,EACpE,WAAW;AAChB;AAEA,eAAe,2BACb,SACA,UACA,EAAE,OAAO,GACsC;AAC/C,QAAM,SACJ,QAAQ,QAAQ,aAAa,IAAI,wBAAwB,KACzD,QAAQ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b,MACA,KACA,CAAC,GACc;AACf,QAAM,UACJ;AACF,UAAQ,MAAM,OAAO;AACrB,SAAO,IAAI,OAAO,GAAG,EAAE,KAAK,OAAO;AACrC;","names":["args"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makeswift/runtime",
3
- "version": "0.23.4-canary.2",
3
+ "version": "0.23.4",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -157,8 +157,8 @@
157
157
  "uuid": "^9.0.0",
158
158
  "zod": "^3.21.4",
159
159
  "@makeswift/controls": "0.1.7",
160
- "@makeswift/next-plugin": "0.3.1",
161
- "@makeswift/prop-controllers": "0.4.0"
160
+ "@makeswift/prop-controllers": "0.4.0",
161
+ "@makeswift/next-plugin": "0.3.1"
162
162
  },
163
163
  "devDependencies": {
164
164
  "@emotion/jest": "^11.11.0",