prismic 1.2.1 → 1.3.0

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.
Files changed (47) hide show
  1. package/dist/{builders-hKD4IrLX-cdTCGdwG.mjs → builders-hKD4IrLX-CiOmsZQP.mjs} +1 -1
  2. package/dist/index.mjs +119 -58
  3. package/dist/nextjs-c8JOjFCt.mjs +413 -0
  4. package/dist/nuxt-BhwnOusi.mjs +90 -0
  5. package/dist/string-CFNpwnbk.mjs +7 -0
  6. package/dist/sveltekit-BW5_-HtZ.mjs +263 -0
  7. package/package.json +1 -1
  8. package/src/adapters/index.ts +6 -0
  9. package/src/adapters/nextjs.templates.ts +170 -38
  10. package/src/adapters/nextjs.ts +33 -3
  11. package/src/adapters/nuxt.templates.ts +48 -0
  12. package/src/adapters/nuxt.ts +42 -20
  13. package/src/adapters/sveltekit.templates.ts +92 -35
  14. package/src/adapters/sveltekit.ts +38 -3
  15. package/src/auth.ts +1 -2
  16. package/src/clients/locale.ts +64 -0
  17. package/src/clients/user.ts +1 -0
  18. package/src/clients/wroom.ts +212 -0
  19. package/src/commands/gen-setup.ts +38 -0
  20. package/src/commands/gen-types.ts +35 -0
  21. package/src/commands/gen.ts +18 -0
  22. package/src/commands/init.ts +7 -1
  23. package/src/commands/locale-add.ts +47 -0
  24. package/src/commands/locale-list.ts +43 -0
  25. package/src/commands/locale-remove.ts +45 -0
  26. package/src/commands/locale-set-master.ts +61 -0
  27. package/src/commands/locale.ts +28 -0
  28. package/src/commands/repo-create.ts +60 -0
  29. package/src/commands/repo-list.ts +58 -0
  30. package/src/commands/repo-set-api-access.ts +53 -0
  31. package/src/commands/repo-set-name.ts +46 -0
  32. package/src/commands/repo-view.ts +74 -0
  33. package/src/commands/repo.ts +33 -0
  34. package/src/commands/sync.ts +4 -2
  35. package/src/commands/token-create.ts +55 -0
  36. package/src/commands/token-delete.ts +61 -0
  37. package/src/commands/token-list.ts +67 -0
  38. package/src/commands/token.ts +23 -0
  39. package/src/config.ts +53 -0
  40. package/src/env.ts +2 -0
  41. package/src/index.ts +20 -0
  42. package/src/lib/codegen.ts +6 -5
  43. package/src/lib/url.ts +7 -0
  44. package/dist/nextjs-DrbOdw3q.mjs +0 -318
  45. package/dist/nuxt-DO5Kp4yy.mjs +0 -59
  46. package/dist/string-CnZrLYLV.mjs +0 -7
  47. package/dist/sveltekit-KHG7YUoX.mjs +0 -236
