@payloadcms/figma 0.1.0-alpha.1 → 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/dist/{utils → adapters}/asset-collection.d.ts +17 -3
- package/dist/adapters/asset-collection.js +242 -0
- package/dist/{utils → adapters}/build-lambda-zip.d.ts +8 -7
- package/dist/adapters/build-lambda-zip.js +111 -0
- package/dist/adapters/configureNextjsCache.d.ts +8 -0
- package/dist/adapters/configureNextjsCache.js +55 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +1 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +15 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.d.ts +12 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.js +28 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.d.ts +9 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.js +13 -0
- package/dist/adapters/deploy-output/isFile.d.ts +1 -0
- package/dist/adapters/deploy-output/isFile.js +4 -0
- package/dist/adapters/deploy-output/readJson.d.ts +1 -0
- package/dist/adapters/deploy-output/readJson.js +9 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.d.ts +8 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.js +16 -0
- package/dist/adapters/deploy-output/resolveOutputPath.d.ts +2 -0
- package/dist/adapters/deploy-output/resolveOutputPath.js +9 -0
- package/dist/adapters/deploy-output/resolveWithin.d.ts +1 -0
- package/dist/adapters/deploy-output/resolveWithin.js +12 -0
- package/dist/adapters/fs-utils.d.ts +39 -0
- package/dist/adapters/fs-utils.js +135 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.d.ts +40 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.js +174 -0
- package/dist/adapters/nextjs.d.ts +12 -0
- package/dist/adapters/nextjs.js +67 -0
- package/dist/adapters/nitro.d.ts +8 -0
- package/dist/adapters/nitro.js +193 -0
- package/dist/adapters/secret-files.d.ts +25 -0
- package/dist/adapters/secret-files.js +50 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.js +1 -0
- package/dist/{utils/adapters → adapters}/vite.d.ts +2 -2
- package/dist/adapters/vite.js +33 -0
- package/dist/api/check-project-subdomain-availability.d.ts +12 -0
- package/dist/api/check-project-subdomain-availability.js +32 -0
- package/dist/api/control-plane-error.d.ts +6 -0
- package/dist/api/control-plane-error.js +8 -0
- package/dist/api/control-plane-fetch.d.ts +7 -0
- package/dist/api/control-plane-fetch.js +37 -0
- package/dist/api/control-plane.d.ts +1 -9
- package/dist/api/control-plane.js +2 -48
- package/dist/api/create-project.d.ts +18 -0
- package/dist/api/create-project.js +37 -0
- package/dist/api/list-project-workspaces.d.ts +8 -0
- package/dist/api/list-project-workspaces.js +28 -0
- package/dist/api/project-resource-type.d.ts +1 -0
- package/dist/api/project-resource-type.js +1 -0
- package/dist/auth/headless-oauth-flow.d.ts +23 -0
- package/dist/auth/headless-oauth-flow.js +69 -0
- package/dist/auth/oauth-flow.d.ts +2 -0
- package/dist/auth/oauth-flow.js +13 -8
- package/dist/auth/token-store.d.ts +4 -1
- package/dist/auth/token-store.js +14 -0
- package/dist/auth/types.d.ts +12 -0
- package/dist/cli.d.ts +39 -0
- package/dist/cli.js +71 -36
- package/dist/commands/bootstrap.js +2 -1
- package/dist/commands/build-lambda-zip.js +1 -1
- package/dist/commands/deploy.d.ts +12 -0
- package/dist/commands/deploy.js +63 -25
- package/dist/commands/detect-project-resource-type.d.ts +3 -0
- package/dist/commands/detect-project-resource-type.js +28 -0
- package/dist/commands/init.d.ts +2 -2
- package/dist/commands/init.js +164 -79
- package/dist/commands/login.d.ts +11 -1
- package/dist/commands/login.js +66 -4
- package/dist/commands/prompt-to-create-project/format-project-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-project-subdomain.js +3 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.js +7 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.js +13 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.d.ts +7 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.js +32 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.d.ts +8 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.js +27 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.js +54 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.js +23 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.d.ts +12 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.js +36 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.js +9 -0
- package/dist/commands/prompt-to-create-project.d.ts +24 -0
- package/dist/commands/prompt-to-create-project.js +69 -0
- package/dist/commands/setup-agent.d.ts +12 -0
- package/dist/commands/setup-agent.js +123 -0
- package/dist/commands/write-project-configuration.d.ts +12 -0
- package/dist/commands/write-project-configuration.js +16 -0
- package/dist/db-content-api/generated/content-api-types.d.ts +6 -2
- package/dist/db-content-api/index.d.ts +1 -1
- package/dist/db-content-api/index.js +121 -72
- package/dist/db-content-api/utilities/data/index.js +2 -2
- package/dist/db-content-api/utilities/data/injectGlobalType.d.ts +6 -0
- package/dist/db-content-api/utilities/data/injectGlobalType.js +11 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +3 -11
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
- package/dist/db-content-api/utilities/isRecord.d.ts +9 -0
- package/dist/db-content-api/utilities/isRecord.js +19 -0
- package/dist/db-content-api/utilities/joins.js +5 -1
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.d.ts +10 -0
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.js +95 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.d.ts +9 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.js +112 -0
- package/dist/db-content-api/utilities/schema/getDocumentSchema.d.ts +3 -0
- package/dist/db-content-api/utilities/schema/getDocumentSchema.js +24 -0
- package/dist/db-content-api/utilities/where.d.ts +2 -6
- package/dist/db-content-api/utilities/where.js +20 -9
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.js +2 -0
- package/dist/exports/views.d.ts +1 -0
- package/dist/exports/views.js +1 -0
- package/dist/imageSizeOptions.d.ts +23 -0
- package/dist/imageSizeOptions.js +26 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/write-agent-config.d.ts +12 -0
- package/dist/lib/write-agent-config.js +52 -0
- package/dist/next/image-loader.d.ts +6 -0
- package/dist/next/image-loader.js +14 -0
- package/dist/oauth/components/LoginButton/index.js +66 -19
- package/dist/oauth/components/LoginButton/index.scss +121 -15
- package/dist/oauth/defaults.js +4 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js +5 -2
- package/dist/oauth/index.js +8 -7
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +1 -1
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +5 -1
- package/dist/plugin/build-config.d.ts +4 -2
- package/dist/plugin/build-config.js +95 -31
- package/dist/plugin/cache-revalidation-hooks.d.ts +6 -0
- package/dist/plugin/cache-revalidation-hooks.js +69 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +8 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.js +66 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.scss +56 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.js +110 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.css +14 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.js +52 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.d.ts +7 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.js +3 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.d.ts +1 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.js +27 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.js +30 -0
- package/dist/plugin/cloud-limits/routes.d.ts +2 -0
- package/dist/plugin/cloud-limits/routes.js +4 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.d.ts +9 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.js +28 -0
- package/dist/plugin/cloud-limits/shared.d.ts +10 -0
- package/dist/plugin/cloud-limits/shared.js +52 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.d.ts +2 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.js +134 -0
- package/dist/plugin/cloud-limits/utilities/toasts.d.ts +4 -0
- package/dist/plugin/cloud-limits/utilities/toasts.js +19 -0
- package/dist/plugin/make-permission-access/make-permission-access.d.ts +8 -0
- package/dist/plugin/make-permission-access/make-permission-access.js +24 -0
- package/dist/plugin/sandbox-upload-fetch.d.ts +32 -0
- package/dist/plugin/sandbox-upload-fetch.js +53 -0
- package/dist/skills/deploy-to-figma/SKILL.md +234 -0
- package/dist/skills/deploy-to-figma/references/cli-reference.md +146 -0
- package/dist/storage-content-api/client-uploads/generate.js +2 -1
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +11 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +27 -0
- package/dist/storage-content-api/index.js +1 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
- package/dist/storage-content-api/staticHandler.js +2 -1
- package/dist/storage-content-api/types.d.ts +4 -1
- package/dist/translations/ar.d.ts +12 -0
- package/dist/translations/ar.js +12 -0
- package/dist/translations/az.d.ts +12 -0
- package/dist/translations/az.js +12 -0
- package/dist/translations/bg.d.ts +12 -0
- package/dist/translations/bg.js +12 -0
- package/dist/translations/bnBd.d.ts +12 -0
- package/dist/translations/bnBd.js +12 -0
- package/dist/translations/bnIn.d.ts +12 -0
- package/dist/translations/bnIn.js +12 -0
- package/dist/translations/ca.d.ts +12 -0
- package/dist/translations/ca.js +12 -0
- package/dist/translations/cs.d.ts +12 -0
- package/dist/translations/cs.js +12 -0
- package/dist/translations/da.d.ts +12 -0
- package/dist/translations/da.js +12 -0
- package/dist/translations/de.d.ts +12 -0
- package/dist/translations/de.js +12 -0
- package/dist/translations/en.d.ts +12 -0
- package/dist/translations/en.js +12 -0
- package/dist/translations/es.d.ts +12 -0
- package/dist/translations/es.js +12 -0
- package/dist/translations/et.d.ts +12 -0
- package/dist/translations/et.js +12 -0
- package/dist/translations/fa.d.ts +12 -0
- package/dist/translations/fa.js +12 -0
- package/dist/translations/fr.d.ts +12 -0
- package/dist/translations/fr.js +12 -0
- package/dist/translations/he.d.ts +12 -0
- package/dist/translations/he.js +12 -0
- package/dist/translations/hr.d.ts +12 -0
- package/dist/translations/hr.js +12 -0
- package/dist/translations/hu.d.ts +12 -0
- package/dist/translations/hu.js +12 -0
- package/dist/translations/hy.d.ts +12 -0
- package/dist/translations/hy.js +12 -0
- package/dist/translations/id.d.ts +12 -0
- package/dist/translations/id.js +12 -0
- package/dist/translations/index.d.ts +533 -0
- package/dist/translations/index.js +90 -0
- package/dist/translations/is.d.ts +12 -0
- package/dist/translations/is.js +12 -0
- package/dist/translations/it.d.ts +12 -0
- package/dist/translations/it.js +12 -0
- package/dist/translations/ja.d.ts +12 -0
- package/dist/translations/ja.js +12 -0
- package/dist/translations/ko.d.ts +12 -0
- package/dist/translations/ko.js +12 -0
- package/dist/translations/lt.d.ts +12 -0
- package/dist/translations/lt.js +12 -0
- package/dist/translations/lv.d.ts +12 -0
- package/dist/translations/lv.js +12 -0
- package/dist/translations/my.d.ts +12 -0
- package/dist/translations/my.js +12 -0
- package/dist/translations/nb.d.ts +12 -0
- package/dist/translations/nb.js +12 -0
- package/dist/translations/nl.d.ts +12 -0
- package/dist/translations/nl.js +12 -0
- package/dist/translations/pl.d.ts +12 -0
- package/dist/translations/pl.js +12 -0
- package/dist/translations/pt.d.ts +12 -0
- package/dist/translations/pt.js +12 -0
- package/dist/translations/ro.d.ts +12 -0
- package/dist/translations/ro.js +12 -0
- package/dist/translations/rs.d.ts +12 -0
- package/dist/translations/rs.js +12 -0
- package/dist/translations/rsLatin.d.ts +12 -0
- package/dist/translations/rsLatin.js +12 -0
- package/dist/translations/ru.d.ts +12 -0
- package/dist/translations/ru.js +12 -0
- package/dist/translations/sk.d.ts +12 -0
- package/dist/translations/sk.js +12 -0
- package/dist/translations/sl.d.ts +12 -0
- package/dist/translations/sl.js +12 -0
- package/dist/translations/sv.d.ts +12 -0
- package/dist/translations/sv.js +12 -0
- package/dist/translations/ta.d.ts +12 -0
- package/dist/translations/ta.js +12 -0
- package/dist/translations/th.d.ts +12 -0
- package/dist/translations/th.js +12 -0
- package/dist/translations/tr.d.ts +12 -0
- package/dist/translations/tr.js +12 -0
- package/dist/translations/uk.d.ts +12 -0
- package/dist/translations/uk.js +12 -0
- package/dist/translations/vi.d.ts +12 -0
- package/dist/translations/vi.js +12 -0
- package/dist/translations/zh.d.ts +12 -0
- package/dist/translations/zh.js +12 -0
- package/dist/translations/zhTw.d.ts +12 -0
- package/dist/translations/zhTw.js +12 -0
- package/dist/types.d.ts +11 -0
- package/dist/utils/assert-never.d.ts +1 -0
- package/dist/utils/assert-never.js +3 -0
- package/dist/utils/build-detection.d.ts +6 -1
- package/dist/utils/build-detection.js +68 -89
- package/dist/utils/deploy-adapter.d.ts +3 -35
- package/dist/utils/deploy-adapter.js +25 -14
- package/dist/utils/lambda-config.js +18 -23
- package/dist/utils/messages.js +24 -3
- package/dist/utils/next-image-loader-config.d.ts +2 -0
- package/dist/utils/next-image-loader-config.js +63 -0
- package/dist/utils/next-image-loader-file.d.ts +2 -0
- package/dist/utils/next-image-loader-file.js +11 -0
- package/dist/utils/payload-generate.d.ts +10 -0
- package/dist/utils/payload-generate.js +59 -0
- package/dist/utils/pnpm-builds.d.ts +14 -0
- package/dist/utils/pnpm-builds.js +125 -0
- package/dist/utils/s3-upload.js +4 -1
- package/package.json +31 -7
- package/dist/lib/download-skill.d.ts +0 -12
- package/dist/lib/download-skill.js +0 -77
- package/dist/utils/adapters/nextjs.d.ts +0 -8
- package/dist/utils/adapters/nextjs.js +0 -61
- package/dist/utils/adapters/nitro.d.ts +0 -8
- package/dist/utils/adapters/nitro.js +0 -172
- package/dist/utils/adapters/vite.js +0 -31
- package/dist/utils/asset-collection.js +0 -144
- package/dist/utils/build-lambda-zip.js +0 -90
- package/dist/utils/fs-utils.d.ts +0 -12
- package/dist/utils/fs-utils.js +0 -55
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveWithin(outputPath: string, relativePath: string, field: string): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
export function resolveWithin(outputPath, relativePath, field) {
|
|
3
|
+
if (path.isAbsolute(relativePath)) {
|
|
4
|
+
throw new Error(`${field} must be relative to output root`);
|
|
5
|
+
}
|
|
6
|
+
const resolved = path.resolve(outputPath, relativePath);
|
|
7
|
+
const relative = path.relative(outputPath, resolved);
|
|
8
|
+
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
9
|
+
throw new Error(`${field} escapes output root`);
|
|
10
|
+
}
|
|
11
|
+
return resolved;
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively collect all file paths under a directory,
|
|
3
|
+
* returned as forward-slash-separated paths relative to baseDir.
|
|
4
|
+
*/
|
|
5
|
+
export declare function collectFilesRecursive(dir: string, baseDir: string): Promise<string[]>;
|
|
6
|
+
export declare class EscapingSymlinkError extends Error {
|
|
7
|
+
readonly symlinkPath: string;
|
|
8
|
+
readonly targetPath: string;
|
|
9
|
+
constructor(symlinkPath: string, targetPath: string, root: string);
|
|
10
|
+
}
|
|
11
|
+
export interface BundleFile {
|
|
12
|
+
/** Forward-slash path relative to the walk root; used as the zip entry name. */
|
|
13
|
+
relativePath: string;
|
|
14
|
+
/**
|
|
15
|
+
* Bytes this entry contributes to unzipped size. Regular files use content
|
|
16
|
+
* size; in-tree symlinks use `lstat` size (the stored link path).
|
|
17
|
+
*/
|
|
18
|
+
size: number;
|
|
19
|
+
/** Path passed to the archiver; may be an in-tree symlink. */
|
|
20
|
+
sourcePath: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Recursively list files under `root` for Lambda bundle sizing and archiving.
|
|
24
|
+
*
|
|
25
|
+
* Regular files and directories are included. Symlinks are included (not
|
|
26
|
+
* followed) only when the resolved target stays within `root`; otherwise an
|
|
27
|
+
* {@link EscapingSymlinkError} is thrown. This matches `archiver.directory`,
|
|
28
|
+
* which stores zip symlink entries rather than copying target contents.
|
|
29
|
+
* Broken or unreadable files are skipped.
|
|
30
|
+
*/
|
|
31
|
+
export declare function walkBundleFiles(root: string): Promise<BundleFile[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Recursively sum the byte size of all files under a directory using the same
|
|
34
|
+
* symlink policy as {@link walkBundleFiles}. Returns 0 for a missing or
|
|
35
|
+
* unreadable directory. Escaping symlinks throw {@link EscapingSymlinkError}.
|
|
36
|
+
* Files that disappear or become unreadable between readdir and stat are
|
|
37
|
+
* skipped (treated as 0 bytes).
|
|
38
|
+
*/
|
|
39
|
+
export declare function getDirectorySize(dir: string): Promise<number>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Recursively collect all file paths under a directory,
|
|
5
|
+
* returned as forward-slash-separated paths relative to baseDir.
|
|
6
|
+
*/ export async function collectFilesRecursive(dir, baseDir) {
|
|
7
|
+
const files = [];
|
|
8
|
+
try {
|
|
9
|
+
const entries = await fs.readdir(dir, {
|
|
10
|
+
withFileTypes: true
|
|
11
|
+
});
|
|
12
|
+
for (const entry of entries){
|
|
13
|
+
const fullPath = path.join(dir, entry.name);
|
|
14
|
+
if (entry.isDirectory()) {
|
|
15
|
+
const subFiles = await collectFilesRecursive(fullPath, baseDir);
|
|
16
|
+
files.push(...subFiles);
|
|
17
|
+
} else if (entry.isFile()) {
|
|
18
|
+
files.push(path.relative(baseDir, fullPath).split(path.sep).join('/'));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
// Not accessible
|
|
23
|
+
}
|
|
24
|
+
return files;
|
|
25
|
+
}
|
|
26
|
+
export class EscapingSymlinkError extends Error {
|
|
27
|
+
symlinkPath;
|
|
28
|
+
targetPath;
|
|
29
|
+
constructor(symlinkPath, targetPath, root){
|
|
30
|
+
super(`Symlink '${symlinkPath}' points outside ${root} (${targetPath})`), this.symlinkPath = symlinkPath, this.targetPath = targetPath;
|
|
31
|
+
this.name = 'EscapingSymlinkError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Recursively list files under `root` for Lambda bundle sizing and archiving.
|
|
36
|
+
*
|
|
37
|
+
* Regular files and directories are included. Symlinks are included (not
|
|
38
|
+
* followed) only when the resolved target stays within `root`; otherwise an
|
|
39
|
+
* {@link EscapingSymlinkError} is thrown. This matches `archiver.directory`,
|
|
40
|
+
* which stores zip symlink entries rather than copying target contents.
|
|
41
|
+
* Broken or unreadable files are skipped.
|
|
42
|
+
*/ export async function walkBundleFiles(root) {
|
|
43
|
+
const rootReal = await fs.realpath(root);
|
|
44
|
+
const files = [];
|
|
45
|
+
await walkBundleDir(root, root, rootReal, files);
|
|
46
|
+
return files;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Recursively sum the byte size of all files under a directory using the same
|
|
50
|
+
* symlink policy as {@link walkBundleFiles}. Returns 0 for a missing or
|
|
51
|
+
* unreadable directory. Escaping symlinks throw {@link EscapingSymlinkError}.
|
|
52
|
+
* Files that disappear or become unreadable between readdir and stat are
|
|
53
|
+
* skipped (treated as 0 bytes).
|
|
54
|
+
*/ export async function getDirectorySize(dir) {
|
|
55
|
+
try {
|
|
56
|
+
const files = await walkBundleFiles(dir);
|
|
57
|
+
return files.reduce((total, file)=>total + file.size, 0);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof EscapingSymlinkError) {
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function isPathWithin(rootReal, targetReal) {
|
|
66
|
+
const relative = path.relative(rootReal, targetReal);
|
|
67
|
+
return relative === '' || relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
68
|
+
}
|
|
69
|
+
async function walkBundleDir(dir, root, rootReal, files) {
|
|
70
|
+
let entries;
|
|
71
|
+
try {
|
|
72
|
+
entries = await fs.readdir(dir, {
|
|
73
|
+
withFileTypes: true
|
|
74
|
+
});
|
|
75
|
+
} catch {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
for (const entry of entries){
|
|
79
|
+
const fullPath = path.join(dir, entry.name);
|
|
80
|
+
if (entry.isSymbolicLink()) {
|
|
81
|
+
await addSymlinkEntry(fullPath, root, rootReal, files);
|
|
82
|
+
} else if (entry.isDirectory()) {
|
|
83
|
+
await walkBundleDir(fullPath, root, rootReal, files);
|
|
84
|
+
} else if (entry.isFile()) {
|
|
85
|
+
await addRegularFile(fullPath, root, files);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function addSymlinkEntry(fullPath, root, rootReal, files) {
|
|
90
|
+
const relativePath = toRelativePath(root, fullPath);
|
|
91
|
+
const targetPath = await resolveSymlinkTarget(fullPath);
|
|
92
|
+
if (targetPath === null) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!isPathWithin(rootReal, targetPath)) {
|
|
96
|
+
throw new EscapingSymlinkError(relativePath, targetPath, root);
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const stats = await fs.lstat(fullPath);
|
|
100
|
+
files.push({
|
|
101
|
+
relativePath,
|
|
102
|
+
size: stats.size,
|
|
103
|
+
sourcePath: fullPath
|
|
104
|
+
});
|
|
105
|
+
} catch {
|
|
106
|
+
// Symlink vanished between readdir and lstat — skip it.
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function resolveSymlinkTarget(fullPath) {
|
|
110
|
+
try {
|
|
111
|
+
return await fs.realpath(fullPath);
|
|
112
|
+
} catch {
|
|
113
|
+
try {
|
|
114
|
+
const link = await fs.readlink(fullPath);
|
|
115
|
+
return path.resolve(path.dirname(fullPath), link);
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function addRegularFile(fullPath, root, files) {
|
|
122
|
+
try {
|
|
123
|
+
const stats = await fs.stat(fullPath);
|
|
124
|
+
files.push({
|
|
125
|
+
relativePath: toRelativePath(root, fullPath),
|
|
126
|
+
size: stats.size,
|
|
127
|
+
sourcePath: fullPath
|
|
128
|
+
});
|
|
129
|
+
} catch {
|
|
130
|
+
// File vanished or is unreadable between readdir and stat — skip it.
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function toRelativePath(root, fullPath) {
|
|
134
|
+
return path.relative(root, fullPath).split(path.sep).join('/');
|
|
135
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { NextjsAdapter } from './nextjs.js';
|
|
2
|
+
export { NitroAdapter } from './nitro.js';
|
|
3
|
+
export type { AdapterLogger, AdapterName, AssetCollection, DeployAdapter, LambdaBundle, PageCollection, PrepareLambdaBundleOptions, } from './types.js';
|
|
4
|
+
export { ViteAdapter } from './vite.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function createNextjsCacheHandler(deserializeValue: any, serializeValue: any): {
|
|
2
|
+
new (): {
|
|
3
|
+
tagVersion: number;
|
|
4
|
+
get(key: any, context?: {}): Promise<{
|
|
5
|
+
value: any;
|
|
6
|
+
lastModified: any;
|
|
7
|
+
} | null>;
|
|
8
|
+
set(key: any, value: any, context?: {}): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* The revalidateTag function allows invalidating cached data on-demand based
|
|
11
|
+
* on the specified tags. For our purposes, since we are currently doing a
|
|
12
|
+
* local in-memory, per-process lambda cache, we can just go ahead and clear
|
|
13
|
+
* the cache. Eventually we will want to support doing tag invalidation at the
|
|
14
|
+
* CDN layer.
|
|
15
|
+
*/
|
|
16
|
+
revalidateTag(tags: any, _durations?: {}): Promise<void>;
|
|
17
|
+
resetRequestCache(): void;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export function createNextjsCacheHandlerSource(): string;
|
|
21
|
+
declare const _default: {
|
|
22
|
+
new (): {
|
|
23
|
+
tagVersion: number;
|
|
24
|
+
get(key: any, context?: {}): Promise<{
|
|
25
|
+
value: any;
|
|
26
|
+
lastModified: any;
|
|
27
|
+
} | null>;
|
|
28
|
+
set(key: any, value: any, context?: {}): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* The revalidateTag function allows invalidating cached data on-demand based
|
|
31
|
+
* on the specified tags. For our purposes, since we are currently doing a
|
|
32
|
+
* local in-memory, per-process lambda cache, we can just go ahead and clear
|
|
33
|
+
* the cache. Eventually we will want to support doing tag invalidation at the
|
|
34
|
+
* CDN layer.
|
|
35
|
+
*/
|
|
36
|
+
revalidateTag(tags: any, _durations?: {}): Promise<void>;
|
|
37
|
+
resetRequestCache(): void;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export default _default;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { deserialize, serialize } from 'node:v8';
|
|
2
|
+
export function createNextjsCacheHandler(deserializeValue, serializeValue) {
|
|
3
|
+
const MAX_CACHE_BYTES = 8 * 1024 * 1024;
|
|
4
|
+
// Approximate Map entry and metadata overhead; actual heap use can differ.
|
|
5
|
+
const ESTIMATED_ENTRY_OVERHEAD_BYTES = 64;
|
|
6
|
+
const cache = new Map();
|
|
7
|
+
let cacheBytes = 0;
|
|
8
|
+
// Tag invalidation advances this counter to reject writes from earlier requests.
|
|
9
|
+
let tagVersion = 0;
|
|
10
|
+
/**
|
|
11
|
+
* A process-local, fresh-only Next.js cacheHandler. The CDN owns stale serving.
|
|
12
|
+
* No filesystem access: Lambda's code directory is read-only. Each cold process
|
|
13
|
+
* starts empty; Gatekeeper serves the separately uploaded static assets.
|
|
14
|
+
*/ class NextjsCacheHandler {
|
|
15
|
+
constructor(){
|
|
16
|
+
this.tagVersion = tagVersion;
|
|
17
|
+
}
|
|
18
|
+
async get(key, context = {}) {
|
|
19
|
+
const cacheKey = getCacheKey(key, context.kind === 'FETCH');
|
|
20
|
+
const entry = cache.get(cacheKey);
|
|
21
|
+
if (!entry) {
|
|
22
|
+
observe('miss', context.kind);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const effectiveTTL = context.kind === 'FETCH' && context.revalidate !== undefined ? Math.min(entry.seconds, lifetime(context.revalidate)) : entry.seconds;
|
|
26
|
+
const ageMs = Math.max(0, Date.now() - entry.lastModified);
|
|
27
|
+
if (ageMs >= effectiveTTL * 1000) {
|
|
28
|
+
if (ageMs >= entry.seconds * 1000) {
|
|
29
|
+
remove(cacheKey);
|
|
30
|
+
}
|
|
31
|
+
observe('expired', context.kind);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
// Clone cached buffers/maps so a caller cannot mutate the stored value.
|
|
35
|
+
// V8 can return Buffer views into its input, so copy the serialized bytes.
|
|
36
|
+
const value = deserializeValue(Buffer.from(entry.data));
|
|
37
|
+
if (value && [
|
|
38
|
+
'APP_PAGE',
|
|
39
|
+
'APP_ROUTE',
|
|
40
|
+
'PAGES'
|
|
41
|
+
].includes(value.kind)) {
|
|
42
|
+
value.headers = withoutAge(value.headers);
|
|
43
|
+
value.headers.Age = String(Math.floor(ageMs / 1000));
|
|
44
|
+
}
|
|
45
|
+
cache.delete(cacheKey);
|
|
46
|
+
cache.set(cacheKey, entry);
|
|
47
|
+
observe('hit', context.kind);
|
|
48
|
+
return {
|
|
49
|
+
value,
|
|
50
|
+
lastModified: entry.lastModified
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async set(key, value, context = {}) {
|
|
54
|
+
// A render that overlaps invalidation must not restore an old value.
|
|
55
|
+
if (this.tagVersion !== tagVersion) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const cacheKey = getCacheKey(key, context.fetchCache);
|
|
59
|
+
remove(cacheKey);
|
|
60
|
+
const seconds = lifetime(context.fetchCache ? value?.revalidate : context.cacheControl?.revalidate);
|
|
61
|
+
if (seconds === 0) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let data;
|
|
65
|
+
try {
|
|
66
|
+
data = serializeValue(value);
|
|
67
|
+
} catch {
|
|
68
|
+
observe('unsupported', value?.kind);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const size = data.byteLength + Buffer.byteLength(cacheKey) + ESTIMATED_ENTRY_OVERHEAD_BYTES;
|
|
72
|
+
if (size > MAX_CACHE_BYTES) {
|
|
73
|
+
observe('oversized', value?.kind);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// Preserve an upstream Age, including a previous cached response that Next
|
|
77
|
+
// attempts to write again after an unsuccessful on-demand revalidation.
|
|
78
|
+
const age = responseAge(value);
|
|
79
|
+
if (age >= seconds) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
while(cacheBytes + size > MAX_CACHE_BYTES){
|
|
83
|
+
remove(cache.keys().next().value);
|
|
84
|
+
}
|
|
85
|
+
cache.set(cacheKey, {
|
|
86
|
+
data,
|
|
87
|
+
size,
|
|
88
|
+
seconds,
|
|
89
|
+
lastModified: Date.now() - age * 1000
|
|
90
|
+
});
|
|
91
|
+
cacheBytes += size;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The revalidateTag function allows invalidating cached data on-demand based
|
|
95
|
+
* on the specified tags. For our purposes, since we are currently doing a
|
|
96
|
+
* local in-memory, per-process lambda cache, we can just go ahead and clear
|
|
97
|
+
* the cache. Eventually we will want to support doing tag invalidation at the
|
|
98
|
+
* CDN layer.
|
|
99
|
+
*/ async revalidateTag(tags, _durations = {}) {
|
|
100
|
+
const tagsArr = Array.isArray(tags) ? tags : [
|
|
101
|
+
tags
|
|
102
|
+
];
|
|
103
|
+
const hasValidTag = tagsArr.some((tag)=>typeof tag === 'string' && tag.length);
|
|
104
|
+
if (!hasValidTag) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
cache.clear();
|
|
108
|
+
cacheBytes = 0;
|
|
109
|
+
tagVersion += 1;
|
|
110
|
+
observe('invalidated', 'local');
|
|
111
|
+
}
|
|
112
|
+
// Outstanding writes still belong to the request that started before invalidation.
|
|
113
|
+
resetRequestCache() {}
|
|
114
|
+
}
|
|
115
|
+
function getCacheKey(key, fetchCache) {
|
|
116
|
+
return `${fetchCache ? 'fetch' : 'route'}:${key}`;
|
|
117
|
+
}
|
|
118
|
+
function lifetime(revalidate) {
|
|
119
|
+
if (revalidate === false) {
|
|
120
|
+
return Infinity;
|
|
121
|
+
}
|
|
122
|
+
return Number.isSafeInteger(revalidate) && revalidate > 0 ? revalidate : 0;
|
|
123
|
+
}
|
|
124
|
+
function remove(key) {
|
|
125
|
+
const entry = cache.get(key);
|
|
126
|
+
if (entry) {
|
|
127
|
+
cacheBytes -= entry.size;
|
|
128
|
+
}
|
|
129
|
+
cache.delete(key);
|
|
130
|
+
}
|
|
131
|
+
function withoutAge(headers) {
|
|
132
|
+
return Object.fromEntries(Object.entries(headers ?? {}).filter(([name])=>name.toLowerCase() !== 'age'));
|
|
133
|
+
}
|
|
134
|
+
function responseAge(value) {
|
|
135
|
+
if (!value || value.kind === 'FETCH') {
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
const age = Object.entries(value.headers ?? {}).find(([name])=>name.toLowerCase() === 'age')?.[1];
|
|
139
|
+
if (age === undefined) {
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
if (typeof age !== 'number' && (typeof age !== 'string' || !/^\d+$/.test(age))) {
|
|
143
|
+
return Infinity;
|
|
144
|
+
}
|
|
145
|
+
const seconds = Number(age);
|
|
146
|
+
return Number.isSafeInteger(seconds) && seconds >= 0 ? seconds : Infinity;
|
|
147
|
+
}
|
|
148
|
+
function observe(result, kind) {
|
|
149
|
+
if (![
|
|
150
|
+
'APP_PAGE',
|
|
151
|
+
'APP_ROUTE',
|
|
152
|
+
'PAGES',
|
|
153
|
+
'local'
|
|
154
|
+
].includes(kind)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
// Bounded fields only: never log cache keys, URLs, values, or tags.
|
|
158
|
+
console.info(JSON.stringify({
|
|
159
|
+
event: 'figma_nextjs_cache',
|
|
160
|
+
result,
|
|
161
|
+
kind
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
return NextjsCacheHandler;
|
|
165
|
+
}
|
|
166
|
+
export function createNextjsCacheHandlerSource() {
|
|
167
|
+
return [
|
|
168
|
+
"import { deserialize, serialize } from 'node:v8'",
|
|
169
|
+
`const createNextjsCacheHandler = ${createNextjsCacheHandler.toString()}`,
|
|
170
|
+
'export default createNextjsCacheHandler(deserialize, serialize)',
|
|
171
|
+
''
|
|
172
|
+
].join('\n');
|
|
173
|
+
}
|
|
174
|
+
export default createNextjsCacheHandler(deserialize, serialize);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AdapterLogger, AssetCollection, DeployAdapter, LambdaBundle, PageCollection, PrepareLambdaBundleOptions } from './types.js';
|
|
2
|
+
export declare class NextjsAdapter implements DeployAdapter {
|
|
3
|
+
private readonly logger?;
|
|
4
|
+
name: "nextjs";
|
|
5
|
+
constructor(options?: {
|
|
6
|
+
logger?: AdapterLogger;
|
|
7
|
+
});
|
|
8
|
+
collectAssets(projectPath: string, output?: string): Promise<AssetCollection>;
|
|
9
|
+
collectPages(projectPath: string, output?: string): Promise<PageCollection>;
|
|
10
|
+
prepareLambdaBundle(projectPath: string, output?: string, options?: PrepareLambdaBundleOptions): Promise<LambdaBundle>;
|
|
11
|
+
}
|
|
12
|
+
export declare const nextjsAdapter: NextjsAdapter;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { collectSSGAssets, collectStaticAssets, collectStaticMetadataAssets } from './asset-collection.js';
|
|
4
|
+
import { buildLambdaZip } from './build-lambda-zip.js';
|
|
5
|
+
import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
|
|
6
|
+
import { collectFilesRecursive } from './fs-utils.js';
|
|
7
|
+
import { isPublishableAsset } from './secret-files.js';
|
|
8
|
+
export class NextjsAdapter {
|
|
9
|
+
logger;
|
|
10
|
+
name = 'nextjs';
|
|
11
|
+
constructor(options = {}){
|
|
12
|
+
this.logger = options.logger;
|
|
13
|
+
}
|
|
14
|
+
async collectAssets(projectPath, output) {
|
|
15
|
+
// Bundle assets: .next/static/ → _next/static/
|
|
16
|
+
const staticAssets = (await collectStaticAssets(projectPath, output, this.logger)).filter(isPublishableAsset);
|
|
17
|
+
const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
|
|
18
|
+
// A normal Next build keeps public/ beside .next. A prebuilt artifact can
|
|
19
|
+
// instead include it in the supplied output directory, which is necessary
|
|
20
|
+
// when the artifact is isolated from the source project (for example Bazel).
|
|
21
|
+
const artifactPublicDir = path.join(outputPath, 'public');
|
|
22
|
+
const publicDir = await fs.stat(artifactPublicDir).then((stat)=>stat.isDirectory()).catch(()=>false) ? artifactPublicDir : path.join(projectPath, 'public');
|
|
23
|
+
let publicAssets = [];
|
|
24
|
+
try {
|
|
25
|
+
await fs.stat(publicDir);
|
|
26
|
+
publicAssets = (await collectFilesRecursive(publicDir, publicDir)).filter(isPublishableAsset);
|
|
27
|
+
} catch {
|
|
28
|
+
// No public directory
|
|
29
|
+
}
|
|
30
|
+
const metadataAssets = await collectStaticMetadataAssets(projectPath, output);
|
|
31
|
+
const pathMap = {};
|
|
32
|
+
for (const key of staticAssets){
|
|
33
|
+
pathMap[key] = path.relative(projectPath, path.join(outputPath, key.replace(/^_next\//, '')));
|
|
34
|
+
}
|
|
35
|
+
for (const key of publicAssets){
|
|
36
|
+
pathMap[key] = path.relative(projectPath, path.join(publicDir, key));
|
|
37
|
+
}
|
|
38
|
+
for (const key of metadataAssets.keys.filter(isPublishableAsset)){
|
|
39
|
+
pathMap[key] = metadataAssets.pathMap[key];
|
|
40
|
+
}
|
|
41
|
+
const uploadKeys = Object.keys(pathMap);
|
|
42
|
+
return {
|
|
43
|
+
pathMap,
|
|
44
|
+
routes: uploadKeys.map((key)=>`/${key}`),
|
|
45
|
+
uploadKeys
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async collectPages(projectPath, output) {
|
|
49
|
+
const ssg = await collectSSGAssets(projectPath, output, this.logger);
|
|
50
|
+
// collectSSGAssets records each key's manifest route while scanning the
|
|
51
|
+
// output, preserving the existing mapping for HTML/RSC/meta files while
|
|
52
|
+
// supporting segment keys whose nested names do not encode the page route.
|
|
53
|
+
return {
|
|
54
|
+
pathMap: ssg.pathMap,
|
|
55
|
+
routeAssetMap: ssg.routeAssetMap,
|
|
56
|
+
routes: Object.keys(ssg.routeAssetMap),
|
|
57
|
+
uploadKeys: ssg.keys
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async prepareLambdaBundle(projectPath, output, options) {
|
|
61
|
+
return buildLambdaZip(projectPath, output, {
|
|
62
|
+
...options,
|
|
63
|
+
logger: this.logger
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export const nextjsAdapter = new NextjsAdapter();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AssetCollection, DeployAdapter, LambdaBundle, PageCollection, PrepareLambdaBundleOptions } from './types.js';
|
|
2
|
+
export declare class NitroAdapter implements DeployAdapter {
|
|
3
|
+
name: "nitro";
|
|
4
|
+
collectAssets(projectPath: string, output?: string): Promise<AssetCollection>;
|
|
5
|
+
collectPages(projectPath: string, output?: string): Promise<PageCollection>;
|
|
6
|
+
prepareLambdaBundle(projectPath: string, output?: string, options?: PrepareLambdaBundleOptions): Promise<LambdaBundle>;
|
|
7
|
+
}
|
|
8
|
+
export declare const nitroAdapter: NitroAdapter;
|