@payloadcms/figma 1.0.0-beta.3 → 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.
- package/dist/adapters/asset-collection.d.ts +15 -0
- package/dist/adapters/asset-collection.js +51 -45
- package/dist/adapters/build-lambda-zip.d.ts +8 -9
- package/dist/adapters/build-lambda-zip.js +36 -44
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +4 -0
- package/dist/adapters/lambdaLimits.d.ts +6 -0
- package/dist/adapters/lambdaLimits.js +5 -0
- package/dist/adapters/nextjs-assets.d.ts +7 -0
- package/dist/adapters/nextjs-assets.js +44 -0
- package/dist/adapters/nextjs.d.ts +8 -0
- package/dist/adapters/nextjs.js +19 -37
- package/dist/adapters/nitro.js +18 -43
- package/dist/adapters/omit-optional-sharp.d.ts +22 -0
- package/dist/adapters/omit-optional-sharp.js +158 -0
- package/dist/adapters/secret-files.js +8 -1
- package/dist/adapters/types.d.ts +8 -0
- package/dist/adapters/v2/core/build.d.ts +69 -0
- package/dist/adapters/v2/core/build.js +183 -0
- package/dist/adapters/v2/core/content-type.d.ts +3 -0
- package/dist/adapters/v2/core/content-type.js +41 -0
- package/dist/adapters/v2/core/getRelativePathError.d.ts +5 -0
- package/dist/adapters/v2/core/getRelativePathError.js +21 -0
- package/dist/adapters/v2/core/index.d.ts +15 -0
- package/dist/adapters/v2/core/index.js +13 -0
- package/dist/adapters/v2/core/limits.d.ts +28 -0
- package/dist/adapters/v2/core/limits.js +26 -0
- package/dist/adapters/v2/core/manifest-version.d.ts +10 -0
- package/dist/adapters/v2/core/manifest-version.js +14 -0
- package/dist/adapters/v2/core/server-zip.d.ts +58 -0
- package/dist/adapters/v2/core/server-zip.js +123 -0
- package/dist/adapters/v2/core/services.d.ts +46 -0
- package/dist/adapters/v2/core/services.js +202 -0
- package/dist/adapters/v2/core/static-path.d.ts +13 -0
- package/dist/adapters/v2/core/static-path.js +32 -0
- package/dist/adapters/v2/core/static-site.d.ts +26 -0
- package/dist/adapters/v2/core/static-site.js +95 -0
- package/dist/adapters/v2/core/types.d.ts +128 -0
- package/dist/adapters/v2/core/types.js +7 -0
- package/dist/adapters/v2/core/upload.d.ts +67 -0
- package/dist/adapters/v2/core/upload.js +198 -0
- package/dist/adapters/v2/core/validateDeployment/createIssue.d.ts +3 -0
- package/dist/adapters/v2/core/validateDeployment/createIssue.js +7 -0
- package/dist/adapters/v2/core/validateDeployment/escapePointer.d.ts +2 -0
- package/dist/adapters/v2/core/validateDeployment/escapePointer.js +3 -0
- package/dist/adapters/v2/core/validateDeployment/singletonHeaders.d.ts +2 -0
- package/dist/adapters/v2/core/validateDeployment/singletonHeaders.js +10 -0
- package/dist/adapters/v2/core/validateDeployment/types.d.ts +16 -0
- package/dist/adapters/v2/core/validateDeployment/types.js +8 -0
- package/dist/adapters/v2/core/validateDeployment/validateArtifacts.d.ts +3 -0
- package/dist/adapters/v2/core/validateDeployment/validateArtifacts.js +30 -0
- package/dist/adapters/v2/core/validateDeployment/validateCachePolicy.d.ts +8 -0
- package/dist/adapters/v2/core/validateDeployment/validateCachePolicy.js +26 -0
- package/dist/adapters/v2/core/validateDeployment/validateCounts/validateCount.d.ts +7 -0
- package/dist/adapters/v2/core/validateDeployment/validateCounts/validateCount.js +11 -0
- package/dist/adapters/v2/core/validateDeployment/validateCounts.d.ts +3 -0
- package/dist/adapters/v2/core/validateDeployment/validateCounts.js +41 -0
- package/dist/adapters/v2/core/validateDeployment/validateFallback.d.ts +3 -0
- package/dist/adapters/v2/core/validateDeployment/validateFallback.js +21 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderName.d.ts +6 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderName.js +13 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp/isReservedRuleHeader.d.ts +2 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp/isReservedRuleHeader.js +13 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp.d.ts +11 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp.js +38 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderRules.d.ts +3 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderRules.js +17 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderValue.d.ts +6 -0
- package/dist/adapters/v2/core/validateDeployment/validateHeaderValue.js +24 -0
- package/dist/adapters/v2/core/validateDeployment/validateId.d.ts +7 -0
- package/dist/adapters/v2/core/validateDeployment/validateId.js +12 -0
- package/dist/adapters/v2/core/validateDeployment/validateMatch.d.ts +15 -0
- package/dist/adapters/v2/core/validateDeployment/validateMatch.js +74 -0
- package/dist/adapters/v2/core/validateDeployment/validatePublicPath.d.ts +7 -0
- package/dist/adapters/v2/core/validateDeployment/validatePublicPath.js +21 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList/findRepeatedSingletons.d.ts +3 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList/findRepeatedSingletons.js +16 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList.d.ts +11 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList.js +48 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseBody.d.ts +10 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseBody.js +16 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseStatus.d.ts +8 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseStatus.js +25 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses.d.ts +7 -0
- package/dist/adapters/v2/core/validateDeployment/validateResponses.js +59 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateCaptures.d.ts +10 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateCaptures.js +12 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRedirectAction.d.ts +14 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRedirectAction.js +59 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRewriteAction.d.ts +11 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRewriteAction.js +20 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateServerAction.d.ts +11 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateServerAction.js +26 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateStaticAction.d.ts +13 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateStaticAction.js +25 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction.d.ts +12 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction.js +35 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes.d.ts +6 -0
- package/dist/adapters/v2/core/validateDeployment/validateRoutes.js +55 -0
- package/dist/adapters/v2/core/validateDeployment/validateServers/listReferencedServerIds.d.ts +3 -0
- package/dist/adapters/v2/core/validateDeployment/validateServers/listReferencedServerIds.js +12 -0
- package/dist/adapters/v2/core/validateDeployment/validateServers.d.ts +7 -0
- package/dist/adapters/v2/core/validateDeployment/validateServers.js +59 -0
- package/dist/adapters/v2/core/validateDeployment/validateStaticMap.d.ts +3 -0
- package/dist/adapters/v2/core/validateDeployment/validateStaticMap.js +22 -0
- package/dist/adapters/v2/core/validateDeployment.d.ts +7 -0
- package/dist/adapters/v2/core/validateDeployment.js +42 -0
- package/dist/adapters/v2/core/write.d.ts +21 -0
- package/dist/adapters/v2/core/write.js +30 -0
- package/dist/adapters/v2/nextjs/coverage.d.ts +45 -0
- package/dist/adapters/v2/nextjs/coverage.js +113 -0
- package/dist/adapters/v2/nextjs/read-build-output.d.ts +116 -0
- package/dist/adapters/v2/nextjs/read-build-output.js +368 -0
- package/dist/adapters/v2/nextjs/translate.d.ts +20 -0
- package/dist/adapters/v2/nextjs/translate.js +400 -0
- package/dist/adapters/vite.d.ts +7 -0
- package/dist/adapters/vite.js +47 -0
- package/dist/adapters/writeZip.d.ts +20 -0
- package/dist/adapters/writeZip.js +28 -0
- package/dist/api/control-plane.d.ts +28 -6
- package/dist/api/control-plane.js +67 -64
- package/dist/auth/cli-build-context.d.ts +3 -0
- package/dist/auth/cli-build-context.js +2 -0
- package/dist/auth/oauth-flow.d.ts +3 -3
- package/dist/auth/oauth-flow.js +13 -3
- package/dist/cli.js +15 -0
- package/dist/commands/build-manifest.d.ts +49 -0
- package/dist/commands/build-manifest.js +111 -0
- package/dist/commands/deploy.js +195 -26
- package/dist/db-content-api/generated/content-api-types.d.ts +18 -14
- package/dist/db-content-api/index.js +4 -1
- package/dist/db-content-api/utilities/where.js +2 -6
- package/dist/endpoints/client-config.d.ts +3 -0
- package/dist/endpoints/client-config.js +87 -0
- package/dist/image-transforms/constants.d.ts +8 -0
- package/dist/image-transforms/constants.js +26 -0
- package/dist/image-transforms/createImageTransformer.d.ts +6 -0
- package/dist/image-transforms/createImageTransformer.js +100 -0
- package/dist/image-transforms/deliverImageResponse.d.ts +11 -0
- package/dist/image-transforms/deliverImageResponse.js +43 -0
- package/dist/image-transforms/imageRevision.d.ts +14 -0
- package/dist/image-transforms/imageRevision.js +115 -0
- package/dist/image-transforms/normalizeMediaType.d.ts +2 -0
- package/dist/image-transforms/normalizeMediaType.js +3 -0
- package/dist/image-transforms/parseImageOverrides.d.ts +4 -0
- package/dist/image-transforms/parseImageOverrides.js +20 -0
- package/dist/image-transforms/preserveImageRedirectHeaders.d.ts +2 -0
- package/dist/image-transforms/preserveImageRedirectHeaders.js +30 -0
- package/dist/image-transforms/preventConflictingImageTransformers.d.ts +9 -0
- package/dist/image-transforms/preventConflictingImageTransformers.js +67 -0
- package/dist/image-transforms/serveImageRequest.d.ts +6 -0
- package/dist/image-transforms/serveImageRequest.js +97 -0
- package/dist/image-transforms/storedImage.d.ts +49 -0
- package/dist/image-transforms/storedImage.js +84 -0
- package/dist/image-transforms/types.d.ts +9 -0
- package/dist/image-transforms/types.js +1 -0
- package/dist/image-transforms/variantMetadata.d.ts +13 -0
- package/dist/image-transforms/variantMetadata.js +164 -0
- package/dist/imageSizeOptions.d.ts +8 -8
- package/dist/imageSizeOptions.js +0 -2
- package/dist/index.d.ts +1 -0
- package/dist/oauth/hooks/refresh.js +9 -4
- package/dist/oauth/strategy/index.js +34 -14
- package/dist/oauth/utilities/createTokenCookie.d.ts +11 -0
- package/dist/oauth/utilities/createTokenCookie.js +21 -0
- package/dist/oauth/utilities/refreshTokens.d.ts +7 -5
- package/dist/oauth/utilities/refreshTokens.js +7 -23
- package/dist/plugin/build-config.d.ts +3 -4
- package/dist/plugin/build-config.js +39 -18
- package/dist/plugin/mcp-oauth.d.ts +18 -7
- package/dist/plugin/mcp-oauth.js +123 -10
- package/dist/skills/deploy-to-figma/SKILL.md +8 -8
- package/dist/skills/deploy-to-figma/references/cli-reference.md +1 -1
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +2 -1
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +2 -1
- package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +2 -1
- package/dist/storage-content-api/buildMediaResponseHeaders.js +11 -5
- package/dist/storage-content-api/isRunningInLambda.d.ts +2 -0
- package/dist/storage-content-api/isRunningInLambda.js +3 -0
- package/dist/storage-content-api/staticHandler.js +13 -51
- package/dist/storage-content-api/streamMediaResponse.d.ts +17 -0
- package/dist/storage-content-api/streamMediaResponse.js +96 -0
- package/dist/utils/lambda-config.js +1 -1
- package/dist/utils/messages.js +8 -0
- package/dist/utils/next-image-loader-config.js +43 -6
- package/dist/utils/next-image-loader-file.js +8 -0
- package/package.json +12 -4
package/dist/commands/deploy.js
CHANGED
|
@@ -3,7 +3,8 @@ import spawn from 'cross-spawn';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import pc from 'picocolors';
|
|
5
5
|
import { getFileSize } from '../adapters/asset-collection.js';
|
|
6
|
-
import { LAMBDA_MAX_UNZIPPED_BYTES } from '../adapters/
|
|
6
|
+
import { LAMBDA_MAX_UNZIPPED_BYTES } from '../adapters/lambdaLimits.js';
|
|
7
|
+
import { MANIFEST_VERSION_ENV, readManifestVersionEnv, uploadVerifiedArtifacts } from '../adapters/v2/core/index.js';
|
|
7
8
|
import { createDeployment, getBootstrapInfo, performDeployment } from '../api/control-plane.js';
|
|
8
9
|
import { ControlPlaneError } from '../api/control-plane-error.js';
|
|
9
10
|
import { tryGetCredential } from '../auth/oauth-flow.js';
|
|
@@ -17,6 +18,7 @@ import { getPackageManager } from '../utils/package-manager.js';
|
|
|
17
18
|
import { isInProjectDirectory } from '../utils/project.js';
|
|
18
19
|
import { resolveEnvironment } from '../utils/resolve-environment.js';
|
|
19
20
|
import { uploadLambdaZip, uploadStaticAssets } from '../utils/s3-upload.js';
|
|
21
|
+
import { buildProjectManifestV2, formatServices, supportsManifestV2 } from './build-manifest.js';
|
|
20
22
|
import { detectProjectResourceType } from './detect-project-resource-type.js';
|
|
21
23
|
import { loginCommand } from './login.js';
|
|
22
24
|
import { promptToCreateProject } from './prompt-to-create-project.js';
|
|
@@ -60,6 +62,14 @@ import { writeProjectConfiguration } from './write-project-configuration.js';
|
|
|
60
62
|
const environmentName = options.env ?? await getEnvVar(projectPath, 'FIGMA_ENVIRONMENT_NAME') ?? undefined;
|
|
61
63
|
try {
|
|
62
64
|
// ===== PRE-FLIGHT CHECKS =====
|
|
65
|
+
// FIGMA_CLOUD_MANIFEST_VERSION=2 submits manifest v2. Checked first, so a bad value fails fast.
|
|
66
|
+
let manifestVersion;
|
|
67
|
+
try {
|
|
68
|
+
manifestVersion = readManifestVersionEnv();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
p.log.error(pc.red(`✗ ${error instanceof Error ? error.message : String(error)}`));
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
63
73
|
// Building requires package.json, but --skip-build can deploy a prebuilt artifact directly.
|
|
64
74
|
if (!options.skipBuild && !await isInProjectDirectory(projectPath)) {
|
|
65
75
|
p.log.error(pc.red('✗ Cannot build because package.json was not found in this directory.'));
|
|
@@ -228,6 +238,23 @@ import { writeProjectConfiguration } from './write-project-configuration.js';
|
|
|
228
238
|
spinner.start('Detecting framework...');
|
|
229
239
|
const adapter = await detectAdapter(projectPath, options.adapter, options.output);
|
|
230
240
|
spinner.stop(pc.green(`✓ Detected ${adapter.name} adapter`));
|
|
241
|
+
if (manifestVersion === 2) {
|
|
242
|
+
if (supportsManifestV2(adapter)) {
|
|
243
|
+
await deployManifestV2({
|
|
244
|
+
adapter,
|
|
245
|
+
buildId: buildInfo.buildId,
|
|
246
|
+
credential,
|
|
247
|
+
output: options.output,
|
|
248
|
+
projectPath,
|
|
249
|
+
spinner,
|
|
250
|
+
tenantInstanceId,
|
|
251
|
+
yes: options.yes
|
|
252
|
+
});
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
// The rollout env var never breaks a deploy: fall back to v1 until the adapter supports v2.
|
|
256
|
+
p.log.warn(pc.yellow(`${MANIFEST_VERSION_ENV}=2, but the ${adapter.name} adapter doesn't support manifest v2 yet. Deploying with manifest v1.`));
|
|
257
|
+
}
|
|
231
258
|
// Collect pages and assets
|
|
232
259
|
spinner.start('Collecting assets...');
|
|
233
260
|
const pages = await adapter.collectPages(projectPath, options.output);
|
|
@@ -244,10 +271,11 @@ import { writeProjectConfiguration } from './write-project-configuration.js';
|
|
|
244
271
|
zipPath = bundle.zipPath;
|
|
245
272
|
unzippedBytes = bundle.unzippedBytes;
|
|
246
273
|
zipSize = await getFileSize(zipPath);
|
|
247
|
-
spinner.stop(pc.green(`✓ Deployment package created (${formatBytes(zipSize)} zipped, ${formatBytes(unzippedBytes)} unzipped)`));
|
|
248
|
-
} else {
|
|
249
|
-
spinner.stop(pc.green('✓ Static site — no server package needed'));
|
|
250
274
|
}
|
|
275
|
+
spinner.stop(formatPackage(zipPath ? {
|
|
276
|
+
unzippedBytes,
|
|
277
|
+
zipSize
|
|
278
|
+
} : null));
|
|
251
279
|
} catch (error) {
|
|
252
280
|
spinner.stop(pc.red('✗ Failed to create deployment package'));
|
|
253
281
|
throw error;
|
|
@@ -269,13 +297,18 @@ import { writeProjectConfiguration } from './write-project-configuration.js';
|
|
|
269
297
|
log.debug(`Assets: ${assets.routes.length} files`);
|
|
270
298
|
// ===== DEPLOYMENT CONFIRMATION =====
|
|
271
299
|
if (!options.yes) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
zipPath ?
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
300
|
+
showDetails({
|
|
301
|
+
adapter: adapter.name,
|
|
302
|
+
buildId: buildInfo.buildId,
|
|
303
|
+
code: zipPath ? {
|
|
304
|
+
unzippedBytes,
|
|
305
|
+
zipSize
|
|
306
|
+
} : null,
|
|
307
|
+
lines: [
|
|
308
|
+
`${pc.cyan('Pages:')} ${pages.routes.length} routes (${pages.uploadKeys.length} files)`,
|
|
309
|
+
`${pc.cyan('Assets:')} ${assets.uploadKeys.length} files`
|
|
310
|
+
]
|
|
311
|
+
});
|
|
279
312
|
}
|
|
280
313
|
// ===== DEPLOYMENT EXECUTION =====
|
|
281
314
|
// Step 1: Create deployment
|
|
@@ -290,6 +323,7 @@ import { writeProjectConfiguration } from './write-project-configuration.js';
|
|
|
290
323
|
const createResponse = await createDeployment(credential, tenantInstanceId, {
|
|
291
324
|
adapter: adapter.name,
|
|
292
325
|
fallback: adapter.fallback,
|
|
326
|
+
manifestVersion: 1,
|
|
293
327
|
pages: pagesPayload,
|
|
294
328
|
staticAssets: assets.uploadKeys
|
|
295
329
|
});
|
|
@@ -342,24 +376,16 @@ import { writeProjectConfiguration } from './write-project-configuration.js';
|
|
|
342
376
|
}
|
|
343
377
|
if (totalFailed > 0) {
|
|
344
378
|
p.log.warning(`${totalFailed}/${totalUploadCount} files failed to upload. Deployment may be incomplete.`);
|
|
345
|
-
} else
|
|
346
|
-
|
|
379
|
+
} else {
|
|
380
|
+
reportUploaded(totalUploaded, totalBytes);
|
|
347
381
|
}
|
|
348
382
|
// Step 4: Perform deployment
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
deploymentId
|
|
383
|
+
await performAndReport({
|
|
384
|
+
credential,
|
|
385
|
+
deploymentId,
|
|
386
|
+
spinner,
|
|
387
|
+
tenantInstanceId
|
|
352
388
|
});
|
|
353
|
-
const tenantDomains = result.tenantDomains ?? [];
|
|
354
|
-
spinner.stop(pc.green('✓ Deployment initiated'));
|
|
355
|
-
// TODO: Add deployment progress tracking
|
|
356
|
-
// Future: Poll deployment status and show progress
|
|
357
|
-
// API endpoint: GET /v1/tenant/{tenant_id}/deploy/{deployment_id}/status
|
|
358
|
-
// Success output
|
|
359
|
-
if (tenantDomains.length > 0) {
|
|
360
|
-
p.log.step(`URL: ${pc.cyan(`https://${tenantDomains[0]}`)}`);
|
|
361
|
-
}
|
|
362
|
-
p.log.step('This usually takes 2-3 minutes to complete.');
|
|
363
389
|
} catch (error) {
|
|
364
390
|
if (error instanceof ControlPlaneError) {
|
|
365
391
|
spinner.stop(pc.red(`✗ ${error.message}`));
|
|
@@ -376,6 +402,149 @@ import { writeProjectConfiguration } from './write-project-configuration.js';
|
|
|
376
402
|
process.exit(1);
|
|
377
403
|
}
|
|
378
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Deploys the build as manifest v2, with the same steps and messages as v1: builds it into
|
|
407
|
+
* `.figma-build/`, submits the manifest to deploy/create, uploads the server ZIP and then the
|
|
408
|
+
* assets to their presigned POSTs (checking each digest and size on the bytes sent), and activates
|
|
409
|
+
* the deployment with deploy/perform. Unlike v1, any failed upload stops the deploy: perform would
|
|
410
|
+
* reject the missing file, and a file that changed since the build must never go live.
|
|
411
|
+
*/ async function deployManifestV2(params) {
|
|
412
|
+
const { adapter, buildId, credential, output, projectPath, spinner, tenantInstanceId, yes } = params;
|
|
413
|
+
// The adapter collects assets and packages the server in one step.
|
|
414
|
+
spinner.start('Collecting assets...');
|
|
415
|
+
const { deployment, summary } = await buildProjectManifestV2(projectPath, adapter, output);
|
|
416
|
+
const { artifacts, manifest } = deployment;
|
|
417
|
+
const serverIds = new Set(Object.values(manifest.servers ?? {}).map((server)=>server.artifact));
|
|
418
|
+
const assetIds = Object.keys(manifest.artifacts).filter((id)=>!serverIds.has(id));
|
|
419
|
+
const [serverId] = serverIds;
|
|
420
|
+
const code = serverId ? {
|
|
421
|
+
zipSize: artifacts[serverId].size
|
|
422
|
+
} : null;
|
|
423
|
+
spinner.stop(pc.green(`✓ ${summary.routes} routes, ${assetIds.length} assets detected`));
|
|
424
|
+
p.log.success(formatPackage(code));
|
|
425
|
+
for (const warning of summary.warnings){
|
|
426
|
+
p.log.warn(pc.yellow(warning));
|
|
427
|
+
}
|
|
428
|
+
if (!yes) {
|
|
429
|
+
showDetails({
|
|
430
|
+
adapter: adapter.name,
|
|
431
|
+
buildId,
|
|
432
|
+
code,
|
|
433
|
+
lines: [
|
|
434
|
+
`${pc.cyan('Assets:')} ${assetIds.length} files`,
|
|
435
|
+
...formatServices(summary.services),
|
|
436
|
+
`${pc.cyan('Manifest:')} v2 (${path.relative(projectPath, summary.manifestPath)})`
|
|
437
|
+
]
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
spinner.start('Creating deployment...');
|
|
441
|
+
const { artifactUploads, deploymentId } = await createDeployment(credential, tenantInstanceId, {
|
|
442
|
+
manifest,
|
|
443
|
+
manifestVersion: 2
|
|
444
|
+
});
|
|
445
|
+
log.debug(`Deployment ID: ${deploymentId}`);
|
|
446
|
+
const missing = Object.keys(manifest.artifacts).filter((id)=>!artifactUploads[id]);
|
|
447
|
+
if (missing.length > 0) {
|
|
448
|
+
throw new Error(`The control plane returned no upload for artifact ${missing.join(', ')}`);
|
|
449
|
+
}
|
|
450
|
+
const upload = async (ids, onProgress)=>{
|
|
451
|
+
// The mock control plane returns fake S3 POST targets; v1 skips its mock URLs the same way.
|
|
452
|
+
if (process.env.FIGMA_MOCK_CONTROL_PLANE === 'true') {
|
|
453
|
+
log.debug(`Mock upload of ${ids.length} artifacts skipped (FIGMA_MOCK_CONTROL_PLANE)`);
|
|
454
|
+
onProgress?.(ids.length, ids.length);
|
|
455
|
+
const totalBytesUploaded = ids.reduce((sum, id)=>sum + artifacts[id].size, 0);
|
|
456
|
+
return {
|
|
457
|
+
failed: 0,
|
|
458
|
+
totalBytesUploaded,
|
|
459
|
+
uploaded: ids.length
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
const lastErrors = new Map();
|
|
463
|
+
const results = await uploadVerifiedArtifacts({
|
|
464
|
+
artifacts,
|
|
465
|
+
cancel: new AbortController(),
|
|
466
|
+
onAttemptFailure: (artifact, statusCode, _retryCount, error)=>{
|
|
467
|
+
lastErrors.set(artifact, error ?? (statusCode ? `HTTP ${statusCode}` : 'upload failed'));
|
|
468
|
+
},
|
|
469
|
+
onProgress,
|
|
470
|
+
uploads: ids.map((artifact)=>({
|
|
471
|
+
artifact,
|
|
472
|
+
...artifactUploads[artifact]
|
|
473
|
+
}))
|
|
474
|
+
});
|
|
475
|
+
if (results.failedArtifact !== undefined) {
|
|
476
|
+
const file = path.relative(projectPath, artifacts[results.failedArtifact].path);
|
|
477
|
+
const reason = lastErrors.get(results.failedArtifact) ?? 'upload failed';
|
|
478
|
+
throw new Error(`Upload failed for ${file} (${reason})`);
|
|
479
|
+
}
|
|
480
|
+
return results;
|
|
481
|
+
};
|
|
482
|
+
let totalUploaded = 0;
|
|
483
|
+
let totalBytes = 0;
|
|
484
|
+
if (serverId && code) {
|
|
485
|
+
spinner.message(`Uploading code (${formatBytes(code.zipSize)})...`);
|
|
486
|
+
const results = await upload([
|
|
487
|
+
serverId
|
|
488
|
+
]);
|
|
489
|
+
totalUploaded += results.uploaded;
|
|
490
|
+
totalBytes += results.totalBytesUploaded;
|
|
491
|
+
spinner.stop(pc.green(`✓ Code uploaded (${formatBytes(code.zipSize)})`));
|
|
492
|
+
}
|
|
493
|
+
if (assetIds.length > 0) {
|
|
494
|
+
spinner.start('Uploading assets...');
|
|
495
|
+
const results = await upload(assetIds, (uploaded, total)=>{
|
|
496
|
+
spinner.message(`Uploading assets (${uploaded}/${total})...`);
|
|
497
|
+
});
|
|
498
|
+
totalUploaded += results.uploaded;
|
|
499
|
+
totalBytes += results.totalBytesUploaded;
|
|
500
|
+
spinner.stop(pc.green(`✓ ${results.uploaded} asset files uploaded`));
|
|
501
|
+
}
|
|
502
|
+
reportUploaded(totalUploaded, totalBytes);
|
|
503
|
+
await performAndReport({
|
|
504
|
+
credential,
|
|
505
|
+
deploymentId,
|
|
506
|
+
spinner,
|
|
507
|
+
tenantInstanceId
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
/** The line for the server package step; static sites have none. */ function formatPackage(code) {
|
|
511
|
+
if (!code) {
|
|
512
|
+
return pc.green('✓ Static site — no server package needed');
|
|
513
|
+
}
|
|
514
|
+
const unzipped = code.unzippedBytes === undefined ? '' : `, ${formatBytes(code.unzippedBytes)} unzipped`;
|
|
515
|
+
return pc.green(`✓ Deployment package created (${formatBytes(code.zipSize)} zipped${unzipped})`);
|
|
516
|
+
}
|
|
517
|
+
/** The confirmation note both manifest versions show before deploying. */ function showDetails(details) {
|
|
518
|
+
const { code } = details;
|
|
519
|
+
const unzipped = code?.unzippedBytes === undefined ? '' : `, ${formatBytes(code.unzippedBytes)} unzipped`;
|
|
520
|
+
p.note([
|
|
521
|
+
`${pc.cyan('Adapter:')} ${details.adapter}`,
|
|
522
|
+
`${pc.cyan('Build ID:')} ${details.buildId}`,
|
|
523
|
+
code ? `${pc.cyan('Code size:')} ${formatBytes(code.zipSize)} zipped${unzipped}` : `${pc.cyan('Code:')} No server`,
|
|
524
|
+
...details.lines
|
|
525
|
+
].join('\n'), 'Details');
|
|
526
|
+
}
|
|
527
|
+
/** The upload summary both manifest versions print once every file is uploaded. */ function reportUploaded(uploaded, bytes) {
|
|
528
|
+
if (uploaded > 0) {
|
|
529
|
+
p.log.success(pc.green(`✓ All files uploaded (${uploaded} files, ${formatBytes(bytes)})`));
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/** Activates a created deployment with deploy/perform and prints its URL. */ async function performAndReport(params) {
|
|
533
|
+
const { credential, deploymentId, spinner, tenantInstanceId } = params;
|
|
534
|
+
spinner.start('Performing deployment...');
|
|
535
|
+
const result = await performDeployment(credential, tenantInstanceId, {
|
|
536
|
+
deploymentId
|
|
537
|
+
});
|
|
538
|
+
const tenantDomains = result.tenantDomains ?? [];
|
|
539
|
+
spinner.stop(pc.green('✓ Deployment initiated'));
|
|
540
|
+
// TODO: Add deployment progress tracking
|
|
541
|
+
// Future: Poll deployment status and show progress
|
|
542
|
+
// API endpoint: GET /v1/tenant/{tenant_id}/deploy/{deployment_id}/status
|
|
543
|
+
if (tenantDomains.length > 0) {
|
|
544
|
+
p.log.step(`URL: ${pc.cyan(`https://${tenantDomains[0]}`)}`);
|
|
545
|
+
}
|
|
546
|
+
p.log.step('This usually takes 2-3 minutes to complete.');
|
|
547
|
+
}
|
|
379
548
|
function getMissingBuildMessage(projectPath, options) {
|
|
380
549
|
const location = options.output ? ` at ${path.resolve(projectPath, options.output)}` : '';
|
|
381
550
|
return options.adapter ? `No ${options.adapter} build found${location}.` : `No supported build found${location}.`;
|
|
@@ -7927,6 +7927,7 @@ export type components = {
|
|
|
7927
7927
|
limit?: number;
|
|
7928
7928
|
locale?: components['schemas']['LocaleClause'];
|
|
7929
7929
|
page?: number;
|
|
7930
|
+
pagination?: boolean;
|
|
7930
7931
|
schema: components['schemas']['DocumentSchema'];
|
|
7931
7932
|
select?: components['schemas']['SelectClause'];
|
|
7932
7933
|
sort?: components['schemas']['SortClauseV1'];
|
|
@@ -8117,6 +8118,7 @@ export type components = {
|
|
|
8117
8118
|
limit?: number;
|
|
8118
8119
|
locale?: components['schemas']['LocaleClause'];
|
|
8119
8120
|
page?: number;
|
|
8121
|
+
pagination?: boolean;
|
|
8120
8122
|
schema: components['schemas']['DocumentSchema'];
|
|
8121
8123
|
select?: components['schemas']['SelectClause'];
|
|
8122
8124
|
sort?: components['schemas']['SortClauseV1'];
|
|
@@ -8402,7 +8404,6 @@ export type components = {
|
|
|
8402
8404
|
/** @enum {string} */
|
|
8403
8405
|
compression?: 'fast';
|
|
8404
8406
|
contrast?: number;
|
|
8405
|
-
dpr?: number;
|
|
8406
8407
|
/** @enum {string} */
|
|
8407
8408
|
fit?: 'contain' | 'cover' | 'crop' | 'pad' | 'scale-down' | 'scale-up' | 'squeeze';
|
|
8408
8409
|
/** @enum {string} */
|
|
@@ -8425,24 +8426,25 @@ export type components = {
|
|
|
8425
8426
|
/** @enum {string} */
|
|
8426
8427
|
segment?: 'foreground';
|
|
8427
8428
|
sharpen?: number;
|
|
8428
|
-
trim?: 'border' | {
|
|
8429
|
-
border?: boolean | {
|
|
8430
|
-
color?: string;
|
|
8431
|
-
keep?: number;
|
|
8432
|
-
tolerance?: number;
|
|
8433
|
-
};
|
|
8434
|
-
bottom?: number;
|
|
8435
|
-
height?: number;
|
|
8436
|
-
left?: number;
|
|
8437
|
-
right?: number;
|
|
8438
|
-
top?: number;
|
|
8439
|
-
width?: number;
|
|
8440
|
-
};
|
|
8441
8429
|
/** @enum {string} */
|
|
8442
8430
|
upscale?: 'generate' | 'interpolate';
|
|
8443
8431
|
width?: number;
|
|
8444
8432
|
zoom?: number;
|
|
8445
8433
|
};
|
|
8434
|
+
source: {
|
|
8435
|
+
width?: number;
|
|
8436
|
+
height?: number;
|
|
8437
|
+
crop?: {
|
|
8438
|
+
x: number;
|
|
8439
|
+
y: number;
|
|
8440
|
+
width: number;
|
|
8441
|
+
height: number;
|
|
8442
|
+
};
|
|
8443
|
+
focalPoint?: {
|
|
8444
|
+
x: number;
|
|
8445
|
+
y: number;
|
|
8446
|
+
};
|
|
8447
|
+
};
|
|
8446
8448
|
request?: {
|
|
8447
8449
|
w?: number;
|
|
8448
8450
|
q?: number;
|
|
@@ -8454,6 +8456,8 @@ export type components = {
|
|
|
8454
8456
|
};
|
|
8455
8457
|
SignImageTransformResponse: {
|
|
8456
8458
|
path: string;
|
|
8459
|
+
/** @description Shared image proxy origin that serves signed paths, or null when unavailable. */
|
|
8460
|
+
deliveryOrigin: string | null;
|
|
8457
8461
|
};
|
|
8458
8462
|
};
|
|
8459
8463
|
responses: never;
|
|
@@ -124,7 +124,7 @@ async function createCollection(collectionId) {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
async function findMany({ collection, joins, limit, locale: localeArg, page, pagination
|
|
127
|
+
async function findMany({ collection, joins, limit, locale: localeArg, page, pagination, req, sort, where }) {
|
|
128
128
|
const locale = addFallbackLocale(localeArg, this.payload);
|
|
129
129
|
const localeNormalizedWhere = normalizeLocaleInWhere(where, this.payload, collection, locale);
|
|
130
130
|
const joinClause = convertPayloadJoinsToContentAPI(this.payload, collection, joins);
|
|
@@ -136,6 +136,8 @@ async function findMany({ collection, joins, limit, locale: localeArg, page, pag
|
|
|
136
136
|
limit,
|
|
137
137
|
locale,
|
|
138
138
|
page: page ?? 1,
|
|
139
|
+
// `false` when the caller never reads the total, so Content API skips its count.
|
|
140
|
+
pagination,
|
|
139
141
|
schema: this.documentSchema(),
|
|
140
142
|
sort: addFallbackSort(sort, this.payload, collection),
|
|
141
143
|
where: convertPayloadWhereToContentAPI(localeNormalizedWhere, this.payload, collection, false)
|
|
@@ -183,6 +185,7 @@ async function findVersions(args) {
|
|
|
183
185
|
limit: args.limit,
|
|
184
186
|
locale,
|
|
185
187
|
page: args.page ?? 1,
|
|
188
|
+
pagination: args.pagination,
|
|
186
189
|
schema: this.documentSchema(),
|
|
187
190
|
sort: sortWithFallback,
|
|
188
191
|
where: whereClause
|
|
@@ -69,12 +69,8 @@ function convertStructure(where, options) {
|
|
|
69
69
|
continue;
|
|
70
70
|
}
|
|
71
71
|
for (const [op, operatorValue] of Object.entries(operators)){
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
if (operatorValue === undefined) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
let finalValue = operatorValue;
|
|
72
|
+
// Dropping an undefined operand (e.g. access `{ equals: user?.id }` for anonymous) would widen the filter.
|
|
73
|
+
let finalValue = operatorValue === undefined ? null : operatorValue;
|
|
78
74
|
// Convert string booleans to actual booleans for exists operator
|
|
79
75
|
// REST API sends "true"/"false" as strings, but Content API requires boolean
|
|
80
76
|
if (op === 'exists' && typeof operatorValue === 'string') {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { getTranslation } from '@payloadcms/translations';
|
|
2
|
+
import { getClientConfig } from '@payloadcms/ui/utilities/getClientConfig';
|
|
3
|
+
import { getClientSchemaMap } from '@payloadcms/ui/utilities/getClientSchemaMap';
|
|
4
|
+
import { getSchemaMap } from '@payloadcms/ui/utilities/getSchemaMap';
|
|
5
|
+
import { canAccessAdmin, getAccessResults } from 'payload';
|
|
6
|
+
/** Returns admin client metadata, not a document-level permission projection. */ export const clientConfig = {
|
|
7
|
+
handler: async (req)=>{
|
|
8
|
+
if (!req.user) {
|
|
9
|
+
return Response.json({
|
|
10
|
+
error: 'Unauthorized'
|
|
11
|
+
}, {
|
|
12
|
+
status: 401
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
await canAccessAdmin({
|
|
16
|
+
req
|
|
17
|
+
});
|
|
18
|
+
const permissions = await getAccessResults({
|
|
19
|
+
req
|
|
20
|
+
});
|
|
21
|
+
const config = getClientConfig({
|
|
22
|
+
config: req.payload.config,
|
|
23
|
+
i18n: req.i18n,
|
|
24
|
+
importMap: req.payload.importMap,
|
|
25
|
+
user: req.user
|
|
26
|
+
});
|
|
27
|
+
const result = {
|
|
28
|
+
collections: {},
|
|
29
|
+
globals: {}
|
|
30
|
+
};
|
|
31
|
+
for (const collection of config.collections){
|
|
32
|
+
if (!permissions.collections?.[collection.slug]?.read) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const schemaMap = getSchemaMap({
|
|
36
|
+
collectionSlug: collection.slug,
|
|
37
|
+
config: req.payload.config,
|
|
38
|
+
i18n: req.i18n
|
|
39
|
+
});
|
|
40
|
+
const clientSchemaMap = getClientSchemaMap({
|
|
41
|
+
collectionSlug: collection.slug,
|
|
42
|
+
config,
|
|
43
|
+
i18n: req.i18n,
|
|
44
|
+
payload: req.payload,
|
|
45
|
+
schemaMap
|
|
46
|
+
});
|
|
47
|
+
result.collections[collection.slug] = {
|
|
48
|
+
slug: collection.slug,
|
|
49
|
+
labels: {
|
|
50
|
+
plural: getTranslation(collection.labels.plural, req.i18n),
|
|
51
|
+
singular: getTranslation(collection.labels.singular, req.i18n)
|
|
52
|
+
},
|
|
53
|
+
schemaMap: Object.fromEntries(clientSchemaMap),
|
|
54
|
+
useAsTitle: collection.admin.useAsTitle
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
for (const global of config.globals){
|
|
58
|
+
if (!permissions.globals?.[global.slug]?.read) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const schemaMap = getSchemaMap({
|
|
62
|
+
config: req.payload.config,
|
|
63
|
+
globalSlug: global.slug,
|
|
64
|
+
i18n: req.i18n
|
|
65
|
+
});
|
|
66
|
+
const clientSchemaMap = getClientSchemaMap({
|
|
67
|
+
config,
|
|
68
|
+
globalSlug: global.slug,
|
|
69
|
+
i18n: req.i18n,
|
|
70
|
+
payload: req.payload,
|
|
71
|
+
schemaMap
|
|
72
|
+
});
|
|
73
|
+
result.globals[global.slug] = {
|
|
74
|
+
slug: global.slug,
|
|
75
|
+
label: getTranslation(global.label, req.i18n),
|
|
76
|
+
schemaMap: Object.fromEntries(clientSchemaMap)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return Response.json(result, {
|
|
80
|
+
headers: {
|
|
81
|
+
'Cache-Control': 'private, no-store'
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
method: 'get',
|
|
86
|
+
path: '/figma/client-config'
|
|
87
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const IMAGE_TRANSFORMER_SLUG = "figma-images";
|
|
2
|
+
export declare const IMAGE_MEDIA_TYPES: string[];
|
|
3
|
+
export declare const IMAGE_OVERRIDE_KEYS: readonly ["w", "q"];
|
|
4
|
+
/**
|
|
5
|
+
* Formats Cloudflare cannot crop or resize. It sanitizes SVG without resizing it, and the Worker
|
|
6
|
+
* serves the others as the stored original.
|
|
7
|
+
*/
|
|
8
|
+
export declare const UNRESIZABLE_IMAGE_MIME_TYPES: Set<string>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const IMAGE_TRANSFORMER_SLUG = 'figma-images';
|
|
2
|
+
export const IMAGE_MEDIA_TYPES = [
|
|
3
|
+
'image/avif',
|
|
4
|
+
'image/bmp',
|
|
5
|
+
'image/gif',
|
|
6
|
+
'image/jpeg',
|
|
7
|
+
'image/png',
|
|
8
|
+
'image/svg+xml',
|
|
9
|
+
'image/vnd.microsoft.icon',
|
|
10
|
+
'image/webp',
|
|
11
|
+
'image/x-icon'
|
|
12
|
+
];
|
|
13
|
+
export const IMAGE_OVERRIDE_KEYS = [
|
|
14
|
+
'w',
|
|
15
|
+
'q'
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* Formats Cloudflare cannot crop or resize. It sanitizes SVG without resizing it, and the Worker
|
|
19
|
+
* serves the others as the stored original.
|
|
20
|
+
*/ export const UNRESIZABLE_IMAGE_MIME_TYPES = new Set([
|
|
21
|
+
'image/avif',
|
|
22
|
+
'image/bmp',
|
|
23
|
+
'image/svg+xml',
|
|
24
|
+
'image/vnd.microsoft.icon',
|
|
25
|
+
'image/x-icon'
|
|
26
|
+
]);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { UploadTransformer } from 'payload';
|
|
2
|
+
import type { StorageClient } from '../storage-content-api/client.js';
|
|
3
|
+
import type { FigmaImageTransformsConfig } from './types.js';
|
|
4
|
+
export declare function createImageTransformer({ client, collections, }: {
|
|
5
|
+
client: StorageClient;
|
|
6
|
+
} & FigmaImageTransformsConfig): UploadTransformer;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { registerUploadVariants } from 'payload';
|
|
2
|
+
import { IMAGE_MEDIA_TYPES, IMAGE_OVERRIDE_KEYS, IMAGE_TRANSFORMER_SLUG, UNRESIZABLE_IMAGE_MIME_TYPES } from './constants.js';
|
|
3
|
+
import { addImageRevision } from './imageRevision.js';
|
|
4
|
+
import { normalizeMediaType } from './normalizeMediaType.js';
|
|
5
|
+
import { preserveImageRedirectHeaders } from './preserveImageRedirectHeaders.js';
|
|
6
|
+
import { preventConflictingImageTransformers } from './preventConflictingImageTransformers.js';
|
|
7
|
+
import { serveImageRequest } from './serveImageRequest.js';
|
|
8
|
+
import { captureStoredImage, takeStoredImage } from './storedImage.js';
|
|
9
|
+
import { addVariantMetadata } from './variantMetadata.js';
|
|
10
|
+
export function createImageTransformer({ client, collections }) {
|
|
11
|
+
return {
|
|
12
|
+
slug: IMAGE_TRANSFORMER_SLUG,
|
|
13
|
+
canTransform: (args)=>{
|
|
14
|
+
if (!Object.hasOwn(collections, args.collectionSlug)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (args.operation !== 'request') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (args.purpose === 'persisted-default') {
|
|
21
|
+
// Leave unsupported crops unclaimed so Payload rejects them on save.
|
|
22
|
+
return {
|
|
23
|
+
canTransform: true,
|
|
24
|
+
handledTransformKeys: UNRESIZABLE_IMAGE_MIME_TYPES.has(normalizeMediaType(args.mimeType)) ? [
|
|
25
|
+
'focalPoint'
|
|
26
|
+
] : [
|
|
27
|
+
'crop',
|
|
28
|
+
'focalPoint'
|
|
29
|
+
]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return IMAGE_OVERRIDE_KEYS.some((key)=>args.req.searchParams?.has(key));
|
|
33
|
+
},
|
|
34
|
+
handleRequest: async (args)=>({
|
|
35
|
+
response: await serveImageRequest({
|
|
36
|
+
...args,
|
|
37
|
+
client,
|
|
38
|
+
collections
|
|
39
|
+
}),
|
|
40
|
+
status: 'complete'
|
|
41
|
+
}),
|
|
42
|
+
init: (config)=>{
|
|
43
|
+
const registeredConfig = registerUploadVariants({
|
|
44
|
+
collections,
|
|
45
|
+
config,
|
|
46
|
+
transformerSlug: IMAGE_TRANSFORMER_SLUG
|
|
47
|
+
});
|
|
48
|
+
return preventConflictingImageTransformers({
|
|
49
|
+
collectionSlugs: new Set(Object.keys(collections)),
|
|
50
|
+
config: {
|
|
51
|
+
...registeredConfig,
|
|
52
|
+
// Keep image redirects working if a collection's header hook replaces all headers.
|
|
53
|
+
collections: registeredConfig.collections?.map((collection)=>Object.hasOwn(collections, collection.slug) ? addImageReadHooks({
|
|
54
|
+
collection: preserveImageRedirectHeaders(collection),
|
|
55
|
+
variants: collections[collection.slug].variants
|
|
56
|
+
}) : collection)
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
mimeTypes: IMAGE_MEDIA_TYPES
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Describe request-time files on read: fill in variant metadata and version file URLs. Payload
|
|
65
|
+
* computes file URLs in field hooks, which run between collection `beforeRead` and `afterRead`
|
|
66
|
+
* hooks and remove the fields a read did not select, so record the stored image before them and
|
|
67
|
+
* describe the returned files after.
|
|
68
|
+
*/ function addImageReadHooks({ collection, variants }) {
|
|
69
|
+
return {
|
|
70
|
+
...collection,
|
|
71
|
+
hooks: {
|
|
72
|
+
...collection.hooks,
|
|
73
|
+
// Before Payload removes the fields a read did not select.
|
|
74
|
+
beforeRead: [
|
|
75
|
+
...collection.hooks?.beforeRead ?? [],
|
|
76
|
+
({ doc })=>captureStoredImage(doc)
|
|
77
|
+
],
|
|
78
|
+
// After Payload computes file URLs.
|
|
79
|
+
afterRead: [
|
|
80
|
+
...collection.hooks?.afterRead ?? [],
|
|
81
|
+
({ doc })=>{
|
|
82
|
+
const { readDoc, storedImage } = takeStoredImage(doc);
|
|
83
|
+
if (!storedImage) {
|
|
84
|
+
return readDoc;
|
|
85
|
+
}
|
|
86
|
+
const describedDoc = addVariantMetadata({
|
|
87
|
+
doc: readDoc,
|
|
88
|
+
storedImage,
|
|
89
|
+
variants
|
|
90
|
+
});
|
|
91
|
+
return addImageRevision({
|
|
92
|
+
doc: describedDoc,
|
|
93
|
+
storedImage,
|
|
94
|
+
variants
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
export declare function deliverImageResponse({ deliveryOrigin, filename, path, req, responseHeaderPolicy, }: {
|
|
3
|
+
/** Shared image proxy origin, or null when unavailable. */
|
|
4
|
+
deliveryOrigin: null | string;
|
|
5
|
+
filename: string;
|
|
6
|
+
path: string;
|
|
7
|
+
req: PayloadRequest;
|
|
8
|
+
responseHeaderPolicy: {
|
|
9
|
+
cacheControl: string;
|
|
10
|
+
};
|
|
11
|
+
}): Promise<Response>;
|