@@ -0,0 +1,61 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import {
3
+ deleteOAuthAuthorization,
4
+ deleteWriteToken,
5
+ getOAuthApps,
6
+ getWriteTokens,
7
+ } from "../clients/wroom";
8
+ import { CommandError, createCommand, type CommandConfig } from "../lib/command";
9
+ import { getRepositoryName } from "../project";
10
+
11
+ const config = {
12
+ name: "prismic token delete",
13
+ description: `
14
+ Delete a token from a Prismic repository.
15
+
16
+ By default, this command reads the repository from prismic.config.json at the
17
+ project root.
18
+ `,
19
+ positionals: {
20
+ token: { description: "Token value" },
21
+ },
22
+ options: {
23
+ repo: { type: "string", short: "r", description: "Repository domain" },
24
+ },
25
+ } satisfies CommandConfig;
26
+
27
+ export default createCommand(config, async ({ positionals, values }) => {
28
+ const [tokenValue] = positionals;
29
+ const { repo = await getRepositoryName() } = values;
30
+
31
+ if (!tokenValue) {
32
+ throw new CommandError("Missing required argument: <token>");
33
+ }
34
+
35
+ const token = await getToken();
36
+ const host = await getHost();
37
+
38
+ const [apps, writeTokensInfo] = await Promise.all([
39
+ getOAuthApps({ repo, token, host }),
40
+ getWriteTokens({ repo, token, host }),
41
+ ]);
42
+
43
+ // Search access tokens
44
+ const accessTokenAuths = apps.flatMap((app) => app.wroom_auths);
45
+ const accessToken = accessTokenAuths.find((auth) => auth.token === tokenValue);
46
+ if (accessToken) {
47
+ await deleteOAuthAuthorization(accessToken.id, { repo, token, host });
48
+ console.info("Token deleted");
49
+ return;
50
+ }
51
+
52
+ // Search write tokens
53
+ const writeToken = writeTokensInfo.tokens.find((t) => t.token === tokenValue);
54
+ if (writeToken) {
55
+ await deleteWriteToken(writeToken.token, { repo, token, host });
56
+ console.info("Token deleted");
57
+ return;
58
+ }
59
+
60
+ throw new CommandError(`Token not found: ${tokenValue}`);
61
+ });
@@ -0,0 +1,67 @@
1
+ import { getHost, getToken } from "../auth";
2
+ import { getOAuthApps, getWriteTokens } from "../clients/wroom";
3
+ import { createCommand, type CommandConfig } from "../lib/command";
4
+ import { stringify } from "../lib/json";
5
+ import { getRepositoryName } from "../project";
6
+
7
+ const config = {
8
+ name: "prismic token list",
9
+ description: `
10
+ List all API tokens for a Prismic repository.
11
+
12
+ By default, this command reads the repository from prismic.config.json at the
13
+ project root.
14
+ `,
15
+ options: {
16
+ json: { type: "boolean", description: "Output as JSON" },
17
+ repo: { type: "string", short: "r", description: "Repository domain" },
18
+ },
19
+ } satisfies CommandConfig;
20
+
21
+ export default createCommand(config, async ({ values }) => {
22
+ const { repo = await getRepositoryName(), json } = values;
23
+
24
+ const token = await getToken();
25
+ const host = await getHost();
26
+
27
+ const [apps, writeTokensInfo] = await Promise.all([
28
+ getOAuthApps({ repo, token, host }),
29
+ getWriteTokens({ repo, token, host }),
30
+ ]);
31
+
32
+ const accessTokens = apps.flatMap((app) =>
33
+ app.wroom_auths.map((auth) => ({
34
+ name: app.name,
35
+ scope: auth.scope,
36
+ token: auth.token,
37
+ createdAt: new Date(auth.created_at.$date).toISOString().split("T")[0],
38
+ })),
39
+ );
40
+ const writeTokens = writeTokensInfo.tokens;
41
+
42
+ if (json) {
43
+ console.info(stringify({ accessTokens, writeTokens }));
44
+ return;
45
+ }
46
+
47
+ if (accessTokens.length > 0) {
48
+ console.info("ACCESS TOKENS");
49
+ for (const accessToken of accessTokens) {
50
+ console.info(` ${accessToken.name} ${accessToken.scope} ${accessToken.token} ${accessToken.createdAt}`);
51
+ }
52
+ } else {
53
+ console.info("ACCESS TOKENS (none)");
54
+ }
55
+
56
+ console.info("");
57
+
58
+ if (writeTokens.length > 0) {
59
+ console.info("WRITE TOKENS");
60
+ for (const writeToken of writeTokens) {
61
+ const date = new Date(writeToken.timestamp * 1000).toISOString().split("T")[0];
62
+ console.info(` ${writeToken.app_name} ${writeToken.token} ${date}`);
63
+ }
64
+ } else {
65
+ console.info("WRITE TOKENS (none)");
66
+ }
67
+ });
@@ -0,0 +1,23 @@
1
+ import { createCommandRouter } from "../lib/command";
2
+ import tokenCreate from "./token-create";
3
+ import tokenDelete from "./token-delete";
4
+ import tokenList from "./token-list";
5
+
6
+ export default createCommandRouter({
7
+ name: "prismic token",
8
+ description: "Manage API tokens for a Prismic repository.",
9
+ commands: {
10
+ list: {
11
+ handler: tokenList,
12
+ description: "List all tokens",
13
+ },
14
+ create: {
15
+ handler: tokenCreate,
16
+ description: "Create a new token",
17
+ },
18
+ delete: {
19
+ handler: tokenDelete,
20
+ description: "Delete a token",
21
+ },
22
+ },
23
+ });
package/src/config.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
2
+
1
3
  import { readFile, rm, writeFile } from "node:fs/promises";
