@prismicio/next 2.2.0 → 2.2.1-pr.130.87623c1
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.
- package/dist/PrismicNextImage.d.ts +57 -0
- package/dist/PrismicNextImage.js +69 -0
- package/dist/PrismicNextImage.js.map +1 -0
- package/dist/PrismicNextLink.d.cts +3 -3
- package/dist/PrismicNextLink.d.ts +54 -0
- package/dist/PrismicNextLink.js +29 -0
- package/dist/PrismicNextLink.js.map +1 -0
- package/dist/PrismicPreview.d.ts +36 -0
- package/dist/PrismicPreview.js +39 -0
- package/dist/PrismicPreview.js.map +1 -0
- package/dist/PrismicPreviewClient.js +76 -0
- package/dist/PrismicPreviewClient.js.map +1 -0
- package/dist/SliceSimulator.d.ts +25 -0
- package/dist/SliceSimulator.js +48 -0
- package/dist/SliceSimulator.js.map +1 -0
- package/dist/SliceSimulatorWrapper.js +35 -0
- package/dist/SliceSimulatorWrapper.js.map +1 -0
- package/dist/createLocaleRedirect.d.ts +14 -0
- package/dist/createLocaleRedirect.js +14 -0
- package/dist/createLocaleRedirect.js.map +1 -0
- package/dist/enableAutoPreviews.d.ts +18 -0
- package/dist/enableAutoPreviews.js +29 -0
- package/dist/enableAutoPreviews.js.map +1 -0
- package/dist/exitPreview.d.ts +21 -0
- package/dist/exitPreview.js +26 -0
- package/dist/exitPreview.js.map +1 -0
- package/dist/getSlices.d.ts +7 -0
- package/dist/getSlices.js +11 -0
- package/dist/getSlices.js.map +1 -0
- package/dist/imgixLoader.d.ts +15 -0
- package/dist/imgixLoader.js +23 -0
- package/dist/imgixLoader.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/lib/devMsg.js +25 -0
- package/dist/lib/devMsg.js.map +1 -0
- package/dist/lib/resolveDefaultExport.js +25 -0
- package/dist/lib/resolveDefaultExport.js.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/pages/PrismicPreview.d.ts +36 -0
- package/dist/pages/PrismicPreview.js +74 -0
- package/dist/pages/PrismicPreview.js.map +1 -0
- package/dist/pages/SliceSimulator.d.ts +37 -0
- package/dist/pages/SliceSimulator.js +40 -0
- package/dist/pages/SliceSimulator.js.map +1 -0
- package/dist/pages/enableAutoPreviews.d.ts +37 -0
- package/dist/pages/enableAutoPreviews.js +25 -0
- package/dist/pages/enableAutoPreviews.js.map +1 -0
- package/dist/pages/exitPreview.d.ts +38 -0
- package/dist/pages/exitPreview.js +26 -0
- package/dist/pages/exitPreview.js.map +1 -0
- package/dist/pages/redirectToPreviewURL.d.ts +48 -0
- package/dist/pages/redirectToPreviewURL.js +15 -0
- package/dist/pages/redirectToPreviewURL.js.map +1 -0
- package/dist/pages/setPreviewData.d.ts +26 -0
- package/dist/pages/setPreviewData.js +12 -0
- package/dist/pages/setPreviewData.js.map +1 -0
- package/dist/pages/types.d.ts +36 -0
- package/dist/pages.d.ts +12 -0
- package/dist/pages.js +12 -0
- package/dist/redirectToPreviewURL.d.ts +33 -0
- package/dist/redirectToPreviewURL.js +23 -0
- package/dist/redirectToPreviewURL.js.map +1 -0
- package/dist/types.d.ts +31 -0
- package/package.json +10 -15
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NextApiRequestLike, NextApiResponseLike } from "./types.js";
|
|
2
|
+
import { Client, LinkResolverFunction } from "@prismicio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/pages/redirectToPreviewURL.d.ts
|
|
5
|
+
type RedirectToPreviewURLConfig = {
|
|
6
|
+
/** The Prismic client configured for the preview session's repository. */
|
|
7
|
+
client: Pick<Client, "resolvePreviewURL">;
|
|
8
|
+
/**
|
|
9
|
+
* The `req` object from a Next.js API route.
|
|
10
|
+
*
|
|
11
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
|
|
12
|
+
*/
|
|
13
|
+
req: NextApiRequestLike;
|
|
14
|
+
/**
|
|
15
|
+
* The `res` object from a Next.js API route.
|
|
16
|
+
*
|
|
17
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
|
|
18
|
+
*/
|
|
19
|
+
res: NextApiResponseLike;
|
|
20
|
+
/**
|
|
21
|
+
* A Link Resolver used to resolve the previewed document's URL.
|
|
22
|
+
*
|
|
23
|
+
* @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
24
|
+
*/
|
|
25
|
+
linkResolver?: LinkResolverFunction;
|
|
26
|
+
/**
|
|
27
|
+
* The default redirect URL if a URL cannot be determined for the previewed
|
|
28
|
+
* document.
|
|
29
|
+
*
|
|
30
|
+
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
31
|
+
* `defaultURL` option must _not_ include it. Instead, provide the `basePath`
|
|
32
|
+
* property using the `basePath` option.
|
|
33
|
+
*/
|
|
34
|
+
defaultURL?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The `basePath` for the Next.js app as it is defined in `next.config.js`.
|
|
37
|
+
* This option can be omitted if the app does not have a `basePath`.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* The Router Handler or API route is unable to detect the app's `basePath`
|
|
41
|
+
* automatically. It must be provided to `redirectToPreviewURL()` manually.
|
|
42
|
+
*/
|
|
43
|
+
basePath?: string;
|
|
44
|
+
};
|
|
45
|
+
declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { RedirectToPreviewURLConfig, redirectToPreviewURL };
|
|
48
|
+
//# sourceMappingURL=redirectToPreviewURL.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/pages/redirectToPreviewURL.ts
|
|
2
|
+
async function redirectToPreviewURL(config) {
|
|
3
|
+
const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config;
|
|
4
|
+
const previewToken = req.query.token?.toString();
|
|
5
|
+
const previewURL = await client.resolvePreviewURL({
|
|
6
|
+
linkResolver,
|
|
7
|
+
defaultURL,
|
|
8
|
+
previewToken
|
|
9
|
+
});
|
|
10
|
+
res.redirect(basePath + previewURL);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { redirectToPreviewURL };
|
|
15
|
+
//# sourceMappingURL=redirectToPreviewURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">;\n\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\treq: NextApiRequestLike;\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\tres: NextApiResponseLike;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<void> {\n\tconst {\n\t\tclient,\n\t\treq,\n\t\tres,\n\t\tlinkResolver,\n\t\tdefaultURL = \"/\",\n\t\tbasePath = \"\",\n\t} = config;\n\n\tconst previewToken = req.query.token?.toString();\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tlinkResolver,\n\t\tdefaultURL,\n\t\tpreviewToken,\n\t});\n\n\tres.redirect(basePath + previewURL);\n\n\treturn;\n}\n"],"mappings":";AAqDA,eAAsB,qBACrB,QACgB;CAChB,MAAM,EACL,QACA,KACA,KACA,cACA,aAAa,KACb,WAAW,OACR;CAEJ,MAAM,eAAe,IAAI,MAAM,OAAO,UAAU;CAEhD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA,CAAC;AAEF,KAAI,SAAS,WAAW,WAAW"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NextApiRequestLike, NextApiResponseLike } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/pages/setPreviewData.d.ts
|
|
4
|
+
/** Configuration for `setPreviewData`. */
|
|
5
|
+
type SetPreviewDataConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* The `req` object from a Next.js API route.
|
|
8
|
+
*
|
|
9
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
10
|
+
*/
|
|
11
|
+
req: NextApiRequestLike;
|
|
12
|
+
/**
|
|
13
|
+
* The `res` object from a Next.js API route.
|
|
14
|
+
*
|
|
15
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
16
|
+
*/
|
|
17
|
+
res: NextApiResponseLike;
|
|
18
|
+
};
|
|
19
|
+
/** Set Prismic preview data for Next.js's Preview Mode. */
|
|
20
|
+
declare function setPreviewData({
|
|
21
|
+
req,
|
|
22
|
+
res
|
|
23
|
+
}: SetPreviewDataConfig): void;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SetPreviewDataConfig, setPreviewData };
|
|
26
|
+
//# sourceMappingURL=setPreviewData.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { cookie } from "@prismicio/client";
|
|
2
|
+
|
|
3
|
+
//#region src/pages/setPreviewData.ts
|
|
4
|
+
/** Set Prismic preview data for Next.js's Preview Mode. */
|
|
5
|
+
function setPreviewData({ req, res }) {
|
|
6
|
+
const ref = req.query.token || req.cookies[cookie.preview];
|
|
7
|
+
if (ref) res.setPreviewData({ ref });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { setPreviewData };
|
|
12
|
+
//# sourceMappingURL=setPreviewData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setPreviewData.js","names":[],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq: NextApiRequestLike;\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike;\n};\n\n/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"mappings":";;;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EnableAutoPreviewsConfig } from "./enableAutoPreviews.js";
|
|
2
|
+
import { ClientConfig } from "@prismicio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/pages/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for creating a Prismic client with automatic preview support in
|
|
8
|
+
* Next.js apps.
|
|
9
|
+
*/
|
|
10
|
+
type CreateClientConfig = ClientConfig & Pick<EnableAutoPreviewsConfig, "previewData" | "req">;
|
|
11
|
+
/**
|
|
12
|
+
* The minimal set of properties needed from `next`'s `NextApiRequest` type.
|
|
13
|
+
*
|
|
14
|
+
* This request type is only compatible with API routes defined in the `pages`
|
|
15
|
+
* directory.
|
|
16
|
+
*/
|
|
17
|
+
type NextApiRequestLike = {
|
|
18
|
+
query: Partial<Record<string, string | string[]>>;
|
|
19
|
+
cookies: Partial<Record<string, string>>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The minimal set of properties needed from `next`'s `NextApiResponse` type.
|
|
23
|
+
*
|
|
24
|
+
* This request type is only compatible with API routes defined in the `pages`
|
|
25
|
+
* directory.
|
|
26
|
+
*/
|
|
27
|
+
type NextApiResponseLike = {
|
|
28
|
+
redirect(url: string): NextApiResponseLike;
|
|
29
|
+
clearPreviewData(): NextApiResponseLike;
|
|
30
|
+
setHeader(name: string, value: string | string[]): NextApiResponseLike;
|
|
31
|
+
json(body: any): void;
|
|
32
|
+
setPreviewData(data: object | string): NextApiResponseLike;
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { CreateClientConfig, NextApiRequestLike, NextApiResponseLike };
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/pages.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PrismicNextLink, PrismicNextLinkProps } from "./PrismicNextLink.js";
|
|
2
|
+
import { PrismicNextImage, PrismicNextImageProps } from "./PrismicNextImage.js";
|
|
3
|
+
import { imgixLoader } from "./imgixLoader.js";
|
|
4
|
+
import { CreateLocaleRedirectConfig, createLocaleRedirect } from "./createLocaleRedirect.js";
|
|
5
|
+
import { SliceSimulator, SliceSimulatorProps, SliceSimulatorSliceZoneProps } from "./pages/SliceSimulator.js";
|
|
6
|
+
import { PrismicPreview, PrismicPreviewProps } from "./pages/PrismicPreview.js";
|
|
7
|
+
import { CreateClientConfig } from "./pages/types.js";
|
|
8
|
+
import { EnableAutoPreviewsConfig, enableAutoPreviews } from "./pages/enableAutoPreviews.js";
|
|
9
|
+
import { RedirectToPreviewURLConfig, redirectToPreviewURL } from "./pages/redirectToPreviewURL.js";
|
|
10
|
+
import { ExitPreviewAPIRouteConfig, exitPreview } from "./pages/exitPreview.js";
|
|
11
|
+
import { SetPreviewDataConfig, setPreviewData } from "./pages/setPreviewData.js";
|
|
12
|
+
export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, type ExitPreviewAPIRouteConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, type SetPreviewDataConfig, SliceSimulator, type SliceSimulatorProps, type SliceSimulatorSliceZoneProps, createLocaleRedirect, enableAutoPreviews, exitPreview, imgixLoader, redirectToPreviewURL, setPreviewData };
|
package/dist/pages.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PrismicNextLink } from "./PrismicNextLink.js";
|
|
2
|
+
import { imgixLoader } from "./imgixLoader.js";
|
|
3
|
+
import { PrismicNextImage } from "./PrismicNextImage.js";
|
|
4
|
+
import { createLocaleRedirect } from "./createLocaleRedirect.js";
|
|
5
|
+
import { SliceSimulator } from "./pages/SliceSimulator.js";
|
|
6
|
+
import { PrismicPreview } from "./pages/PrismicPreview.js";
|
|
7
|
+
import { enableAutoPreviews } from "./pages/enableAutoPreviews.js";
|
|
8
|
+
import { redirectToPreviewURL } from "./pages/redirectToPreviewURL.js";
|
|
9
|
+
import { exitPreview } from "./pages/exitPreview.js";
|
|
10
|
+
import { setPreviewData } from "./pages/setPreviewData.js";
|
|
11
|
+
|
|
12
|
+
export { PrismicNextImage, PrismicNextLink, PrismicPreview, SliceSimulator, createLocaleRedirect, enableAutoPreviews, exitPreview, imgixLoader, redirectToPreviewURL, setPreviewData };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NextRequestLike } from "./types.js";
|
|
2
|
+
import { Client, LinkResolverFunction } from "@prismicio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/redirectToPreviewURL.d.ts
|
|
5
|
+
type RedirectToPreviewURLConfig = {
|
|
6
|
+
/** The Prismic client configured for the preview session's repository. */
|
|
7
|
+
client: Pick<Client, "resolvePreviewURL">;
|
|
8
|
+
/**
|
|
9
|
+
* The `request` object from a Next.js Route Handler.
|
|
10
|
+
*
|
|
11
|
+
* @see Next.js Route Handler docs: \<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\>
|
|
12
|
+
*/
|
|
13
|
+
request: NextRequestLike;
|
|
14
|
+
/**
|
|
15
|
+
* A Link Resolver used to resolve the previewed document's URL.
|
|
16
|
+
*
|
|
17
|
+
* @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
18
|
+
*/
|
|
19
|
+
linkResolver?: LinkResolverFunction;
|
|
20
|
+
/**
|
|
21
|
+
* The default redirect URL if a URL cannot be determined for the previewed
|
|
22
|
+
* document.
|
|
23
|
+
*
|
|
24
|
+
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
25
|
+
* `defaultURL` option must _not_ include it. Instead, provide the `basePath`
|
|
26
|
+
* property using the `basePath` option.
|
|
27
|
+
*/
|
|
28
|
+
defaultURL?: string;
|
|
29
|
+
};
|
|
30
|
+
declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { RedirectToPreviewURLConfig, redirectToPreviewURL };
|
|
33
|
+
//# sourceMappingURL=redirectToPreviewURL.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { cookie } from "@prismicio/client";
|
|
2
|
+
import { redirect } from "next/navigation";
|
|
3
|
+
|
|
4
|
+
//#region src/redirectToPreviewURL.ts
|
|
5
|
+
async function redirectToPreviewURL(config) {
|
|
6
|
+
const { client, request, linkResolver, defaultURL = "/" } = config;
|
|
7
|
+
const { cookies, draftMode } = await import("next/headers");
|
|
8
|
+
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
9
|
+
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
10
|
+
if (previewToken) (await cookies()).set(cookie.preview, previewToken);
|
|
11
|
+
const previewURL = await client.resolvePreviewURL({
|
|
12
|
+
documentID,
|
|
13
|
+
previewToken,
|
|
14
|
+
defaultURL,
|
|
15
|
+
linkResolver
|
|
16
|
+
});
|
|
17
|
+
(await draftMode()).enable();
|
|
18
|
+
redirect(previewURL);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { redirectToPreviewURL };
|
|
23
|
+
//# sourceMappingURL=redirectToPreviewURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} from \"@prismicio/client\";\n\nimport type { NextRequestLike } from \"./types\";\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">;\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config;\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\");\n\n\tconst documentID =\n\t\trequest.nextUrl.searchParams.get(\"documentId\") ?? undefined;\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined;\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies();\n\t\tcookieJar.set(prismicCookie.preview, previewToken);\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t});\n\n\t(await draftMode()).enable();\n\n\tredirect(previewURL);\n}\n"],"mappings":";;;;AAyCA,eAAsB,qBACrB,QACiB;CACjB,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI;CAMnD,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,OAAc,SAAS,aAAa;CAGnD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAEF,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE5B,UAAS,WAAW"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ClientConfig } from "@prismicio/client";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
declare module "@prismicio/client" {
|
|
5
|
+
interface RequestInitLike {
|
|
6
|
+
next?: RequestInit["next"];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** @deprecated Use `@prismicio/client`'s `ClientConfig`. */
|
|
10
|
+
type CreateClientConfig = ClientConfig;
|
|
11
|
+
/**
|
|
12
|
+
* The minimal set of properties needed from `next`'s `NextRequest` type.
|
|
13
|
+
*
|
|
14
|
+
* This request type is only compatible with Route Handlers defined in the `app`
|
|
15
|
+
* directory.
|
|
16
|
+
*/
|
|
17
|
+
type NextRequestLike = {
|
|
18
|
+
headers: {
|
|
19
|
+
get(name: string): string | null;
|
|
20
|
+
};
|
|
21
|
+
url: string;
|
|
22
|
+
nextUrl: {
|
|
23
|
+
pathname: string;
|
|
24
|
+
searchParams: {
|
|
25
|
+
get(name: string): string | null;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { CreateClientConfig, NextRequestLike };
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1-pr.130.87623c1",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -18,23 +18,18 @@
|
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"type": "module",
|
|
20
20
|
"exports": {
|
|
21
|
-
".":
|
|
22
|
-
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./pages": {
|
|
26
|
+
"types": "./dist/pages.d.ts",
|
|
27
|
+
"default": "./dist/pages.cjs"
|
|
28
|
+
},
|
|
23
29
|
"./package.json": "./package.json"
|
|
24
30
|
},
|
|
25
31
|
"main": "./dist/index.cjs",
|
|
26
|
-
"
|
|
27
|
-
"types": "./dist/index.d.cts",
|
|
28
|
-
"typesVersions": {
|
|
29
|
-
"*": {
|
|
30
|
-
"*": [
|
|
31
|
-
"./dist/index.d.ts"
|
|
32
|
-
],
|
|
33
|
-
"pages": [
|
|
34
|
-
"./dist/pages/index.d.ts"
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
},
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
38
33
|
"files": [
|
|
39
34
|
"dist",
|
|
40
35
|
"src"
|