@payloadcms/figma 1.0.0-beta.4 → 1.0.0-beta.5

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 (177) hide show
  1. package/dist/adapters/asset-collection.d.ts +15 -0
  2. package/dist/adapters/asset-collection.js +51 -45
  3. package/dist/adapters/build-lambda-zip.d.ts +8 -9
  4. package/dist/adapters/build-lambda-zip.js +36 -44
  5. package/dist/adapters/index.d.ts +4 -0
  6. package/dist/adapters/index.js +4 -0
  7. package/dist/adapters/lambdaLimits.d.ts +6 -0
  8. package/dist/adapters/lambdaLimits.js +5 -0
  9. package/dist/adapters/nextjs-assets.d.ts +7 -0
  10. package/dist/adapters/nextjs-assets.js +44 -0
  11. package/dist/adapters/nextjs.d.ts +8 -0
  12. package/dist/adapters/nextjs.js +19 -37
  13. package/dist/adapters/nitro.js +18 -43
  14. package/dist/adapters/omit-optional-sharp.d.ts +22 -0
  15. package/dist/adapters/omit-optional-sharp.js +158 -0
  16. package/dist/adapters/secret-files.js +8 -1
  17. package/dist/adapters/types.d.ts +8 -0
  18. package/dist/adapters/v2/core/build.d.ts +69 -0
  19. package/dist/adapters/v2/core/build.js +183 -0
  20. package/dist/adapters/v2/core/content-type.d.ts +3 -0
  21. package/dist/adapters/v2/core/content-type.js +41 -0
  22. package/dist/adapters/v2/core/getRelativePathError.d.ts +5 -0
  23. package/dist/adapters/v2/core/getRelativePathError.js +21 -0
  24. package/dist/adapters/v2/core/index.d.ts +15 -0
  25. package/dist/adapters/v2/core/index.js +13 -0
  26. package/dist/adapters/v2/core/limits.d.ts +28 -0
  27. package/dist/adapters/v2/core/limits.js +26 -0
  28. package/dist/adapters/v2/core/manifest-version.d.ts +10 -0
  29. package/dist/adapters/v2/core/manifest-version.js +14 -0
  30. package/dist/adapters/v2/core/server-zip.d.ts +58 -0
  31. package/dist/adapters/v2/core/server-zip.js +123 -0
  32. package/dist/adapters/v2/core/services.d.ts +46 -0
  33. package/dist/adapters/v2/core/services.js +202 -0
  34. package/dist/adapters/v2/core/static-path.d.ts +13 -0
  35. package/dist/adapters/v2/core/static-path.js +32 -0
  36. package/dist/adapters/v2/core/static-site.d.ts +26 -0
  37. package/dist/adapters/v2/core/static-site.js +95 -0
  38. package/dist/adapters/v2/core/types.d.ts +128 -0
  39. package/dist/adapters/v2/core/types.js +7 -0
  40. package/dist/adapters/v2/core/upload.d.ts +67 -0
  41. package/dist/adapters/v2/core/upload.js +198 -0
  42. package/dist/adapters/v2/core/validateDeployment/createIssue.d.ts +3 -0
  43. package/dist/adapters/v2/core/validateDeployment/createIssue.js +7 -0
  44. package/dist/adapters/v2/core/validateDeployment/escapePointer.d.ts +2 -0
  45. package/dist/adapters/v2/core/validateDeployment/escapePointer.js +3 -0
  46. package/dist/adapters/v2/core/validateDeployment/singletonHeaders.d.ts +2 -0
  47. package/dist/adapters/v2/core/validateDeployment/singletonHeaders.js +10 -0
  48. package/dist/adapters/v2/core/validateDeployment/types.d.ts +16 -0
  49. package/dist/adapters/v2/core/validateDeployment/types.js +8 -0
  50. package/dist/adapters/v2/core/validateDeployment/validateArtifacts.d.ts +3 -0
  51. package/dist/adapters/v2/core/validateDeployment/validateArtifacts.js +30 -0
  52. package/dist/adapters/v2/core/validateDeployment/validateCachePolicy.d.ts +8 -0
  53. package/dist/adapters/v2/core/validateDeployment/validateCachePolicy.js +26 -0
  54. package/dist/adapters/v2/core/validateDeployment/validateCounts/validateCount.d.ts +7 -0
  55. package/dist/adapters/v2/core/validateDeployment/validateCounts/validateCount.js +11 -0
  56. package/dist/adapters/v2/core/validateDeployment/validateCounts.d.ts +3 -0
  57. package/dist/adapters/v2/core/validateDeployment/validateCounts.js +41 -0
  58. package/dist/adapters/v2/core/validateDeployment/validateFallback.d.ts +3 -0
  59. package/dist/adapters/v2/core/validateDeployment/validateFallback.js +21 -0
  60. package/dist/adapters/v2/core/validateDeployment/validateHeaderName.d.ts +6 -0
  61. package/dist/adapters/v2/core/validateDeployment/validateHeaderName.js +13 -0
  62. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp/isReservedRuleHeader.d.ts +2 -0
  63. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp/isReservedRuleHeader.js +13 -0
  64. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp.d.ts +11 -0
  65. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp.js +38 -0
  66. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules.d.ts +3 -0
  67. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules.js +17 -0
  68. package/dist/adapters/v2/core/validateDeployment/validateHeaderValue.d.ts +6 -0
  69. package/dist/adapters/v2/core/validateDeployment/validateHeaderValue.js +24 -0
  70. package/dist/adapters/v2/core/validateDeployment/validateId.d.ts +7 -0
  71. package/dist/adapters/v2/core/validateDeployment/validateId.js +12 -0
  72. package/dist/adapters/v2/core/validateDeployment/validateMatch.d.ts +15 -0
  73. package/dist/adapters/v2/core/validateDeployment/validateMatch.js +74 -0
  74. package/dist/adapters/v2/core/validateDeployment/validatePublicPath.d.ts +7 -0
  75. package/dist/adapters/v2/core/validateDeployment/validatePublicPath.js +21 -0
  76. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList/findRepeatedSingletons.d.ts +3 -0
  77. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList/findRepeatedSingletons.js +16 -0
  78. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList.d.ts +11 -0
  79. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList.js +48 -0
  80. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseBody.d.ts +10 -0
  81. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseBody.js +16 -0
  82. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseStatus.d.ts +8 -0
  83. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseStatus.js +25 -0
  84. package/dist/adapters/v2/core/validateDeployment/validateResponses.d.ts +7 -0
  85. package/dist/adapters/v2/core/validateDeployment/validateResponses.js +59 -0
  86. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateCaptures.d.ts +10 -0
  87. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateCaptures.js +12 -0
  88. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRedirectAction.d.ts +14 -0
  89. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRedirectAction.js +59 -0
  90. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRewriteAction.d.ts +11 -0
  91. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRewriteAction.js +20 -0
  92. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateServerAction.d.ts +11 -0
  93. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateServerAction.js +26 -0
  94. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateStaticAction.d.ts +13 -0
  95. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateStaticAction.js +25 -0
  96. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction.d.ts +12 -0
  97. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction.js +35 -0
  98. package/dist/adapters/v2/core/validateDeployment/validateRoutes.d.ts +6 -0
  99. package/dist/adapters/v2/core/validateDeployment/validateRoutes.js +55 -0
  100. package/dist/adapters/v2/core/validateDeployment/validateServers/listReferencedServerIds.d.ts +3 -0
  101. package/dist/adapters/v2/core/validateDeployment/validateServers/listReferencedServerIds.js +12 -0
  102. package/dist/adapters/v2/core/validateDeployment/validateServers.d.ts +7 -0
  103. package/dist/adapters/v2/core/validateDeployment/validateServers.js +59 -0
  104. package/dist/adapters/v2/core/validateDeployment/validateStaticMap.d.ts +3 -0
  105. package/dist/adapters/v2/core/validateDeployment/validateStaticMap.js +22 -0
  106. package/dist/adapters/v2/core/validateDeployment.d.ts +7 -0
  107. package/dist/adapters/v2/core/validateDeployment.js +42 -0
  108. package/dist/adapters/v2/core/write.d.ts +21 -0
  109. package/dist/adapters/v2/core/write.js +30 -0
  110. package/dist/adapters/v2/nextjs/coverage.d.ts +45 -0
  111. package/dist/adapters/v2/nextjs/coverage.js +113 -0
  112. package/dist/adapters/v2/nextjs/read-build-output.d.ts +116 -0
  113. package/dist/adapters/v2/nextjs/read-build-output.js +368 -0
  114. package/dist/adapters/v2/nextjs/translate.d.ts +20 -0
  115. package/dist/adapters/v2/nextjs/translate.js +400 -0
  116. package/dist/adapters/vite.d.ts +7 -0
  117. package/dist/adapters/vite.js +47 -0
  118. package/dist/adapters/writeZip.d.ts +20 -0
  119. package/dist/adapters/writeZip.js +28 -0
  120. package/dist/api/control-plane.d.ts +28 -6
  121. package/dist/api/control-plane.js +67 -64
  122. package/dist/auth/cli-build-context.d.ts +3 -0
  123. package/dist/auth/cli-build-context.js +2 -0
  124. package/dist/auth/oauth-flow.d.ts +3 -3
  125. package/dist/auth/oauth-flow.js +13 -3
  126. package/dist/cli.js +15 -0
  127. package/dist/commands/build-manifest.d.ts +49 -0
  128. package/dist/commands/build-manifest.js +111 -0
  129. package/dist/commands/deploy.js +195 -26
  130. package/dist/db-content-api/generated/content-api-types.d.ts +18 -14
  131. package/dist/db-content-api/index.js +4 -1
  132. package/dist/db-content-api/utilities/where.js +2 -6
  133. package/dist/endpoints/client-config.d.ts +3 -0
  134. package/dist/endpoints/client-config.js +87 -0
  135. package/dist/image-transforms/constants.d.ts +8 -0
  136. package/dist/image-transforms/constants.js +26 -0
  137. package/dist/image-transforms/createImageTransformer.d.ts +6 -0
  138. package/dist/image-transforms/createImageTransformer.js +100 -0
  139. package/dist/image-transforms/deliverImageResponse.d.ts +11 -0
  140. package/dist/image-transforms/deliverImageResponse.js +43 -0
  141. package/dist/image-transforms/imageRevision.d.ts +14 -0
  142. package/dist/image-transforms/imageRevision.js +115 -0
  143. package/dist/image-transforms/normalizeMediaType.d.ts +2 -0
  144. package/dist/image-transforms/normalizeMediaType.js +3 -0
  145. package/dist/image-transforms/parseImageOverrides.d.ts +4 -0
  146. package/dist/image-transforms/parseImageOverrides.js +20 -0
  147. package/dist/image-transforms/preserveImageRedirectHeaders.d.ts +2 -0
  148. package/dist/image-transforms/preserveImageRedirectHeaders.js +30 -0
  149. package/dist/image-transforms/preventConflictingImageTransformers.d.ts +9 -0
  150. package/dist/image-transforms/preventConflictingImageTransformers.js +67 -0
  151. package/dist/image-transforms/serveImageRequest.d.ts +6 -0
  152. package/dist/image-transforms/serveImageRequest.js +97 -0
  153. package/dist/image-transforms/storedImage.d.ts +49 -0
  154. package/dist/image-transforms/storedImage.js +84 -0
  155. package/dist/image-transforms/types.d.ts +9 -0
  156. package/dist/image-transforms/types.js +1 -0
  157. package/dist/image-transforms/variantMetadata.d.ts +13 -0
  158. package/dist/image-transforms/variantMetadata.js +164 -0
  159. package/dist/imageSizeOptions.d.ts +8 -8
  160. package/dist/imageSizeOptions.js +0 -2
  161. package/dist/index.d.ts +1 -0
  162. package/dist/plugin/build-config.d.ts +3 -4
  163. package/dist/plugin/build-config.js +32 -16
  164. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +2 -1
  165. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +2 -1
  166. package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +2 -1
  167. package/dist/storage-content-api/buildMediaResponseHeaders.js +11 -5
  168. package/dist/storage-content-api/isRunningInLambda.d.ts +2 -0
  169. package/dist/storage-content-api/isRunningInLambda.js +3 -0
  170. package/dist/storage-content-api/staticHandler.js +13 -51
  171. package/dist/storage-content-api/streamMediaResponse.d.ts +17 -0
  172. package/dist/storage-content-api/streamMediaResponse.js +96 -0
  173. package/dist/utils/lambda-config.js +1 -1
  174. package/dist/utils/messages.js +8 -0
  175. package/dist/utils/next-image-loader-config.js +43 -6
  176. package/dist/utils/next-image-loader-file.js +8 -0
  177. package/package.json +7 -1