2
4
  import * as z from "zod/mini";
3
5
 
@@ -8,9 +10,20 @@ import { findPackageJson, MissingPackageJson } from "./lib/packageJson";
8
10
  const CONFIG_FILENAME = "prismic.config.json";
9
11
  const LEGACY_SLICE_MACHINE_CONFIG_FILENAME = "slicemachine.config.json";
10
12
 
13
+ const RouteSchema = z.object({
14
+ type: z.string(),
15
+ path: z.string(),
16
+ uid: z.optional(z.string()),
17
+ lang: z.optional(z.string()),
18
+ resolvers: z.optional(z.record(z.string(), z.string())),
19
+ });
20
+ export type Route = z.infer<typeof RouteSchema>;
21
+
11
22
  const ConfigSchema = z.object({
12
23
  repositoryName: z.string(),
24
+ documentAPIEndpoint: z.optional(z.url()),
13
25
  libraries: z.optional(z.array(z.string())),
26
+ routes: z.optional(z.array(RouteSchema)),
14
27
  });
15
28
  export type Config = z.infer<typeof ConfigSchema>;
16
29
 
@@ -87,6 +100,46 @@ export class UnknownProjectRoot extends Error {
87
100
  name = "UnknownProjectRoot";
88
101
  }
89
102
 
