@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,58 @@
1
+ import { type BundleFile } from '../../fs-utils.js';
2
+ export declare const SERVER_ZIP_FILE_NAME = "server.zip";
3
+ /**
4
+ * Transitional launcher at the ZIP root. The current Event Function provider runs `run.sh` as the
5
+ * Lambda handler through Lambda Web Adapter, as it does for v1 bundles. The script is the same for
6
+ * every deployment: the control plane sets `AWS_LAMBDA_NODEJS_ENTRYPOINT` from the manifest's
7
+ * `servers.<id>.entrypoint` (CMSP-1065). Lambda Web Functions reads the same variable, so moving
8
+ * there removes the launcher but keeps that rule.
9
+ */
10
+ export declare const LAUNCHER_FILE_NAME = "run.sh";
11
+ export declare const LAUNCHER_SCRIPT = "#!/bin/bash\nmkdir -p /tmp/cache\nNODE_ENV=production exec node \"${AWS_LAMBDA_NODEJS_ENTRYPOINT:?AWS_LAMBDA_NODEJS_ENTRYPOINT is not set}\"\n";
12
+ export interface PackageServerOptions {
13
+ /** ZIP-relative path of the file the platform starts, such as `server.js`. */
14
+ entrypoint: string;
15
+ /**
16
+ * Files from outside `rootDir` to add, such as public files the server must serve. Each
17
+ * replaces any file at the same ZIP path in `rootDir`.
18
+ */
19
+ extraFiles?: Array<{
20
+ sourcePath: string;
21
+ zipPath: string;
22
+ }>;
23
+ /**
24
+ * Narrows the files from `rootDir` before they are counted and zipped, for framework rules such
25
+ * as dropping an optional dependency the app never uses.
26
+ */
27
+ filterFiles?: (files: BundleFile[]) => Promise<BundleFile[]>;
28
+ /**
29
+ * Largest unzipped size allowed, exclusive. Defaults to AWS Lambda's limit; null skips the check
30
+ * for callers that offer an override.
31
+ */
32
+ maxUnzippedBytes?: null | number;
33
+ /** Directory the ZIP is written to. */
34
+ outDir: string;
35
+ /** Files that replace or extend `rootDir`, keyed by ZIP-relative path. */
36
+ overrides?: Map<string, Buffer>;
37
+ /** Directory whose contents become the ZIP root. */
38
+ rootDir: string;
39
+ }
40
+ export interface PackagedServer {
41
+ entrypoint: string;
42
+ /** Total bytes of the ZIP's contents before compression. */
43
+ unzippedBytes: number;
44
+ /** Absolute path of the server ZIP. */
45
+ zipPath: string;
46
+ }
47
+ export declare class ServerPackageError extends Error {
48
+ constructor(message: string);
49
+ }
50
+ /**
51
+ * ZIPs a built server for manifest v2. The ZIP holds `rootDir` and any overrides, minus local
52
+ * secrets, plus the shared {@link LAUNCHER_SCRIPT} as {@link LAUNCHER_FILE_NAME}, which replaces any
53
+ * `run.sh` in the build.
54
+ *
55
+ * Throws when the entrypoint is unsafe or isn't a regular file in the ZIP, when a symlink escapes
56
+ * `rootDir` ({@link EscapingSymlinkError}), and when the unzipped size reaches the limit.
57
+ */
58
+ export declare function packageServer(options: PackageServerOptions): Promise<PackagedServer>;
@@ -0,0 +1,123 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { walkBundleFiles } from '../../fs-utils.js';
4
+ import { LAMBDA_MAX_UNZIPPED_BYTES } from '../../lambdaLimits.js';
5
+ import { isBundlableFile } from '../../secret-files.js';
6
+ import { writeZip } from '../../writeZip.js';
7
+ import { getRelativePathError } from './getRelativePathError.js';
8
+ export const SERVER_ZIP_FILE_NAME = 'server.zip';
9
+ /**
10
+ * Transitional launcher at the ZIP root. The current Event Function provider runs `run.sh` as the
11
+ * Lambda handler through Lambda Web Adapter, as it does for v1 bundles. The script is the same for
12
+ * every deployment: the control plane sets `AWS_LAMBDA_NODEJS_ENTRYPOINT` from the manifest's
13
+ * `servers.<id>.entrypoint` (CMSP-1065). Lambda Web Functions reads the same variable, so moving
14
+ * there removes the launcher but keeps that rule.
15
+ */ export const LAUNCHER_FILE_NAME = 'run.sh';
16
+ export const LAUNCHER_SCRIPT = `#!/bin/bash
17
+ mkdir -p /tmp/cache
18
+ NODE_ENV=production exec node "\${AWS_LAMBDA_NODEJS_ENTRYPOINT:?AWS_LAMBDA_NODEJS_ENTRYPOINT is not set}"
19
+ `;
20
+ export class ServerPackageError extends Error {
21
+ constructor(message){
22
+ super(message);
23
+ this.name = 'ServerPackageError';
24
+ }
25
+ }
26
+ /**
27
+ * ZIPs a built server for manifest v2. The ZIP holds `rootDir` and any overrides, minus local
28
+ * secrets, plus the shared {@link LAUNCHER_SCRIPT} as {@link LAUNCHER_FILE_NAME}, which replaces any
29
+ * `run.sh` in the build.
30
+ *
31
+ * Throws when the entrypoint is unsafe or isn't a regular file in the ZIP, when a symlink escapes
32
+ * `rootDir` ({@link EscapingSymlinkError}), and when the unzipped size reaches the limit.
33
+ */ export async function packageServer(options) {
34
+ const { entrypoint, outDir, rootDir } = options;
35
+ const overrides = options.overrides ?? new Map();
36
+ const maxUnzippedBytes = options.maxUnzippedBytes === undefined ? LAMBDA_MAX_UNZIPPED_BYTES : options.maxUnzippedBytes;
37
+ const entrypointError = getRelativePathError(entrypoint);
38
+ if (entrypointError) {
39
+ throw new ServerPackageError(`Server entrypoint ${JSON.stringify(entrypoint)} ${entrypointError}`);
40
+ }
41
+ if (entrypoint === LAUNCHER_FILE_NAME) {
42
+ throw new ServerPackageError(`Server entrypoint cannot be ${LAUNCHER_FILE_NAME}; it is generated to start the entrypoint`);
43
+ }
44
+ const extraFiles = await statExtraFiles(options.extraFiles ?? []);
45
+ for (const name of [
46
+ ...overrides.keys(),
47
+ ...extraFiles.map((file)=>file.relativePath)
48
+ ]){
49
+ const error = getRelativePathError(name);
50
+ if (error) {
51
+ throw new ServerPackageError(`Server file ${JSON.stringify(name)} ${error}`);
52
+ }
53
+ }
54
+ const replaced = new Set([
55
+ ...extraFiles.map((file)=>file.relativePath),
56
+ ...overrides.keys()
57
+ ]);
58
+ const rootFiles = (await walkBundleFiles(rootDir)).filter((file)=>isBundlableFile(file.relativePath) && !replaced.has(file.relativePath));
59
+ const files = [
60
+ ...options.filterFiles ? await options.filterFiles(rootFiles) : rootFiles,
61
+ ...extraFiles.filter((file)=>!overrides.has(file.relativePath))
62
+ ].filter((file)=>file.relativePath !== LAUNCHER_FILE_NAME);
63
+ await assertEntrypointIsRegularFile(entrypoint, files, overrides);
64
+ const generated = new Map(overrides);
65
+ generated.set(LAUNCHER_FILE_NAME, Buffer.from(LAUNCHER_SCRIPT));
66
+ const unzippedBytes = files.reduce((total, file)=>total + file.size, 0) + [
67
+ ...generated.values()
68
+ ].reduce((total, contents)=>total + contents.byteLength, 0);
69
+ if (maxUnzippedBytes !== null && unzippedBytes >= maxUnzippedBytes) {
70
+ throw new ServerPackageError(`Unzipped server size (${unzippedBytes} bytes) is at or over the ${maxUnzippedBytes}-byte limit`);
71
+ }
72
+ await fs.mkdir(outDir, {
73
+ recursive: true
74
+ });
75
+ const zipPath = path.join(outDir, SERVER_ZIP_FILE_NAME);
76
+ await writeZip({
77
+ entries: [
78
+ ...files.map((file)=>({
79
+ name: file.relativePath,
80
+ sourcePath: file.sourcePath
81
+ })),
82
+ ...[
83
+ ...generated
84
+ ].map(([name, contents])=>({
85
+ name,
86
+ contents,
87
+ mode: name === LAUNCHER_FILE_NAME ? 0o755 : 0o644
88
+ }))
89
+ ],
90
+ zipPath
91
+ });
92
+ return {
93
+ entrypoint,
94
+ unzippedBytes,
95
+ zipPath
96
+ };
97
+ }
98
+ async function statExtraFiles(extraFiles) {
99
+ return Promise.all(extraFiles.map(async ({ sourcePath, zipPath })=>{
100
+ const stats = await fs.stat(sourcePath).catch(()=>null);
101
+ if (!stats?.isFile()) {
102
+ throw new ServerPackageError(`Server file ${sourcePath} is not a regular file`);
103
+ }
104
+ return {
105
+ relativePath: zipPath,
106
+ size: stats.size,
107
+ sourcePath
108
+ };
109
+ }));
110
+ }
111
+ async function assertEntrypointIsRegularFile(entrypoint, files, overrides) {
112
+ if (overrides.has(entrypoint)) {
113
+ return;
114
+ }
115
+ const file = files.find((candidate)=>candidate.relativePath === entrypoint);
116
+ if (!file) {
117
+ throw new ServerPackageError(`Server entrypoint ${entrypoint} is not in the server bundle`);
118
+ }
119
+ // A symlink would be stored as a link entry, which the platform can't start.
120
+ if (!(await fs.lstat(file.sourcePath)).isFile()) {
121
+ throw new ServerPackageError(`Server entrypoint ${entrypoint} is not a regular file`);
122
+ }
123
+ }
@@ -0,0 +1,46 @@
1
+ import type { ManifestServices } from './types.js';
2
+ /** The project file both CLIs read service declarations from, relative to the project root. */
3
+ export declare const DEPLOY_CONFIG_PATH: string;
4
+ export declare const SERVICE_NAMES: readonly ["contentSystem", "figmaOauth"];
5
+ export type ServiceName = (typeof SERVICE_NAMES)[number];
6
+ /** Where a resolved service value came from. */
7
+ export type ServiceSource = 'default' | 'deploy.json' | 'payload config';
8
+ export type ServiceRequests = Partial<Record<ServiceName, boolean>>;
9
+ /**
10
+ * A service's value in `.figma/make/deploy.json`: an object or `true` requests it, `false` opts
11
+ * out. Service objects have no settings yet.
12
+ */
13
+ export type ServiceDeclaration = boolean | Record<string, never>;
14
+ /** The service keys of `.figma/make/deploy.json`; its other keys belong to other tools. */
15
+ export type DeclaredServices = Partial<Record<ServiceName, ServiceDeclaration>>;
16
+ export interface ResolvedServices {
17
+ /** Omitted when nothing is requested, which the manifest treats as both false. */
18
+ services?: ManifestServices;
19
+ sources: Record<ServiceName, ServiceSource>;
20
+ }
21
+ export declare class ServiceDeclarationError extends Error {
22
+ constructor(message: string);
23
+ }
24
+ /**
25
+ * Resolves the services a project needs, per service: its top-level key in
26
+ * `.figma/make/deploy.json`, then the framework integration's configuration, then none. Runs
27
+ * before the build, so the result can also drive the pre-deploy services API.
28
+ */
29
+ export declare function resolveProjectServices(projectPath: string): Promise<ResolvedServices>;
30
+ /** Combines declared and integration requests. An explicit declaration, including false, wins. */
31
+ export declare function resolveServices(options: {
32
+ declared: ServiceRequests;
33
+ integration?: ServiceRequests;
34
+ }): ResolvedServices;
35
+ /**
36
+ * Reads the service keys from `.figma/make/deploy.json`. An object or `true` requests a service,
37
+ * `false` opts out, and an absent key leaves the decision to the integration. Service objects
38
+ * have no settings yet, so a non-empty object is an error rather than being ignored.
39
+ */
40
+ export declare function readDeclaredServices(projectPath: string): Promise<ServiceRequests>;
41
+ /**
42
+ * Reads a Payload project's services from its config: a `buildFigmaConfig` call requests the
43
+ * content system unless `figma.useContentSystem` is literally false, and always requests Figma
44
+ * OAuth, which `buildFigmaConfig` always adds. Returns undefined for a project without one.
45
+ */
46
+ export declare function detectPayloadServices(projectPath: string): Promise<ServiceRequests | undefined>;
@@ -0,0 +1,202 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { Node, Project, SyntaxKind } from 'ts-morph';
4
+ /** The project file both CLIs read service declarations from, relative to the project root. */ export const DEPLOY_CONFIG_PATH = path.join('.figma', 'make', 'deploy.json');
5
+ export const SERVICE_NAMES = [
6
+ 'contentSystem',
7
+ 'figmaOauth'
8
+ ];
9
+ export class ServiceDeclarationError extends Error {
10
+ constructor(message){
11
+ super(message);
12
+ this.name = 'ServiceDeclarationError';
13
+ }
14
+ }
15
+ // Mirrors payload-config-finder's fallback list; Payload's own finder isn't available here.
16
+ const PAYLOAD_CONFIG_FILES = [
17
+ 'payload.config.ts',
18
+ 'payload.config.js',
19
+ 'src/payload.config.ts',
20
+ 'src/payload.config.js'
21
+ ];
22
+ /**
23
+ * Resolves the services a project needs, per service: its top-level key in
24
+ * `.figma/make/deploy.json`, then the framework integration's configuration, then none. Runs
25
+ * before the build, so the result can also drive the pre-deploy services API.
26
+ */ export async function resolveProjectServices(projectPath) {
27
+ return resolveServices({
28
+ declared: await readDeclaredServices(projectPath),
29
+ integration: await detectPayloadServices(projectPath)
30
+ });
31
+ }
32
+ /** Combines declared and integration requests. An explicit declaration, including false, wins. */ export function resolveServices(options) {
33
+ const services = {};
34
+ const sources = {};
35
+ for (const name of SERVICE_NAMES){
36
+ const declared = options.declared[name];
37
+ const integration = options.integration?.[name];
38
+ if (declared !== undefined) {
39
+ services[name] = declared;
40
+ sources[name] = 'deploy.json';
41
+ } else if (integration !== undefined) {
42
+ services[name] = integration;
43
+ sources[name] = 'payload config';
44
+ } else {
45
+ services[name] = false;
46
+ sources[name] = 'default';
47
+ }
48
+ }
49
+ const requested = SERVICE_NAMES.some((name)=>services[name]);
50
+ return {
51
+ ...requested ? {
52
+ services
53
+ } : {},
54
+ sources
55
+ };
56
+ }
57
+ /**
58
+ * Reads the service keys from `.figma/make/deploy.json`. An object or `true` requests a service,
59
+ * `false` opts out, and an absent key leaves the decision to the integration. Service objects
60
+ * have no settings yet, so a non-empty object is an error rather than being ignored.
61
+ */ export async function readDeclaredServices(projectPath) {
62
+ const configPath = path.join(projectPath, DEPLOY_CONFIG_PATH);
63
+ let contents;
64
+ try {
65
+ contents = await fs.readFile(configPath, 'utf8');
66
+ } catch (error) {
67
+ if (error.code === 'ENOENT') {
68
+ return {};
69
+ }
70
+ throw error;
71
+ }
72
+ let config;
73
+ try {
74
+ config = JSON.parse(contents);
75
+ } catch {
76
+ throw new ServiceDeclarationError(`${DEPLOY_CONFIG_PATH} is not valid JSON`);
77
+ }
78
+ if (config === null || typeof config !== 'object' || Array.isArray(config)) {
79
+ throw new ServiceDeclarationError(`${DEPLOY_CONFIG_PATH} must contain a JSON object`);
80
+ }
81
+ const declared = config;
82
+ const requests = {};
83
+ for (const name of SERVICE_NAMES){
84
+ if (!(name in declared)) {
85
+ continue;
86
+ }
87
+ const declaration = declared[name];
88
+ assertServiceDeclaration(name, declaration);
89
+ requests[name] = declaration !== false;
90
+ }
91
+ return requests;
92
+ }
93
+ /**
94
+ * Reads a Payload project's services from its config: a `buildFigmaConfig` call requests the
95
+ * content system unless `figma.useContentSystem` is literally false, and always requests Figma
96
+ * OAuth, which `buildFigmaConfig` always adds. Returns undefined for a project without one.
97
+ */ export async function detectPayloadServices(projectPath) {
98
+ const configPath = await findPayloadConfigFile(projectPath);
99
+ if (!configPath) {
100
+ return undefined;
101
+ }
102
+ const project = new Project({
103
+ skipAddingFilesFromTsConfig: true,
104
+ useInMemoryFileSystem: true
105
+ });
106
+ const sourceFile = project.createSourceFile(configPath, await fs.readFile(configPath, 'utf8'));
107
+ const callees = buildFigmaConfigCallees(sourceFile);
108
+ const call = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).find((candidate)=>callees.has(candidate.getExpression().getText()));
109
+ if (!call) {
110
+ return undefined;
111
+ }
112
+ return {
113
+ contentSystem: !usesContentSystemFalse(call.getArguments()[0]),
114
+ figmaOauth: true
115
+ };
116
+ }
117
+ // deploy.json is user-written JSON, so each declaration is checked at runtime.
118
+ function assertServiceDeclaration(name, value) {
119
+ if (typeof value === 'boolean') {
120
+ return;
121
+ }
122
+ if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
123
+ const settings = Object.keys(value);
124
+ if (settings.length > 0) {
125
+ throw new ServiceDeclarationError(`${DEPLOY_CONFIG_PATH}: ${name} has no settings yet; unknown ${settings.map((key)=>JSON.stringify(key)).join(', ')}`);
126
+ }
127
+ return;
128
+ }
129
+ throw new ServiceDeclarationError(`${DEPLOY_CONFIG_PATH}: ${name} must be an object, true or false`);
130
+ }
131
+ /**
132
+ * The expressions that call `buildFigmaConfig` in this file: its local name, including an import
133
+ * alias (`import { buildFigmaConfig as buildConfig }`), and `<namespace>.buildFigmaConfig` for a
134
+ * namespace import. Without an import from `@payloadcms/figma`, the plain name.
135
+ */ function buildFigmaConfigCallees(sourceFile) {
136
+ const callees = new Set();
137
+ for (const declaration of sourceFile.getImportDeclarations()){
138
+ if (declaration.getModuleSpecifierValue() !== '@payloadcms/figma') {
139
+ continue;
140
+ }
141
+ for (const specifier of declaration.getNamedImports()){
142
+ if (specifier.getName() === 'buildFigmaConfig') {
143
+ callees.add(specifier.getAliasNode()?.getText() ?? 'buildFigmaConfig');
144
+ }
145
+ }
146
+ const namespace = declaration.getNamespaceImport()?.getText();
147
+ if (namespace) {
148
+ callees.add(`${namespace}.buildFigmaConfig`);
149
+ }
150
+ }
151
+ return callees.size > 0 ? callees : new Set([
152
+ 'buildFigmaConfig'
153
+ ]);
154
+ }
155
+ // Only a literal `false` that nothing later can overwrite opts out; anything else keeps
156
+ // buildFigmaConfig's default of true.
157
+ function usesContentSystemFalse(configArg) {
158
+ const figma = finalPropertyValue(configArg, 'figma');
159
+ const useContentSystem = finalPropertyValue(figma, 'useContentSystem');
160
+ return useContentSystem?.getKind() === SyntaxKind.FalseKeyword;
161
+ }
162
+ /**
163
+ * The value an object literal finally gives `name`, seen through `as`, `satisfies` and
164
+ * parentheses. Undefined when it isn't a literal property, or when a later spread could replace it.
165
+ */ function finalPropertyValue(node, name) {
166
+ const object = unwrapExpression(node);
167
+ if (!object || !Node.isObjectLiteralExpression(object)) {
168
+ return undefined;
169
+ }
170
+ let value;
171
+ for (const property of object.getProperties()){
172
+ if (Node.isSpreadAssignment(property)) {
173
+ value = undefined;
174
+ } else if (Node.isPropertyAssignment(property) && property.getName() === name) {
175
+ value = unwrapExpression(property.getInitializer());
176
+ }
177
+ }
178
+ return value;
179
+ }
180
+ function unwrapExpression(node) {
181
+ let current = node;
182
+ while(current && (Node.isAsExpression(current) || Node.isSatisfiesExpression(current) || Node.isParenthesizedExpression(current) || Node.isTypeAssertion(current))){
183
+ current = current.getExpression();
184
+ }
185
+ return current;
186
+ }
187
+ /**
188
+ * Finds the Payload config the way Payload does: `PAYLOAD_CONFIG_PATH` when it is set (relative
189
+ * to the project), and the conventional locations otherwise.
190
+ */ async function findPayloadConfigFile(projectPath) {
191
+ const configured = process.env.PAYLOAD_CONFIG_PATH;
192
+ const files = configured ? [
193
+ configured
194
+ ] : PAYLOAD_CONFIG_FILES;
195
+ for (const file of files){
196
+ const candidate = path.resolve(projectPath, file);
197
+ if (await fs.stat(candidate).then((stats)=>stats.isFile()).catch(()=>false)) {
198
+ return candidate;
199
+ }
200
+ }
201
+ return undefined;
202
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The request paths that name a build file, relative to the output root with forward slashes.
3
+ * Gatekeeper matches static keys against the path as received, percent-encoded, with nothing
4
+ * decoded, so a file gets a key for each form a client sends:
5
+ *
6
+ * - the form a browser produces from a raw link, which keeps characters such as `[`, `]` and `@`;
7
+ * - each segment fully encoded, the form frameworks such as Next.js use for their own chunk URLs
8
+ * (`app/%5Bslug%5D/page-abc.js`).
9
+ *
10
+ * Both forms are usually the same, so most files get one key. Neither form contains an encoded
11
+ * `/`, which the control plane rejects.
12
+ */
13
+ export declare function staticPathsForFile(relativePath: string): string[];
@@ -0,0 +1,32 @@
1
+ // What the URL parser doesn't encode the way a file name needs: it leaves `%` as is, reads `\` as
2
+ // `/`, and drops tabs and newlines.
3
+ const URL_PARSER_UNSAFE = /[%\\\t\n\r]/g;
4
+ /**
5
+ * The request paths that name a build file, relative to the output root with forward slashes.
6
+ * Gatekeeper matches static keys against the path as received, percent-encoded, with nothing
7
+ * decoded, so a file gets a key for each form a client sends:
8
+ *
9
+ * - the form a browser produces from a raw link, which keeps characters such as `[`, `]` and `@`;
10
+ * - each segment fully encoded, the form frameworks such as Next.js use for their own chunk URLs
11
+ * (`app/%5Bslug%5D/page-abc.js`).
12
+ *
13
+ * Both forms are usually the same, so most files get one key. Neither form contains an encoded
14
+ * `/`, which the control plane rejects.
15
+ */ export function staticPathsForFile(relativePath) {
16
+ const browser = browserPath(relativePath);
17
+ const encoded = `/${relativePath.split('/').map(encodeURIComponent).join('/')}`;
18
+ return browser === encoded ? [
19
+ browser
20
+ ] : [
21
+ browser,
22
+ encoded
23
+ ];
24
+ }
25
+ /**
26
+ * The path a browser requests for a raw link to the file. The URL `pathname` setter applies the
27
+ * WHATWG path percent-encoding, the same algorithm browsers use.
28
+ */ function browserPath(relativePath) {
29
+ const url = new URL('http://static.invalid');
30
+ url.pathname = `/${relativePath.replace(URL_PARSER_UNSAFE, encodeURIComponent)}`;
31
+ return url.pathname;
32
+ }
@@ -0,0 +1,26 @@
1
+ import type { DeploymentInput } from './build.js';
2
+ import type { ManifestSource } from './types.js';
3
+ export interface StaticSiteOptions {
4
+ /**
5
+ * Also serves `page.html` at `/page` when no file or directory index has that path, like the
6
+ * Make sites worker's clean URLs (Next.js `output: 'export'` emits pages this way). Off by
7
+ * default: Gatekeeper's v1 static serving has no clean URLs.
8
+ */
9
+ cleanUrls?: boolean;
10
+ /**
11
+ * `spa` serves the root index.html for unknown GET and HEAD paths. `notFound` serves 404.html
12
+ * with status 404 when the build has one, and the platform 404 otherwise.
13
+ */
14
+ fallback: 'notFound' | 'spa';
15
+ /** The build output root: every publishable file under it is served at its relative path. */
16
+ outputDir: string;
17
+ source?: ManifestSource;
18
+ }
19
+ /**
20
+ * Describes a static build as manifest v2 input. Every file is served at its own path, and a
21
+ * directory's index.html also at the directory path with and without a trailing slash. Local
22
+ * secrets and `node_modules` are never published. Every file revalidates: a static build doesn't
23
+ * prove which file names are content-hashed, and a wrong `immutable` keeps a stale file in browsers
24
+ * for a year.
25
+ */
26
+ export declare function createStaticSiteInput(options: StaticSiteOptions): Promise<DeploymentInput>;
@@ -0,0 +1,95 @@
1
+ import path from 'path';
2
+ import { collectFilesRecursive } from '../../fs-utils.js';
3
+ import { isPublishableAsset } from '../../secret-files.js';
4
+ import { responseIdForPath } from './build.js';
5
+ import { staticPathsForFile } from './static-path.js';
6
+ /**
7
+ * Describes a static build as manifest v2 input. Every file is served at its own path, and a
8
+ * directory's index.html also at the directory path with and without a trailing slash. Local
9
+ * secrets and `node_modules` are never published. Every file revalidates: a static build doesn't
10
+ * prove which file names are content-hashed, and a wrong `immutable` keeps a stale file in browsers
11
+ * for a year.
12
+ */ export async function createStaticSiteInput(options) {
13
+ const { outputDir } = options;
14
+ const files = (await collectFilesRecursive(outputDir, outputDir)).filter(isPublishableAsset).sort();
15
+ const fileSet = new Set(files);
16
+ const taken = new Set();
17
+ const responses = {};
18
+ const staticMap = {};
19
+ for (const file of files){
20
+ const publicPath = `/${file}`;
21
+ const id = responseIdForPath(publicPath, taken);
22
+ responses[id] = {
23
+ file: path.join(outputDir, file)
24
+ };
25
+ for (const key of staticPathsForFile(file)){
26
+ staticMap[key] = id;
27
+ }
28
+ if (path.posix.basename(file) === 'index.html') {
29
+ const dir = path.posix.dirname(file);
30
+ if (dir === '.') {
31
+ staticMap['/'] = id;
32
+ } else {
33
+ for (const key of staticPathsForFile(dir)){
34
+ staticMap[`${key}/`] = id;
35
+ if (!fileSet.has(dir)) {
36
+ staticMap[key] = id;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+ // After every file and directory index, which take precedence.
43
+ if (options.cleanUrls) {
44
+ addCleanUrls(files, staticMap);
45
+ }
46
+ return {
47
+ fallback: createFallback(options.fallback, staticMap, responses, outputDir, taken, fileSet),
48
+ responses,
49
+ rootDir: outputDir,
50
+ routes: [],
51
+ ...options.source ? {
52
+ source: options.source
53
+ } : {},
54
+ static: staticMap
55
+ };
56
+ }
57
+ function addCleanUrls(files, staticMap) {
58
+ for (const file of files){
59
+ // index.html too: the sites worker serves /about/index from about/index.html.
60
+ if (!file.endsWith('.html')) {
61
+ continue;
62
+ }
63
+ const id = staticMap[staticPathsForFile(file)[0]];
64
+ for (const key of staticPathsForFile(file.slice(0, -'.html'.length))){
65
+ staticMap[key] ??= id;
66
+ }
67
+ }
68
+ }
69
+ function createFallback(type, staticMap, responses, outputDir, taken, fileSet) {
70
+ if (type === 'spa') {
71
+ const index = staticMap['/index.html'];
72
+ if (!index) {
73
+ throw new Error(`A single-page app needs index.html at the root of ${outputDir}`);
74
+ }
75
+ return {
76
+ type: 'spa',
77
+ response: index
78
+ };
79
+ }
80
+ if (!fileSet.has('404.html')) {
81
+ return {
82
+ type: 'notFound'
83
+ };
84
+ }
85
+ // /404.html itself stays a 200 response; the fallback copy carries the 404 status.
86
+ const id = responseIdForPath('/404-fallback', taken);
87
+ responses[id] = {
88
+ file: path.join(outputDir, '404.html'),
89
+ status: 404
90
+ };
91
+ return {
92
+ type: 'notFound',
93
+ response: id
94
+ };
95
+ }