@@ -0,0 +1,116 @@
1
+ import type { ManifestHeader } from '../core/types.js';
2
+ /**
3
+ * A version-normalized view of a Next.js standalone build: what the build output says about pages,
4
+ * assets, middleware and next.config routing. Translation to manifest v2 reads only this model,
5
+ * so the Adapter API path (16.2+) can produce the same model from its build-complete hook.
6
+ */
7
+ export interface NextBuildModel {
8
+ /** `basePath` from next.config, or `''`. */
9
+ basePath: string;
10
+ /** Matches next.config `caseSensitiveRoutes`; when false Next.js matches paths case-insensitively. */
11
+ caseSensitive: boolean;
12
+ /**
13
+ * Computes the `_rsc` value Next.js's client sends and its server accepts for these router
14
+ * headers, using the build's own Next.js. Absent when the build's Next.js doesn't export it.
15
+ */
16
+ computeRscParam?: RscParamFunction;
17
+ /** next.config `headers`, each with Next.js's compiled regex. */
18
+ configHeaders: NextConfigRule[];
19
+ /**
20
+ * Whether next.config has any rewrite. A rewrite the server handles can serve a public file, so
21
+ * public files must also be in the server deployment.
22
+ */
23
+ hasRewrites: boolean;
24
+ /** Time-based ISR paths: exact prerendered paths and dynamic route patterns. */
25
+ isrRoutes: NextIsrRoute[];
26
+ /** Middleware or proxy matchers. Undefined when the build has no middleware. */
27
+ middlewareMatchers?: NextMatcher[];
28
+ /** `version` of the Next.js package in the standalone output, when readable. */
29
+ nextVersion?: string;
30
+ /** Fully prerendered App Router pages whose HTML, RSC and segment files can be served as is. */
31
+ pages: NextPrerenderedPage[];
32
+ /** next.config redirects and beforeFiles rewrites: Next.js applies them before serving a file. */
33
+ preFilesystemRules: NextConfigRule[];
34
+ /** Router header names from `routes-manifest.json`. */
35
+ rscHeaders: NextRscHeaders;
36
+ server: {
37
+ outputPath: string;
38
+ /** Absolute path of the standalone server file. */
39
+ serverEntryPath: string;
40
+ standalonePath: string;
41
+ };
42
+ /** Files Next.js serves unchanged: `_next/static`, `public` and static metadata icons. */
43
+ staticFiles: NextStaticFile[];
44
+ }
45
+ export interface NextPrerenderedPage {
46
+ /** HTML representation. */
47
+ html: string;
48
+ /** Headers from the page's `.meta`, without `content-length`. */
49
+ metaHeaders: ManifestHeader[];
50
+ /** Public path, such as `/` or `/blog/a`. */
51
+ path: string;
52
+ /** Complete RSC payload, when the build emitted one. */
53
+ rsc?: string;
54
+ /** Segment-prefetch payloads keyed by the `Next-Router-Segment-Prefetch` value. */
55
+ segments: Array<{
56
+ file: string;
57
+ segmentPath: string;
58
+ }>;
59
+ /** Status from `.meta`; 200 when absent. */
60
+ status: number;
61
+ }
62
+ export interface NextIsrRoute {
63
+ expireSeconds?: number;
64
+ /** An exact path (`/isr`) or a manifest path pattern (`/blog/:slug`). */
65
+ path: string;
66
+ revalidateSeconds: number;
67
+ }
68
+ export interface NextMatcher {
69
+ /** Request conditions; a matcher with any can't be ruled out at build time. */
70
+ conditional: boolean;
71
+ originalSource?: string;
72
+ regexp: string;
73
+ }
74
+ export interface NextConfigRule {
75
+ conditional: boolean;
76
+ /** Headers a `headers` rule sets. */
77
+ headers?: ManifestHeader[];
78
+ regex: string;
79
+ source: string;
80
+ }
81
+ export interface NextStaticFile {
82
+ /** Absolute path of the bytes to serve. */
83
+ file: string;
84
+ /** `_next/static` output, which Next.js content-hashes. */
85
+ hashed: boolean;
86
+ /**
87
+ * `build` for `_next/static`, `public` for the public folder, and `metadata` for prerendered
88
+ * metadata icons, whose bytes live in a `.body` file.
89
+ */
90
+ kind: 'build' | 'metadata' | 'public';
91
+ /** Public path. */
92
+ path: string;
93
+ }
94
+ export interface NextRscHeaders {
95
+ nextUrl: string;
96
+ prefetch: string;
97
+ rsc: string;
98
+ segmentPrefetch: string;
99
+ stateTree: string;
100
+ }
101
+ export type RscParamFunction = (headers: {
102
+ nextUrl?: string;
103
+ prefetch?: string;
104
+ segmentPrefetch?: string;
105
+ stateTree?: string;
106
+ }) => Promise<string>;
107
+ /**
108
+ * Reads a Next.js standalone build into a {@link NextBuildModel}. Throws when the build lacks a
109
+ * standalone server or a manifest the model depends on is unreadable, rather than guessing.
110
+ */
111
+ export declare function readNextBuildOutput(projectPath: string, output?: string): Promise<NextBuildModel>;
112
+ /**
113
+ * Converts a Next.js route (`/blog/[slug]`, `/docs/[...rest]`) into a manifest path pattern.
114
+ * Returns undefined for shapes the base contract can't express exactly.
115
+ */
116
+ export declare function toPathPattern(route: string): string | undefined;
@@ -0,0 +1,368 @@
1
+ import fs from 'fs/promises';
2
+ import { createRequire } from 'module';
3
+ import path from 'path';
4
+ import { listStaticPrerenderedPages } from '../../asset-collection.js';
5
+ import { inspectNextjsOutput } from '../../deploy-output/inspectNextjsOutput.js';
6
+ import { readJson } from '../../deploy-output/readJson.js';
7
+ import { resolveOutputPath } from '../../deploy-output/resolveOutputPath.js';
8
+ import { collectNextjsAssets } from '../../nextjs-assets.js';
9
+ const DEFAULT_RSC_HEADERS = {
10
+ nextUrl: 'next-url',
11
+ prefetch: 'next-router-prefetch',
12
+ rsc: 'rsc',
13
+ segmentPrefetch: 'next-router-segment-prefetch',
14
+ stateTree: 'next-router-state-tree'
15
+ };
16
+ /** Middleware that runs for every path, which Next.js uses when no matcher is configured. */ const MATCH_ALL = {
17
+ conditional: false,
18
+ regexp: '^/.*$'
19
+ };
20
+ /** Middleware or proxy bundles, under `server/`. A `src/` app compiles them under `server/src/`. */ const MIDDLEWARE_BUNDLES = [
21
+ 'middleware.js',
22
+ 'proxy.js',
23
+ 'src/middleware.js',
24
+ 'src/proxy.js'
25
+ ];
26
+ const CACHE_BUSTING_MODULE = 'dist/shared/lib/router/utils/cache-busting-search-param.js';
27
+ /**
28
+ * Reads a Next.js standalone build into a {@link NextBuildModel}. Throws when the build lacks a
29
+ * standalone server or a manifest the model depends on is unreadable, rather than guessing.
30
+ */ export async function readNextBuildOutput(projectPath, output) {
31
+ const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
32
+ const layout = await inspectNextjsOutput(outputPath);
33
+ if (!layout) {
34
+ throw new Error(`Standalone build not found at ${outputPath}`);
35
+ }
36
+ const routesManifest = await readRequiredJson(path.join(outputPath, 'routes-manifest.json'));
37
+ const prerenderManifest = await readRequiredJson(path.join(outputPath, 'prerender-manifest.json'));
38
+ const nextDir = await findStandaloneNextPackage(layout.serverEntryPath, layout.standalonePath);
39
+ return {
40
+ basePath: typeof routesManifest.basePath === 'string' ? routesManifest.basePath : '',
41
+ caseSensitive: routesManifest.caseSensitive === true,
42
+ computeRscParam: nextDir ? loadRscParamFunction(nextDir) : undefined,
43
+ configHeaders: readConfigRules(routesManifest.headers),
44
+ hasRewrites: hasRewrites(routesManifest.rewrites),
45
+ isrRoutes: readIsrRoutes(prerenderManifest),
46
+ middlewareMatchers: await readMiddlewareMatchers(outputPath),
47
+ nextVersion: nextDir ? readNextVersion(nextDir) : undefined,
48
+ pages: await readPages(outputPath),
49
+ preFilesystemRules: [
50
+ ...readConfigRules(routesManifest.redirects),
51
+ ...readConfigRules(readBeforeFilesRewrites(routesManifest.rewrites))
52
+ ],
53
+ rscHeaders: readRscHeaders(routesManifest.rsc),
54
+ server: {
55
+ outputPath,
56
+ serverEntryPath: layout.serverEntryPath,
57
+ standalonePath: layout.standalonePath
58
+ },
59
+ staticFiles: await readStaticFiles(projectPath, output)
60
+ };
61
+ }
62
+ async function readPages(outputPath) {
63
+ const appDir = path.join(outputPath, 'server', 'app');
64
+ const pages = [];
65
+ for (const page of (await listStaticPrerenderedPages(outputPath))){
66
+ const html = path.join(appDir, `${page.fileStem}.html`);
67
+ const metaPath = path.join(appDir, `${page.fileStem}.meta`);
68
+ const meta = await readJson(metaPath);
69
+ if (!await isFile(html) || !meta) {
70
+ throw new Error(`Prerendered page ${page.routeKey} is missing ${html} or ${metaPath}`);
71
+ }
72
+ const rsc = path.join(appDir, `${page.fileStem}.rsc`);
73
+ pages.push({
74
+ html,
75
+ metaHeaders: readMetaHeaders(meta.headers),
76
+ path: page.routeKey,
77
+ ...page.hasFullRSC && await isFile(rsc) ? {
78
+ rsc
79
+ } : {},
80
+ segments: await readSegments(appDir, page.fileStem, meta.segmentPaths),
81
+ status: typeof meta.status === 'number' ? meta.status : 200
82
+ });
83
+ }
84
+ return pages;
85
+ }
86
+ /**
87
+ * Pairs each segment path the page's `.meta` lists with its `<page>.segments<path>.segment.rsc`
88
+ * file. Gatekeeper v1 uses the same mapping. Paths without a file are left out.
89
+ */ async function readSegments(appDir, fileStem, segmentPaths) {
90
+ if (!Array.isArray(segmentPaths)) {
91
+ return [];
92
+ }
93
+ const segments = [];
94
+ for (const segmentPath of segmentPaths){
95
+ if (typeof segmentPath !== 'string' || !segmentPath.startsWith('/')) {
96
+ continue;
97
+ }
98
+ const file = path.join(appDir, `${fileStem}.segments${segmentPath}.segment.rsc`);
99
+ const relative = path.relative(appDir, file);
100
+ // Segment paths come from the build, but never let one point outside server/app.
101
+ if (relative.startsWith('..') || path.isAbsolute(relative)) {
102
+ continue;
103
+ }
104
+ if (await isFile(file)) {
105
+ segments.push({
106
+ file,
107
+ segmentPath
108
+ });
109
+ }
110
+ }
111
+ return segments;
112
+ }
113
+ function readMetaHeaders(headers) {
114
+ if (headers === null || typeof headers !== 'object' || Array.isArray(headers)) {
115
+ return [];
116
+ }
117
+ const result = [];
118
+ for (const [name, value] of Object.entries(headers)){
119
+ // The platform computes Content-Length, and the core sets Content-Type.
120
+ if ([
121
+ 'content-length',
122
+ 'content-type'
123
+ ].includes(name.toLowerCase())) {
124
+ continue;
125
+ }
126
+ for (const entry of Array.isArray(value) ? value : [
127
+ value
128
+ ]){
129
+ if (typeof entry === 'string') {
130
+ result.push({
131
+ name,
132
+ value: entry
133
+ });
134
+ }
135
+ }
136
+ }
137
+ return result;
138
+ }
139
+ function readIsrRoutes(manifest) {
140
+ const routes = asRecord(manifest.routes);
141
+ const byPath = new Map();
142
+ for (const [routeKey, value] of Object.entries(routes)){
143
+ const route = asRecord(value);
144
+ const revalidateSeconds = route.initialRevalidateSeconds;
145
+ if (typeof revalidateSeconds !== 'number' || revalidateSeconds <= 0) {
146
+ continue;
147
+ }
148
+ const expireSeconds = typeof route.initialExpireSeconds === 'number' ? route.initialExpireSeconds : undefined;
149
+ const isr = {
150
+ ...expireSeconds !== undefined ? {
151
+ expireSeconds
152
+ } : {},
153
+ revalidateSeconds
154
+ };
155
+ byPath.set(routeKey, {
156
+ path: routeKey,
157
+ ...isr
158
+ });
159
+ // A dynamic route renders unlisted params on demand with the same revalidation.
160
+ const srcRoute = route.srcRoute;
161
+ if (typeof srcRoute === 'string' && srcRoute !== routeKey && srcRoute.includes('[')) {
162
+ const pattern = toPathPattern(srcRoute);
163
+ if (pattern && !byPath.has(pattern)) {
164
+ byPath.set(pattern, {
165
+ path: pattern,
166
+ ...isr
167
+ });
168
+ }
169
+ }
170
+ }
171
+ return [
172
+ ...byPath.values()
173
+ ];
174
+ }
175
+ /**
176
+ * Converts a Next.js route (`/blog/[slug]`, `/docs/[...rest]`) into a manifest path pattern.
177
+ * Returns undefined for shapes the base contract can't express exactly.
178
+ */ export function toPathPattern(route) {
179
+ const segments = route.split('/').slice(1);
180
+ const converted = [];
181
+ for (const [index, segment] of segments.entries()){
182
+ const dynamic = /^\[(\[)?(\.\.\.)?([A-Z_]\w*)\]?\]$/i.exec(segment);
183
+ if (!dynamic) {
184
+ if (segment.includes('[')) {
185
+ return undefined;
186
+ }
187
+ converted.push(segment);
188
+ continue;
189
+ }
190
+ const [, optional, catchAll, name] = dynamic;
191
+ if (optional && !catchAll) {
192
+ return undefined;
193
+ }
194
+ if (catchAll && index !== segments.length - 1) {
195
+ return undefined;
196
+ }
197
+ converted.push(catchAll ? `:${name}*` : `:${name}`);
198
+ }
199
+ return `/${converted.join('/')}`;
200
+ }
201
+ async function readMiddlewareMatchers(outputPath) {
202
+ const serverDir = path.join(outputPath, 'server');
203
+ const edge = asRecord((await readJson(path.join(serverDir, 'middleware-manifest.json')))?.middleware);
204
+ const node = asRecord((await readJson(path.join(serverDir, 'functions-config-manifest.json')))?.functions);
205
+ // Presence of the entry matters, even when it is empty.
206
+ const entries = [
207
+ ...'/' in edge ? [
208
+ asRecord(edge['/'])
209
+ ] : [],
210
+ ...'/_middleware' in node ? [
211
+ asRecord(node['/_middleware'])
212
+ ] : []
213
+ ];
214
+ const hasMiddlewareFile = (await Promise.all(MIDDLEWARE_BUNDLES.map((file)=>isFile(path.join(serverDir, file))))).some(Boolean);
215
+ if (entries.length === 0) {
216
+ // A middleware bundle without a readable manifest entry could cover anything.
217
+ return hasMiddlewareFile ? [
218
+ MATCH_ALL
219
+ ] : undefined;
220
+ }
221
+ const matchers = [];
222
+ for (const entry of entries){
223
+ if (!Array.isArray(entry.matchers) || entry.matchers.length === 0) {
224
+ matchers.push(MATCH_ALL);
225
+ continue;
226
+ }
227
+ for (const value of entry.matchers){
228
+ const matcher = asRecord(value);
229
+ if (typeof matcher.regexp !== 'string') {
230
+ matchers.push(MATCH_ALL);
231
+ continue;
232
+ }
233
+ matchers.push({
234
+ conditional: hasConditions(matcher),
235
+ ...typeof matcher.originalSource === 'string' ? {
236
+ originalSource: matcher.originalSource
237
+ } : {},
238
+ regexp: matcher.regexp
239
+ });
240
+ }
241
+ }
242
+ return matchers;
243
+ }
244
+ function readConfigRules(value) {
245
+ if (!Array.isArray(value)) {
246
+ return [];
247
+ }
248
+ return value.map((entry)=>{
249
+ const rule = asRecord(entry);
250
+ if (typeof rule.regex !== 'string' || typeof rule.source !== 'string') {
251
+ throw new Error('routes-manifest.json has a rule without source and regex');
252
+ }
253
+ const headers = Array.isArray(rule.headers) ? rule.headers.flatMap((header)=>{
254
+ const { key, value: headerValue } = asRecord(header);
255
+ return typeof key === 'string' && typeof headerValue === 'string' ? [
256
+ {
257
+ name: key,
258
+ value: headerValue
259
+ }
260
+ ] : [];
261
+ }) : undefined;
262
+ return {
263
+ conditional: hasConditions(rule),
264
+ ...headers ? {
265
+ headers
266
+ } : {},
267
+ regex: rule.regex,
268
+ source: rule.source
269
+ };
270
+ });
271
+ }
272
+ function hasRewrites(rewrites) {
273
+ if (Array.isArray(rewrites)) {
274
+ return rewrites.length > 0;
275
+ }
276
+ const { afterFiles, beforeFiles, fallback } = asRecord(rewrites);
277
+ return [
278
+ afterFiles,
279
+ beforeFiles,
280
+ fallback
281
+ ].some((list)=>Array.isArray(list) && list.length > 0);
282
+ }
283
+ // Older manifests use a plain array, which means afterFiles rewrites.
284
+ function readBeforeFilesRewrites(rewrites) {
285
+ const beforeFiles = Array.isArray(rewrites) ? [] : asRecord(rewrites).beforeFiles;
286
+ return Array.isArray(beforeFiles) ? beforeFiles : [];
287
+ }
288
+ function readRscHeaders(value) {
289
+ const rsc = asRecord(value);
290
+ const pick = (key, fallback)=>typeof rsc[key] === 'string' ? rsc[key].toLowerCase() : fallback;
291
+ return {
292
+ nextUrl: DEFAULT_RSC_HEADERS.nextUrl,
293
+ prefetch: pick('prefetchHeader', DEFAULT_RSC_HEADERS.prefetch),
294
+ rsc: pick('header', DEFAULT_RSC_HEADERS.rsc),
295
+ segmentPrefetch: pick('prefetchSegmentHeader', DEFAULT_RSC_HEADERS.segmentPrefetch),
296
+ stateTree: DEFAULT_RSC_HEADERS.stateTree
297
+ };
298
+ }
299
+ async function readStaticFiles(projectPath, output) {
300
+ const assets = await collectNextjsAssets(projectPath, output);
301
+ return assets.uploadKeys.map((key)=>{
302
+ const file = path.resolve(projectPath, assets.pathMap[key]);
303
+ const hashed = key.startsWith('_next/static/');
304
+ return {
305
+ file,
306
+ hashed,
307
+ kind: hashed ? 'build' : file.endsWith('.body') ? 'metadata' : 'public',
308
+ path: `/${key}`
309
+ };
310
+ });
311
+ }
312
+ /**
313
+ * Finds the `next` package the standalone server resolves, searching from the server file's
314
+ * directory up to the standalone root and never above it, so a Next.js installed elsewhere on the
315
+ * machine is never used.
316
+ */ async function findStandaloneNextPackage(serverEntryPath, standalonePath) {
317
+ const root = path.resolve(standalonePath);
318
+ for(let dir = path.dirname(path.resolve(serverEntryPath));; dir = path.dirname(dir)){
319
+ const candidate = path.join(dir, 'node_modules', 'next');
320
+ if (await isFile(path.join(candidate, 'package.json'))) {
321
+ return candidate;
322
+ }
323
+ if (dir === root || path.dirname(dir) === dir) {
324
+ return undefined;
325
+ }
326
+ }
327
+ }
328
+ /**
329
+ * Loads `computeCacheBustingSearchParam` from the Next.js that the standalone server runs, so the
330
+ * value always matches what that server validates. Never reimplement the hash: it changes between
331
+ * Next.js versions.
332
+ */ function loadRscParamFunction(nextDir) {
333
+ let mod;
334
+ try {
335
+ mod = createRequire(path.join(nextDir, 'package.json'))(path.join(nextDir, CACHE_BUSTING_MODULE));
336
+ } catch {
337
+ return undefined;
338
+ }
339
+ const compute = mod.computeCacheBustingSearchParam;
340
+ if (typeof compute !== 'function') {
341
+ return undefined;
342
+ }
343
+ return async ({ nextUrl, prefetch, segmentPrefetch, stateTree })=>String(await compute(prefetch, segmentPrefetch, stateTree, nextUrl));
344
+ }
345
+ function readNextVersion(nextDir) {
346
+ try {
347
+ const pkg = createRequire(path.join(nextDir, 'package.json'))(path.join(nextDir, 'package.json'));
348
+ return typeof pkg.version === 'string' ? pkg.version : undefined;
349
+ } catch {
350
+ return undefined;
351
+ }
352
+ }
353
+ async function readRequiredJson(filePath) {
354
+ const value = await readJson(filePath);
355
+ if (!value) {
356
+ throw new Error(`Next.js build output is missing or has an unreadable ${filePath}`);
357
+ }
358
+ return value;
359
+ }
360
+ function hasConditions(rule) {
361
+ return Array.isArray(rule.has) && rule.has.length > 0 || Array.isArray(rule.missing) && rule.missing.length > 0;
362
+ }
363
+ function asRecord(value) {
364
+ return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};
365
+ }
366
+ async function isFile(filePath) {
367
+ return fs.stat(filePath).then((stats)=>stats.isFile()).catch(()=>false);
368
+ }
@@ -0,0 +1,20 @@
1
+ import type { AdapterLogger } from '../../types.js';
2
+ import type { DeploymentInput } from '../core/build.js';
3
+ import type { NextBuildModel } from './read-build-output.js';
4
+ export declare const NEXTJS_SERVER_ID = "web";
5
+ export interface TranslateNextOptions {
6
+ /** Directory for the server ZIP. */
7
+ artifactDir: string;
8
+ logger?: AdapterLogger;
9
+ /** The app's root, where its dependencies are installed. */
10
+ projectPath: string;
11
+ /** Skips the unzipped size check, for `--skip-size-check`. */
12
+ skipSizeCheck?: boolean;
13
+ }
14
+ /**
15
+ * Translates a Next.js build into manifest v2 input. Framework behavior stays in the Next.js
16
+ * server: the manifest answers only requests it can prove match a prerendered artifact, and sends
17
+ * everything else, including every path middleware or request-dependent next.config rules cover,
18
+ * to the server.
19
+ */
20
+ export declare function toManifestV2Input(model: NextBuildModel, options: TranslateNextOptions): Promise<DeploymentInput>;