103
+ export async function addRoute(pageType: CustomType): Promise<void> {
104
+ const { routes = [] } = await readConfig();
105
+ const hasRoute = routes.some((r) => r.type === pageType.id);
106
+ if (hasRoute) return;
107
+ const path = buildRoutePath(pageType);
108
+ const newRoute: Route = { type: pageType.id, path };
109
+ const newRoutes = [...routes, newRoute].sort((a, b) => a.type.localeCompare(b.type));
110
+ await updateConfig({ routes: newRoutes });
111
+ }
112
+
113
+ export async function updateRoute(pageType: CustomType): Promise<void> {
114
+ if (pageType.format === "page") {
115
+ const { routes = [] } = await readConfig();
116
+ const hasRoute = routes.some((r) => r.type === pageType.id);
117
+ if (hasRoute) return;
118
+ await addRoute(pageType);
119
+ } else {
120
+ await removeRoute(pageType.id);
121
+ }
122
+ }
123
+
124
+ export async function removeRoute(id: string): Promise<void> {
125
+ const { routes = [] } = await readConfig();
126
+ const newRoutes = routes.filter((r) => r.type !== id);
127
+ if (routes.length === newRoutes.length) return;
128
+ await updateConfig({ routes: newRoutes });
129
+ }
130
+
131
+ export function buildRoutePath(pageType: CustomType): string {
132
+ const { id, repeatable } = pageType;
133
+ const namespace = id.replaceAll("_", "-").toLowerCase();
134
+ if (repeatable) {
135
+ if (id === "page") return "/:uid";
136
+ return `/${namespace}/:uid`;
137
+ } else {
138
+ if (id === "homepage") return "/";
139
+ return `/${namespace}`;
140
+ }
141
+ }
142
+
90
143
  export async function readLegacySliceMachineConfig(): Promise<LegacySliceMachineConfig> {
91
144
  const configPath = await findLegacySliceMachineConfigPath();
92
145
  try {
package/src/env.ts CHANGED
@@ -3,6 +3,8 @@ import * as z from "zod/mini";
3
3
  const DEFAULT_PRISMIC_SENTRY_DSN =
4
4
  "https://e1886b1775bd397cd1afc60bfd2ebfc8@o146123.ingest.us.sentry.io/4510445143588864";
5
5
 
6
+ export const DEFAULT_PRISMIC_HOST = "prismic.io";
7
+
6
8
  const Env = z.object({
7
9
  MODE: z.string(),
8
10
  DEV: z.stringbool(),
package/src/index.ts CHANGED
@@ -6,11 +6,15 @@ import packageJson from "../package.json" with { type: "json" };
6
6
  import { getAdapter, NoSupportedFrameworkError } from "./adapters";
7
7
  import { getHost, refreshToken } from "./auth";
8
8
  import { getProfile } from "./clients/user";
9
+ import gen from "./commands/gen";
9
10
  import init from "./commands/init";
11
+ import locale from "./commands/locale";
10
12
  import login from "./commands/login";
11
13
  import logout from "./commands/logout";
12
14
  import preview from "./commands/preview";
15
+ import repo from "./commands/repo";
13
16
  import sync from "./commands/sync";
17
+ import token from "./commands/token";
14
18
  import webhook from "./commands/webhook";
15
19
  import whoami from "./commands/whoami";
16
20
  import { InvalidPrismicConfig, MissingPrismicConfig } from "./config";
@@ -43,14 +47,30 @@ const router = createCommandRouter({
43
47
  handler: init,
44
48
  description: "Initialize a Prismic project",
45
49
  },
50
+ gen: {
51
+ handler: gen,
52
+ description: "Generate files from local models",
53
+ },
46
54
  sync: {
47
55
  handler: sync,
48
56
  description: "Sync types and slices from Prismic",
49
57
  },
58
+ locale: {
59
+ handler: locale,
60
+ description: "Manage locales",
61
+ },
62
+ repo: {
63
+ handler: repo,
64
+ description: "Manage repositories",
65
+ },
50
66
  preview: {
51
67
  handler: preview,
52
68
  description: "Manage preview configurations",
53
69
  },
70
+ token: {
71
+ handler: token,
72
+ description: "Manage API tokens",
73
+ },
54
74
  webhook: {
55
75
  handler: webhook,
56
76
  description: "Manage webhooks",
@@ -6,11 +6,13 @@ import { generateTypes } from "prismic-ts-codegen";
6
6
  export async function generateAndWriteTypes(args: {
7
7
  customTypes: CustomType[];
8
8
  slices: SharedSlice[];
9
- projectRoot: URL;
9
+ output: URL;
10
10
  }): Promise<void> {
11
+ const { customTypes, slices, output } = args;
12
+
11
13
  const types = generateTypes({
12
- customTypeModels: args.customTypes,
13
- sharedSliceModels: args.slices,
14
+ customTypeModels: customTypes,
15
+ sharedSliceModels: slices,
14
16
  clientIntegration: {
15
17
  includeContentNamespace: true,
16
18
  includeCreateClientInterface: true,
@@ -18,6 +20,5 @@ export async function generateAndWriteTypes(args: {
18
20
  cache: true,
19
21
  typesProvider: "@prismicio/client",
20
22
  });
21
- const outputPath = new URL("prismicio-types.d.ts", args.projectRoot);
22
- await writeFile(outputPath, types);
23
+ await writeFile(output, types);
23
24
  }
package/src/lib/url.ts CHANGED
@@ -1,5 +1,12 @@
1
+ import { relative } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+
1
4
  export function appendTrailingSlash(url: string | URL): URL {
2
5
  const newURL = new URL(url);
3
6
  if (!newURL.pathname.endsWith("/")) newURL.pathname += "/";
4
7
  return newURL;
5
8
  }
9
+
10
+ export function relativePathname(a: URL, b: URL): string {
11
+ return relative(fileURLToPath(a), fileURLToPath(b));
12
+ }
@@ -1,318 +0,0 @@
1
- import{C as e,T as t,a as n,b as r,n as i,o as a,t as o,v as s,w as c,y as l,z as u}from"./string-CnZrLYLV.mjs";import{createRequire as d}from"node:module";import{fileURLToPath as f}from"node:url";import{relative as p}from"node:path";const m=o`
2
- return (
3
- <section
4
- data-slice-type={slice.slice_type}
5
- data-slice-variation={slice.variation}
6
- >
7
- Placeholder component for {slice.slice_type} (variation: {slice.variation}) slices.
8
- <br />
9
- <strong>You can edit this slice directly in your code editor.</strong>
10
- </section>
11
- )
12
- `;function h(e){let{name:t,typescript:n}=e,r=u(t),i=o`
13
- import { FC } from "react";
14
- import { Content } from "@prismicio/client";
15
- import { SliceComponentProps } from "@prismicio/react";
16
-
17
- /**
18
- * Props for \`${r}\`.
19
- */
20
- export type ${r}Props = SliceComponentProps<Content.${r}Slice>;
21
-
22
- /**
23
- * Component for "${t}" Slices.
24
- */
25
- const ${r}: FC<${r}Props> = ({ slice }) => {
26
- ${m}
27
- };
28
-
29
- export default ${r}
30
- `,a=o`
31
- /**
32
- * @typedef {import("@prismicio/client").Content.${r}Slice} ${r}Slice
33
- * @typedef {import("@prismicio/react").SliceComponentProps<${r}Slice>} ${r}Props
34
- * @type {import("react").FC<${r}Props>}
35
- */
36
- const ${r} = ({ slice }) => {
37
- ${m}
38
- };
39
-
40
- export default ${r};
41
- `;return n?i:a}function g(e){let{typescript:t,appRouter:n,hasSrcDirectory:r}=e,i=`${r?`..`:`.`}/prismic.config.json`,a,s;return n?t?(a=o`
42
- import {
43
- createClient as baseCreateClient,
44
- type ClientConfig,
45
- type Route,
46
- } from "@prismicio/client";
47
- import { enableAutoPreviews } from "@prismicio/next";
48
- import prismicConfig from "${i}";
49
- `,s=o`
50
- /**
51
- * Creates a Prismic client for the project's repository. The client is used to
52
- * query content from the Prismic API.
53
- *
54
- * @param config - Configuration for the Prismic client.
55
- */
56
- export const createClient = (config: ClientConfig = {}) => {
57
- const client = baseCreateClient(repositoryName, {
58
- routes,
59
- fetchOptions:
60
- process.env.NODE_ENV === 'production'
61
- ? { next: { tags: ['prismic'] }, cache: 'force-cache' }
62
- : { next: { revalidate: 5 } },
63
- ...config,
64
- });
65
-
66
- enableAutoPreviews({ client });
67
-
68
- return client;
69
- };
70
- `):(a=o`
71
- import { createClient as baseCreateClient } from "@prismicio/client";
72
- import { enableAutoPreviews } from "@prismicio/next";
73
- import prismicConfig from "${i}";
74
- `,s=o`
75
- /**
76
- * Creates a Prismic client for the project's repository. The client is used to
77
- * query content from the Prismic API.
78
- *
79
- * @param {import("@prismicio/client").ClientConfig} config - Configuration for the Prismic client.
80
- */
81
- export const createClient = (config = {}) => {
82
- const client = baseCreateClient(repositoryName, {
83
- routes,
84
- fetchOptions:
85
- process.env.NODE_ENV === 'production'
86
- ? { next: { tags: ['prismic'] }, cache: 'force-cache' }
87
- : { next: { revalidate: 5 } },
88
- ...config,
89
- });
90
-
91
- enableAutoPreviews({ client });
92
-
93
- return client;
94
- };
95
- `):t?(a=o`
96
- import { createClient as baseCreateClient, type Routes } from "@prismicio/client";
97
- import { enableAutoPreviews, type CreateClientConfig } from "@prismicio/next/pages";
98
- import prismicConfig from "${i}";
99
- `,s=o`
100
- /**
101
- * Creates a Prismic client for the project's repository. The client is used to
102
- * query content from the Prismic API.
103
- *
104
- * @param config - Configuration for the Prismic client.
105
- */
106
- export const createClient = ({ previewData, req, ...config }: CreateClientConfig = {}) => {
107
- const client = baseCreateClient(repositoryName, {
108
- routes,
109
- ...config,
110
- });
111
-
112
- enableAutoPreviews({ client, previewData, req });
113
-
114
- return client;
115
- };
116
- `):(a=o`
117
- import { createClient as baseCreateClient } from "@prismicio/client";
118
- import { enableAutoPreviews } from "@prismicio/next/pages";
119
- import prismicConfig from "${i}";
120
- `,s=o`
121
- /**
122
- * Creates a Prismic client for the project's repository. The client is used to
123
- * query content from the Prismic API.
124
- *
125
- * @param {import("@prismicio/next/pages").CreateClientConfig} config - Configuration for the Prismic client.
126
- */
127
- export const createClient = ({ previewData, req, ...config } = {}) => {
128
- const client = baseCreateClient(repositoryName, {
129
- routes,
130
- ...config,
131
- });
132
-
133
- enableAutoPreviews({ client, previewData, req });
134
-
135
- return client;
136
- };
137
- `),t?o`
138
- ${a}
139
-
140
- /**
141
- * The project's Prismic repository name.
142
- */
143
- export const repositoryName = prismicConfig.repositoryName;
144
-
145
- /**
146
- * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
147
- *
148
- * {@link https://prismic.io/docs/route-resolver#route-resolver}
149
- *
150
- * Note: \`prismic sync\` may append new default routes for Page Types. Feel free
151
- * to edit these to match your site's routing structure.
152
- */
153
- // TODO: Update the routes array to match your project's route structure.
154
- const routes: Route[] = [
155
- // Examples:
156
- // { type: "homepage", path: "/" },
157
- // { type: "page", path: "/:uid" },
158
- ];
159
-
160
- ${s}
161
- `:o`
162
- ${a}
163
-
164
- /**
165
- * The project's Prismic repository name.
166
- */
167
- export const repositoryName = prismicConfig.repositoryName;
168
-
169
- /**
170
- * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
171
- *
172
- * {@link https://prismic.io/docs/route-resolver#route-resolver}
173
- *
174
- * Note: \`prismic sync\` may append new default routes for Page Types. Feel free
175
- * to edit these to match your site's routing structure.
176
- *
177
- * @type {import("@prismicio/client").Route[]}
178
- */
179
- // TODO: Update the routes array to match your project's route structure.
180
- const routes = [
181
- // Examples:
182
- // { type: "homepage", path: "/" },
183
- // { type: "page", path: "/:uid" },
184
- ];
185
-
186
- ${s}
187
- `}function _(e){let{typescript:t,appRouter:n}=e,r=o`
188
- import { SliceSimulator, SliceSimulatorParams, getSlices } from "@prismicio/next";
189
- import { SliceZone } from "@prismicio/react";
190
-
191
- import { components } from "../../slices";
192
-
193
- export default async function SliceSimulatorPage({
194
- searchParams,
195
- }: SliceSimulatorParams) {
196
- const { state } = await searchParams
197
- const slices = getSlices(state);
198
-
199
- return (
200
- <SliceSimulator>
201
- <SliceZone slices={slices} components={components} />
202
- </SliceSimulator>
203
- );
204
- }
205
- `,i=o`
206
- import { SliceSimulator, getSlices } from "@prismicio/next";
207
- import { SliceZone } from "@prismicio/react";
208
-
209
- import { components } from "../../slices";
210
-
211
- export default async function SliceSimulatorPage({ searchParams }) {
212
- const { state } = await searchParams
213
- const slices = getSlices(state);
214
-
215
- return (
216
- <SliceSimulator>
217
- <SliceZone slices={slices} components={components} />
218
- </SliceSimulator>
219
- );
220
- }
221
- `,a=o`
222
- import { SliceSimulator } from "@prismicio/next/pages";
223
- import { SliceZone } from "@prismicio/react";
224
-
225
- import { components } from "../slices";
226
-
227
- export default function SliceSimulatorPage() {
228
- return (
229
- <SliceSimulator
230
- sliceZone={(props) => <SliceZone {...props} components={components} />}
231
- />
232
- );
233
- }
234
- `;return n?t?r:i:a}function v(e){let{typescript:t,appRouter:n}=e,r=o`
235
- import { NextRequest } from "next/server";
236
- import { redirectToPreviewURL } from "@prismicio/next";
237
-
238
- import { createClient } from "../../../prismicio";
239
-
240
- export async function GET(request: NextRequest) {
241
- const client = createClient();
242
-
243
- return await redirectToPreviewURL({ client, request });
244
- }
245
- `,i=o`
246
- import { redirectToPreviewURL } from "@prismicio/next";
247
-
248
- import { createClient } from "../../../prismicio";
249
-
250
- export async function GET(request) {
251
- const client = createClient();
252
-
253
- return await redirectToPreviewURL({ client, request });
254
- }
255
- `,a=o`
256
- import { NextApiRequest, NextApiResponse } from "next";
257
- import { setPreviewData, redirectToPreviewURL } from "@prismicio/next/pages";
258
-
259
- import { createClient } from "../../prismicio";
260
-
261
- export default async function handler(req: NextApiRequest, res: NextApiResponse) {
262
- const client = createClient({ req });
263
-
264
- setPreviewData({ req, res });
265
-
266
- return await redirectToPreviewURL({ req, res, client });
267
- };
268
- `,s=o`
269
- import { setPreviewData, redirectToPreviewURL } from "@prismicio/next/pages";
270
-
271
- import { createClient } from "../../prismicio";
272
-
273
- export default async function handler(req, res) {
274
- const client = createClient({ req });
275
-
276
- setPreviewData({ req, res });
277
-
278
- return await redirectToPreviewURL({ req, res, client });
279
- };
280
- `;return n?t?r:i:t?a:s}function y(e){let{typescript:t,appRouter:n}=e,r=o`
281
- import { exitPreview } from "@prismicio/next";
282
-
283
- export function GET() {
284
- return exitPreview();
285
- }
286
- `,i=o`
287
- import { NextApiRequest, NextApiResponse } from "next";
288
- import { exitPreview } from "@prismicio/next/pages";
289
-
290
- export default function handler(req: NextApiRequest, res: NextApiResponse) {
291
- return exitPreview({ req, res });
292
- }
293
- `,a=o`
294
- import { exitPreview } from "@prismicio/next/pages";
295
-
296
- export default function handler(req, res) {
297
- return exitPreview({ req, res });
298
- }
299
- `;return n?r:t?i:a}function b(e){let{supportsCacheLife:t}=e;return o`
300
- import { NextResponse } from "next/server";
301
- import { revalidateTag } from "next/cache";
302
-
303
- export async function POST() {
304
- revalidateTag("prismic"${t?`, "max"`:``});
305
-
306
- return NextResponse.json({ revalidated: true, now: Date.now() });
307
- }
308
- `}var x=class extends i{id=`next`;async onProjectInitialized(){await s({"@prismicio/client":`^${await r(`@prismicio/client`)}`,"@prismicio/react":`^${await r(`@prismicio/react`)}`,"@prismicio/next":`^${await r(`@prismicio/next`)}`}),await E(),await T(),await w(),await C(),await S()}async onSliceCreated(e,r){let i=u(e.name),a=new URL(i,t(r)),o=await A();await c(new URL(`index.${o}x`,t(a)),h({name:e.name,typescript:await n()}))}onSliceUpdated(){}onSliceDeleted(){}onCustomTypeCreated(){}onCustomTypeUpdated(){}onCustomTypeDeleted(){}async createSliceIndexFile(e){let t=(await this.getSlices()).filter(t=>t.library.href===e.href),n=t.map(t=>`import ${u(t.model.name)} from "./${p(f(e),f(t.directory))}";`),r=t.map(e=>{let t=u(e.model.name);return`${e.model.id}: ${t}`}),i=o`
309
- // Code generated by Prismic. DO NOT EDIT.
310
-
311
- ${n.join(`
312
- `)}
313
-
314
- export const components = {
315
- ${r.join(`,
316
- `)}
317
- };
318
- `,a=`index.${await A()}`;await c(new URL(a,e),i)}async getDefaultSliceLibrary(){let e=await a(),t=await k();return new URL(t?`src/slices/`:`slices/`,e)}};async function S(){if(!await D())return;let t=await O(),n=await A(),r=new URL(`app/api/revalidate/route.${n}`,t);if(await e(r))return;let i=await j();await c(r,b({supportsCacheLife:Number.parseInt(i.split(`.`)[0])>=16}))}async function C(){let t=await D(),r=await O(),i=await A(),a=new URL(t?`app/api/exit-preview/route.${i}`:`pages/api/exit-preview.${i}`,r);await e(a)||await c(a,y({typescript:await n(),appRouter:t}))}async function w(){let t=await D(),r=await O(),i=await A(),a=new URL(t?`app/api/preview/route.${i}`:`pages/api/preview.${i}`,r);await e(a)||await c(a,v({typescript:await n(),appRouter:t}))}async function T(){let t=await D(),r=await O(),i=`${await A()}x`,a=new URL(t?`app/slice-simulator/page.${i}`:`pages/slice-simulator.${i}`,r);await e(a)||await c(a,_({typescript:await n(),appRouter:t}))}async function E(){let t=await A(),r=await O(),i=new URL(`prismicio.${t}`,r);await e(i)||await c(i,g({typescript:await n(),appRouter:await D(),hasSrcDirectory:await k()}))}async function D(){let t=await O();return await e(new URL(`app/`,t))}async function O(){let e=await a();return await k()?new URL(`src/`,e):e}async function k(){let t=await a();return e(new URL(`src/`,t))}async function A(){return await n()?`ts`:`js`}async function j(){let{version:e}=d(await l())(`next/package.json`);return e}export{x as NextJsAdapter};