@payloadcms/figma 0.1.0-internal.10c3b07 → 0.1.0-internal.fbdc0d3

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 (149) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/{utils → adapters}/asset-collection.d.ts +10 -4
  3. package/dist/{utils → adapters}/asset-collection.js +58 -17
  4. package/dist/{utils → adapters}/build-lambda-zip.d.ts +4 -2
  5. package/dist/adapters/build-lambda-zip.js +111 -0
  6. package/dist/adapters/configureNextjsCache.d.ts +8 -0
  7. package/dist/adapters/configureNextjsCache.js +55 -0
  8. package/dist/{utils → adapters}/deploy-output/resolveOutputPath.d.ts +1 -1
  9. package/dist/adapters/fs-utils.d.ts +39 -0
  10. package/dist/adapters/fs-utils.js +135 -0
  11. package/dist/adapters/index.d.ts +4 -0
  12. package/dist/adapters/index.js +3 -0
  13. package/dist/adapters/lambda-runtime/nextjs-cache.d.ts +40 -0
  14. package/dist/adapters/lambda-runtime/nextjs-cache.js +174 -0
  15. package/dist/adapters/nextjs.d.ts +12 -0
  16. package/dist/adapters/nextjs.js +67 -0
  17. package/dist/{utils/adapters → adapters}/nitro.d.ts +2 -2
  18. package/dist/{utils/adapters → adapters}/nitro.js +54 -29
  19. package/dist/adapters/secret-files.d.ts +25 -0
  20. package/dist/adapters/secret-files.js +50 -0
  21. package/dist/adapters/types.d.ts +42 -0
  22. package/dist/adapters/types.js +1 -0
  23. package/dist/{utils/adapters → adapters}/vite.d.ts +1 -1
  24. package/dist/{utils/adapters → adapters}/vite.js +4 -3
  25. package/dist/api/control-plane.d.ts +11 -0
  26. package/dist/api/control-plane.js +26 -0
  27. package/dist/auth/headless-oauth-flow.js +4 -0
  28. package/dist/auth/oauth-flow.js +17 -0
  29. package/dist/auth/refresh.js +12 -12
  30. package/dist/auth/requested-scopes.d.ts +1 -0
  31. package/dist/auth/requested-scopes.js +3 -0
  32. package/dist/auth/token-store.d.ts +16 -0
  33. package/dist/auth/token-store.js +33 -0
  34. package/dist/auth/types.d.ts +5 -3
  35. package/dist/commands/bootstrap.js +3 -0
  36. package/dist/commands/build-lambda-zip.js +1 -1
  37. package/dist/commands/deploy.js +2 -2
  38. package/dist/commands/init.js +72 -2
  39. package/dist/commands/upgrade.js +65 -1
  40. package/dist/commands/upload-schema.js +3 -4
  41. package/dist/config/oauth.js +6 -1
  42. package/dist/constants.d.ts +0 -2
  43. package/dist/constants.js +0 -3
  44. package/dist/db-content-api/generated/content-api-types.d.ts +6 -2
  45. package/dist/db-content-api/utilities/auth.d.ts +1 -4
  46. package/dist/db-content-api/utilities/auth.js +1 -1
  47. package/dist/db-content-api/utilities/data/index.js +8 -2
  48. package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +3 -11
  49. package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
  50. package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +9 -4
  51. package/dist/index.d.ts +1 -0
  52. package/dist/index.js +2 -0
  53. package/dist/next/image-loader.d.ts +6 -0
  54. package/dist/next/image-loader.js +14 -0
  55. package/dist/oauth/components/LoginButton/index.js +66 -19
  56. package/dist/oauth/components/LoginButton/index.scss +121 -15
  57. package/dist/oauth/defaults.js +4 -1
  58. package/dist/plugin/build-config.d.ts +13 -3
  59. package/dist/plugin/build-config.js +198 -59
  60. package/dist/plugin/cache-revalidation-hooks.d.ts +6 -0
  61. package/dist/plugin/cache-revalidation-hooks.js +69 -0
  62. package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +2 -1
  63. package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -1
  64. package/dist/plugin/make-permission-access/make-permission-access.d.ts +8 -0
  65. package/dist/plugin/make-permission-access/make-permission-access.js +24 -0
  66. package/dist/storage-content-api/api-types.d.ts +5 -2
  67. package/dist/storage-content-api/buildBaseMediaResponseHeaders.d.ts +1 -1
  68. package/dist/storage-content-api/buildBaseMediaResponseHeaders.js +3 -1
  69. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +8 -6
  70. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +17 -12
  71. package/dist/storage-content-api/buildMediaRequestHeaders.d.ts +1 -0
  72. package/dist/storage-content-api/buildMediaRequestHeaders.js +14 -0
  73. package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +3 -3
  74. package/dist/storage-content-api/buildMediaResponseHeaders.js +25 -18
  75. package/dist/storage-content-api/client-uploads/generate.d.ts +7 -3
  76. package/dist/storage-content-api/client-uploads/generate.js +22 -21
  77. package/dist/storage-content-api/client.d.ts +0 -2
  78. package/dist/storage-content-api/client.js +2 -2
  79. package/dist/storage-content-api/copyFile.d.ts +16 -0
  80. package/dist/storage-content-api/copyFile.js +90 -0
  81. package/dist/storage-content-api/deleteFile.d.ts +8 -0
  82. package/dist/storage-content-api/deleteFile.js +18 -0
  83. package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +11 -0
  84. package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +33 -0
  85. package/dist/storage-content-api/getMediaType.d.ts +1 -0
  86. package/dist/storage-content-api/getMediaType.js +3 -0
  87. package/dist/storage-content-api/handleUpload.d.ts +1 -2
  88. package/dist/storage-content-api/handleUpload.js +13 -157
  89. package/dist/storage-content-api/hasSupportedContentEncoding.d.ts +1 -1
  90. package/dist/storage-content-api/hasSupportedContentEncoding.js +4 -2
  91. package/dist/storage-content-api/index.js +17 -8
  92. package/dist/storage-content-api/mediaErrorResponse.d.ts +1 -1
  93. package/dist/storage-content-api/mediaErrorResponse.js +2 -2
  94. package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
  95. package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
  96. package/dist/storage-content-api/shouldAttachMedia.d.ts +1 -0
  97. package/dist/storage-content-api/{getInlineContentType.js → shouldAttachMedia.js} +8 -7
  98. package/dist/storage-content-api/staticHandler.d.ts +2 -1
  99. package/dist/storage-content-api/staticHandler.js +47 -53
  100. package/dist/storage-content-api/types.d.ts +4 -1
  101. package/dist/storage-content-api/uploadFileData.d.ts +10 -0
  102. package/dist/storage-content-api/uploadFileData.js +145 -0
  103. package/dist/utils/build-detection.js +3 -3
  104. package/dist/utils/cache-bootstrap.js +1 -0
  105. package/dist/utils/deploy-adapter.d.ts +2 -34
  106. package/dist/utils/deploy-adapter.js +16 -9
  107. package/dist/utils/env-management.d.ts +15 -0
  108. package/dist/utils/env-management.js +47 -0
  109. package/dist/utils/lambda-config.js +14 -9
  110. package/dist/utils/load-payload-config.js +1 -6
  111. package/dist/utils/next-image-loader-config.d.ts +2 -0
  112. package/dist/utils/next-image-loader-config.js +63 -0
  113. package/dist/utils/next-image-loader-file.d.ts +2 -0
  114. package/dist/utils/next-image-loader-file.js +11 -0
  115. package/dist/utils/payload-config-ast.d.ts +5 -0
  116. package/dist/utils/payload-config-ast.js +73 -4
  117. package/dist/utils/payload-config-modifier.js +3 -0
  118. package/dist/utils/payload-secret.d.ts +28 -0
  119. package/dist/utils/payload-secret.js +34 -0
  120. package/package.json +22 -10
  121. package/dist/storage-content-api/getInlineContentType.d.ts +0 -1
  122. package/dist/storage-content-api/handleDelete.d.ts +0 -7
  123. package/dist/storage-content-api/handleDelete.js +0 -15
  124. package/dist/storage-content-api/utilities/getSafeFilename.d.ts +0 -11
  125. package/dist/storage-content-api/utilities/getSafeFilename.js +0 -59
  126. package/dist/storage-content-api/utilities/index.d.ts +0 -2
  127. package/dist/storage-content-api/utilities/index.js +0 -2
  128. package/dist/storage-content-api/utilities/parseUploadReference.d.ts +0 -17
  129. package/dist/storage-content-api/utilities/parseUploadReference.js +0 -27
  130. package/dist/utils/adapters/nextjs.d.ts +0 -8
  131. package/dist/utils/adapters/nextjs.js +0 -64
  132. package/dist/utils/build-lambda-zip.js +0 -73
  133. package/dist/utils/fs-utils.d.ts +0 -12
  134. package/dist/utils/fs-utils.js +0 -55
  135. /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +0 -0
  136. /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +0 -0
  137. /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput.d.ts +0 -0
  138. /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput.js +0 -0
  139. /package/dist/{utils → adapters}/deploy-output/inspectNitroOutput.d.ts +0 -0
  140. /package/dist/{utils → adapters}/deploy-output/inspectNitroOutput.js +0 -0
  141. /package/dist/{utils → adapters}/deploy-output/isFile.d.ts +0 -0
  142. /package/dist/{utils → adapters}/deploy-output/isFile.js +0 -0
  143. /package/dist/{utils → adapters}/deploy-output/readJson.d.ts +0 -0
  144. /package/dist/{utils → adapters}/deploy-output/readJson.js +0 -0
  145. /package/dist/{utils → adapters}/deploy-output/resolveNitroOutputLayout.d.ts +0 -0
  146. /package/dist/{utils → adapters}/deploy-output/resolveNitroOutputLayout.js +0 -0
  147. /package/dist/{utils → adapters}/deploy-output/resolveOutputPath.js +0 -0
  148. /package/dist/{utils → adapters}/deploy-output/resolveWithin.d.ts +0 -0
  149. /package/dist/{utils → adapters}/deploy-output/resolveWithin.js +0 -0
@@ -2,7 +2,7 @@ import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
2
2
  import { lexicalEditor } from '@payloadcms/richtext-lexical';
3
3
  import { buildConfig as payloadBuildConfig } from 'payload';
4
4
  import { deepMergeSimple } from 'payload/shared';
5
- import { getBootstrapInfo } from '../api/control-plane.js';
5
+ import { getBootstrapInfo, getEnvironmentVariableByName } from '../api/control-plane.js';
6
6
  import { getValidCredential } from '../auth/oauth-flow.js';
7
7
  import { getTokenStore } from '../auth/token-store.js';
8
8
  import { getEnvConfig } from '../constants.js';
@@ -16,12 +16,14 @@ import { createStorageClient } from '../storage-content-api/client.js';
16
16
  import { contentApiStorageAdapter } from '../storage-content-api/index.js';
17
17
  import { translations as figmaTranslations } from '../translations/index.js';
18
18
  import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
19
- import { getEnvVarSync } from '../utils/env-management.js';
19
+ import { getEnvVarSync, getParsedEnvVarSync } from '../utils/env-management.js';
20
20
  import * as log from '../utils/log.js';
21
21
  import { logMissingCliAuth } from './auth-preflight.js';
22
22
  import { logMissingContentSystemId } from './bootstrap-preflight.js';
23
+ import { createCacheRevalidationHooksPlugin } from './cache-revalidation-hooks.js';
23
24
  import { LIMIT_REACHED_VIEW_KEY, LIMIT_REACHED_VIEW_PATH } from './cloud-limits/routes.js';
24
25
  import { getDevCookieNames } from './dev-cookie-names.js';
26
+ import { passesMakeViewerWriteGate, withMakeViewerWriteBaseAccessDefaults } from './make-permission-access/make-permission-access.js';
25
27
  import { createSandboxUploadFetchPlugin } from './sandbox-upload-fetch.js';
26
28
  /**
27
29
  * Worker-trusted marker injected by Figma's sites-worker after it validates the
@@ -165,35 +167,132 @@ function missingOAuthCredential(name) {
165
167
  ok: true
166
168
  };
167
169
  }
170
+ /**
171
+ * Project + environment named in process.env or .env. Uses getEnvVarSync because Next.js
172
+ * evaluates config before dotenv populates process.env.
173
+ */ function readProjectScope() {
174
+ const projectId = process.env.FIGMA_PROJECT_ID ?? getEnvVarSync(process.cwd(), 'FIGMA_PROJECT_ID');
175
+ const environmentName = process.env.FIGMA_ENVIRONMENT_NAME ?? getEnvVarSync(process.cwd(), 'FIGMA_ENVIRONMENT_NAME');
176
+ if (!projectId || !environmentName) {
177
+ return null;
178
+ }
179
+ return {
180
+ environmentName,
181
+ projectId
182
+ };
183
+ }
184
+ function readCachedBootstrapData() {
185
+ const scope = readProjectScope();
186
+ return scope ? getTokenStore().getBootstrapData(scope.projectId, scope.environmentName) : null;
187
+ }
188
+ /**
189
+ * Resolve the Content API base URL: FIGMA_CONTENT_API_URL (injected in deployed environments),
190
+ * then the environment's regional URL from the bootstrap cache. A cached entry without a URL
191
+ * (written before bootstrap returned one) is refreshed from the API, unless this build already
192
+ * fetched bootstrap. Throws when no URL can be resolved.
193
+ */ async function requireContentApiUrl(args) {
194
+ if (process.env.FIGMA_CONTENT_API_URL) {
195
+ return process.env.FIGMA_CONTENT_API_URL;
196
+ }
197
+ const cached = args.bootstrapData ?? readCachedBootstrapData();
198
+ if (cached?.contentApiUrl) {
199
+ return cached.contentApiUrl;
200
+ }
201
+ const scope = readProjectScope();
202
+ if (!scope) {
203
+ throw new Error('Could not resolve the Content API URL.');
204
+ }
205
+ const message = `Could not resolve the Content API URL for environment "${scope.environmentName}" of project ${scope.projectId}.`;
206
+ if (args.bootstrapFetched) {
207
+ throw new Error(message);
208
+ }
209
+ const resolution = await resolveAndCacheBootstrap(getTokenStore(), scope.projectId, scope.environmentName);
210
+ if (!resolution.ok) {
211
+ throw new Error(`${message} ${describeBootstrapFailure(resolution.reason)}`);
212
+ }
213
+ if (!resolution.data.contentApiUrl) {
214
+ throw new Error(message);
215
+ }
216
+ return resolution.data.contentApiUrl;
217
+ }
218
+ function describeBootstrapFailure(reason) {
219
+ switch(reason.kind){
220
+ case 'environment-not-found':
221
+ return 'Fetching bootstrap data failed: environment not found.';
222
+ case 'network':
223
+ return `Fetching bootstrap data failed: ${reason.message}`;
224
+ case 'unauthenticated':
225
+ return 'Fetching bootstrap data failed: not logged in.';
226
+ }
227
+ }
168
228
  function messageOf(error) {
169
229
  return error instanceof Error ? error.message : 'Unknown error';
170
230
  }
231
+ /**
232
+ * Local-dev fallback: if the tenant config didn't supply a secret (usually
233
+ * because process.env.PAYLOAD_SECRET is unset), try the TokenStore cache,
234
+ * then fetch from the Control Plane. Skipped in Lambda — the platform
235
+ * injects PAYLOAD_SECRET as an env var there, and TokenStore throws in AWS.
236
+ * Returns undefined if we can't resolve one; the caller lets payload.init()
237
+ * throw its own error.
238
+ */ async function resolvePayloadSecretForRuntime(store, projectId, environmentName, tenantInstanceId) {
239
+ const cached = store.getPayloadSecret({
240
+ projectInfo: {
241
+ environmentName,
242
+ projectId
243
+ }
244
+ });
245
+ if (cached) {
246
+ return cached;
247
+ }
248
+ let credential;
249
+ try {
250
+ credential = await getValidCredential(store);
251
+ } catch (error) {
252
+ log.debug(`PAYLOAD_SECRET fetch skipped: ${messageOf(error)}`);
253
+ return undefined;
254
+ }
255
+ if (!credential) {
256
+ log.debug('PAYLOAD_SECRET fetch skipped: no cached CLI credential');
257
+ return undefined;
258
+ }
259
+ try {
260
+ const secret = await getEnvironmentVariableByName(credential, tenantInstanceId, 'PAYLOAD_SECRET');
261
+ store.setPayloadSecret({
262
+ projectInfo: {
263
+ environmentName,
264
+ projectId
265
+ },
266
+ secret
267
+ });
268
+ return secret;
269
+ } catch (error) {
270
+ log.debug(`PAYLOAD_SECRET fetch failed: ${messageOf(error)}`);
271
+ return undefined;
272
+ }
273
+ }
171
274
  /**
172
275
  * Creates storage configuration for upload collections
173
- */ function createStorageConfig(url, contentSystemId) {
174
- const usesEgressProxy = process.env.FIGMA_CONTENT_API_AUTH_MODE === 'egress-proxy';
175
- const storageConfig = usesEgressProxy ? {
176
- auth: {
177
- mode: 'egressProxy'
178
- },
179
- baseUrl: url,
180
- contentSystemId
181
- } : process.env.FIGMA_CONTENT_API_ACCESS_KEY ? {
182
- baseUrl: url,
183
- contentApiKey: process.env.FIGMA_CONTENT_API_ACCESS_KEY
184
- } : process.env.FIGMA_DEV_JWT === 'true' ? {
185
- auth: {
186
- mode: 'devJwt'
187
- },
188
- baseUrl: url,
189
- contentSystemId
190
- } : {
191
- auth: {
192
- mode: 'tokenStore',
193
- tokenStore: getTokenStore()
276
+ */ function createStorageConfig(url, contentSystemId, uploadInstructionsAccess) {
277
+ const storageConfig = {
278
+ ...process.env.FIGMA_CONTENT_API_ACCESS_KEY ? {
279
+ baseUrl: url,
280
+ contentApiKey: process.env.FIGMA_CONTENT_API_ACCESS_KEY
281
+ } : process.env.FIGMA_DEV_JWT === 'true' ? {
282
+ auth: {
283
+ mode: 'devJwt'
284
+ },
285
+ baseUrl: url,
286
+ contentSystemId
287
+ } : {
288
+ auth: {
289
+ mode: 'tokenStore',
290
+ tokenStore: getTokenStore()
291
+ },
292
+ baseUrl: url,
293
+ contentSystemId
194
294
  },
195
- baseUrl: url,
196
- contentSystemId
295
+ uploadInstructionsAccess
197
296
  };
198
297
  const adapter = contentApiStorageAdapter(storageConfig);
199
298
  const storageClient = createStorageClient(storageConfig);
@@ -205,13 +304,13 @@ function messageOf(error) {
205
304
  /**
206
305
  * Plugin that applies cloud storage configuration to all upload-enabled collections.
207
306
  * Runs at the end of the plugin chain so it sees collections added by user plugins too.
208
- */ function createStoragePlugin(url, contentSystemId) {
307
+ */ function createStoragePlugin(url, contentSystemId, uploadInstructionsAccess) {
209
308
  return (incomingConfig)=>{
210
309
  const uploadCollections = (incomingConfig.collections || []).filter((c)=>c.upload);
211
310
  if (uploadCollections.length === 0) {
212
311
  return incomingConfig;
213
312
  }
214
- const { adapter } = createStorageConfig(url, contentSystemId);
313
+ const { adapter } = createStorageConfig(url, contentSystemId, uploadInstructionsAccess);
215
314
  const collectionsMap = uploadCollections.reduce((acc, c)=>{
216
315
  acc[c.slug] = {
217
316
  adapter,
@@ -232,21 +331,22 @@ export async function buildFigmaConfig(config) {
232
331
  let environmentId = config.figma.environmentId ?? process.env.FIGMA_EID;
233
332
  contentSystemId ??= process.env.FIGMA_CONTENT_API_CONTENT_SYSTEM_ID;
234
333
  let bootstrapData = null;
334
+ let bootstrapFetched = false;
235
335
  let bootstrapReason = null;
236
336
  // Local dev: resolve from project ID + bootstrap cache
237
- // Use getEnvVarSync fallback because Next.js evaluates config before dotenv populates process.env
238
337
  if (!contentSystemId) {
239
- const projectId = process.env.FIGMA_PROJECT_ID ?? getEnvVarSync(process.cwd(), 'FIGMA_PROJECT_ID');
240
- const environmentName = process.env.FIGMA_ENVIRONMENT_NAME ?? getEnvVarSync(process.cwd(), 'FIGMA_ENVIRONMENT_NAME');
241
- if (!projectId || !environmentName) {
338
+ const scope = readProjectScope();
339
+ if (!scope) {
242
340
  bootstrapReason = {
243
341
  kind: 'no-config'
244
342
  };
245
343
  } else {
344
+ const { environmentName, projectId } = scope;
246
345
  const store = getTokenStore();
247
346
  bootstrapData = store.getBootstrapData(projectId, environmentName);
248
347
  // Runtime fallback: fetch from API if not cached (e.g. environment switch without re-init)
249
348
  if (!bootstrapData) {
349
+ bootstrapFetched = true;
250
350
  const resolution = await resolveAndCacheBootstrap(store, projectId, environmentName);
251
351
  if (resolution.ok) {
252
352
  bootstrapData = resolution.data;
@@ -261,12 +361,8 @@ export async function buildFigmaConfig(config) {
261
361
  }
262
362
  }
263
363
  if (!environmentId) {
264
- const projectId = process.env.FIGMA_PROJECT_ID ?? getEnvVarSync(process.cwd(), 'FIGMA_PROJECT_ID');
265
- const environmentName = process.env.FIGMA_ENVIRONMENT_NAME ?? getEnvVarSync(process.cwd(), 'FIGMA_ENVIRONMENT_NAME');
266
- if (projectId && environmentName) {
267
- bootstrapData ??= getTokenStore().getBootstrapData(projectId, environmentName);
268
- environmentId = bootstrapData?.tenantInstanceId;
269
- }
364
+ bootstrapData ??= readCachedBootstrapData();
365
+ environmentId = bootstrapData?.tenantInstanceId;
270
366
  }
271
367
  if (!environmentId) {
272
368
  throw new Error('Environment ID could not be resolved. Set FIGMA_EID or initialize the project.');
@@ -277,32 +373,26 @@ export async function buildFigmaConfig(config) {
277
373
  });
278
374
  throw new Error('Content System ID could not be resolved. ' + 'Run `npx @payloadcms/figma init` to set up your project.');
279
375
  }
280
- const url = process.env.FIGMA_CONTENT_API_URL || envConfig.contentApiUrl;
376
+ // Only the content-system db adapter and cloud storage call the Content API, so a project on a
377
+ // custom db with storage disabled needs no URL; `url` stays '' and is unused in that case.
378
+ const usesContentSystem = config.figma.useContentSystem !== false;
379
+ const url = usesContentSystem || config.figma.storage !== false ? await requireContentApiUrl({
380
+ bootstrapData,
381
+ bootstrapFetched
382
+ }) : '';
281
383
  const isProduction = process.env.NODE_ENV === 'production';
282
- const usesEgressProxy = process.env.FIGMA_CONTENT_API_AUTH_MODE === 'egress-proxy';
283
384
  // The deployed Lambda runs all queued jobs; locally there is no runner, so the db adapter logs
284
385
  // a heads-up whenever a job is queued. Deployed environments set DISABLE_LOCAL_JOB_QUEUE_NOTIFICATIONS=true
285
386
  // (injected by the control plane); end-users can also set it locally to silence the notice.
286
387
  const notifyLocalJobQueue = process.env.DISABLE_LOCAL_JOB_QUEUE_NOTIFICATIONS !== 'true';
287
- const usesTokenStoreAuth = !usesEgressProxy && !process.env.FIGMA_CONTENT_API_ACCESS_KEY && process.env.FIGMA_DEV_JWT !== 'true';
388
+ const usesTokenStoreAuth = !process.env.FIGMA_CONTENT_API_ACCESS_KEY && process.env.FIGMA_DEV_JWT !== 'true';
288
389
  if (usesTokenStoreAuth) {
289
390
  logMissingCliAuth(getTokenStore());
290
391
  }
291
392
  // Determine database adapter based on environment
292
393
  let db;
293
- const usesContentSystem = config.figma.useContentSystem !== false;
294
394
  if (!usesContentSystem) {
295
395
  db = config.db;
296
- } else if (usesEgressProxy) {
297
- db = contentAPIAdapter({
298
- auth: {
299
- mode: 'egressProxy'
300
- },
301
- contentSystemId,
302
- environmentName: process.env.FIGMA_ENVIRONMENT_NAME,
303
- notifyLocalJobQueue,
304
- url
305
- });
306
396
  } else if (process.env.FIGMA_CONTENT_API_ACCESS_KEY) {
307
397
  db = contentAPIAdapter({
308
398
  auth: {
@@ -338,7 +428,30 @@ export async function buildFigmaConfig(config) {
338
428
  }
339
429
  const userJobsAccessRun = config.jobs?.access?.run;
340
430
  const adminCollectionSlug = getAdminCollectionSlug(config);
341
- // Build complete config with Figma platform defaults
431
+ // Hosted runtimes inject the Content API key and PAYLOAD_SECRET together, so
432
+ // the process env is authoritative. Ordinary local dev still checks the
433
+ // TokenStore first so a leftover .env value cannot shadow the platform secret.
434
+ let resolvedSecret;
435
+ if (process.env.AWS_EXECUTION_ENV || process.env.FIGMA_CONTENT_API_ACCESS_KEY) {
436
+ resolvedSecret = process.env.PAYLOAD_SECRET;
437
+ } else {
438
+ const projectId = process.env.FIGMA_PROJECT_ID ?? getEnvVarSync(process.cwd(), 'FIGMA_PROJECT_ID');
439
+ const environmentName = process.env.FIGMA_ENVIRONMENT_NAME ?? getEnvVarSync(process.cwd(), 'FIGMA_ENVIRONMENT_NAME');
440
+ if (projectId && environmentName && environmentId) {
441
+ resolvedSecret = await resolvePayloadSecretForRuntime(getTokenStore(), projectId, environmentName, environmentId);
442
+ }
443
+ if (!resolvedSecret) {
444
+ // Config may be evaluated before the framework loads dotenv. Parse the
445
+ // file without mutating process.env, preserving quotes/comments correctly.
446
+ resolvedSecret = process.env.PAYLOAD_SECRET || getParsedEnvVarSync(process.cwd(), 'PAYLOAD_SECRET') || undefined;
447
+ if (resolvedSecret) {
448
+ log.warning('Using a local PAYLOAD_SECRET fallback because the platform secret could not be resolved. ' + 'It may differ from the deployed secret. Run `npx @payloadcms/figma init --id <project-id> --force` to refresh it.');
449
+ }
450
+ }
451
+ }
452
+ // Build complete config with Figma platform defaults.
453
+ // `secret` may be undefined here; payload.init() enforces its presence at
454
+ // runtime, so we relax the intermediate type instead of forging a default.
342
455
  const configWithFigmaDefaults = {
343
456
  ...config,
344
457
  admin: {
@@ -356,9 +469,15 @@ export async function buildFigmaConfig(config) {
356
469
  ]
357
470
  }
358
471
  },
472
+ // Payload applies this policy during sanitization, after user plugins and
473
+ // generated resources have registered their collections and globals.
474
+ baseAccess: withMakeViewerWriteBaseAccessDefaults(config.baseAccess),
359
475
  custom: {
360
476
  figma: {
361
477
  ...config.figma,
478
+ ...typeof config.figma.storage === 'object' ? {
479
+ storage: true
480
+ } : {},
362
481
  contentSystemId,
363
482
  environmentId
364
483
  }
@@ -374,10 +493,11 @@ export async function buildFigmaConfig(config) {
374
493
  ...config.i18n,
375
494
  translations: deepMergeSimple(figmaTranslations, config.i18n?.translations ?? {})
376
495
  },
496
+ secret: resolvedSecret,
377
497
  // Gate /api/payload-jobs/run and /api/payload-jobs/handle-schedules. Honor the
378
498
  // sites-worker trust marker so Figma infra job runs never break, defer to the
379
- // tenant's jobs.access.run if they set one, otherwise fall back to Payload's
380
- // "logged-in user" default so the admin "Run jobs" UI keeps working.
499
+ // tenant's jobs.access.run if they set one, otherwise require an authenticated
500
+ // user who is not a known Make viewer.
381
501
  jobs: {
382
502
  ...config.jobs ?? {},
383
503
  access: {
@@ -389,21 +509,37 @@ export async function buildFigmaConfig(config) {
389
509
  if (userJobsAccessRun) {
390
510
  return userJobsAccessRun(args);
391
511
  }
392
- return !!args.req.user;
512
+ // Allow undefined Make permissions during rollout, but fail closed for empty,
513
+ // explicit view, and other unrecognized values.
514
+ return Boolean(args.req.user) && passesMakeViewerWriteGate(args.req.user);
393
515
  }
394
- }
516
+ },
517
+ // Remove Payload's default read/write denials so the jobs collection uses
518
+ // the standard access defaults and baseAccess Make-permission write gate.
519
+ // Preserve tenant-supplied overrides; jobs.access.run separately controls
520
+ // the job execution endpoints.
521
+ jobsCollectionOverrides: config.jobs?.jobsCollectionOverrides ?? (({ defaultJobsCollection })=>{
522
+ const { access: _access, ...rest } = defaultJobsCollection;
523
+ return rest;
524
+ })
395
525
  },
396
526
  ...isProduction && !config.logger ? {
397
527
  logger: {
398
528
  options: {}
399
529
  }
400
530
  } : {},
401
- secret: 'MY_SECRET',
531
+ // The platform owns rotation of PAYLOAD_SECRET; this compat entry lets
532
+ // data encrypted under the old shared hosted secret keep decrypting.
533
+ // Appended last so any tenant-supplied previousSecrets are honored first.
534
+ previousSecrets: [
535
+ ...config.previousSecrets ?? [],
536
+ Buffer.from('TVlfU0VDUkVU', 'base64').toString('utf8')
537
+ ],
402
538
  // Add oauth to plugins if not already present
403
539
  plugins: [
404
540
  ...config.plugins ?? [],
405
541
  ...config.figma.storage !== false ? [
406
- createStoragePlugin(url, contentSystemId)
542
+ createStoragePlugin(url, contentSystemId, typeof config.figma.storage === 'object' ? config.figma.storage.uploadInstructionsAccess : undefined)
407
543
  ] : [],
408
544
  oAuth2Plugin({
409
545
  collections: [
@@ -433,7 +569,10 @@ export async function buildFigmaConfig(config) {
433
569
  // figma.storage is false and would break remote uploads for those apps.
434
570
  createSandboxUploadFetchPlugin({
435
571
  userCollections: config.collections
436
- })
572
+ }),
573
+ // Keep last so hooks added by app plugins also get the missing Next cache
574
+ // context guard used by Payload CLI operations in the Make sandbox.
575
+ createCacheRevalidationHooksPlugin()
437
576
  ]
438
577
  };
439
578
  // Inject Figma-managed identity fields only into the Payload Admin collection.
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'payload';
2
+ /**
3
+ * Prevent Next cache invalidation from turning a successful Payload mutation
4
+ * into an apparent failure when the mutation runs outside a Next request.
5
+ */
6
+ export declare function createCacheRevalidationHooksPlugin(): Plugin;
@@ -0,0 +1,69 @@
1
+ const missingNextCacheContext = /^Invariant: static generation store missing in (?:revalidateTag|revalidatePath|updateTag)\b/;
2
+ const unsupportedUpdateTagContext = /^updateTag can only be called from within a Server Action\./;
3
+ /**
4
+ * Next cache invalidation requires request-scoped state. Payload's Local API has
5
+ * no Next request when it runs from the CLI in a Make sandbox, so Next throws
6
+ * after the database write has already committed. Treat only that missing-
7
+ * context error as a no-op; cache invalidation still runs normally in a Next
8
+ * request, and all other hook failures retain their existing behavior.
9
+ */ function isUnsupportedNextCacheContextError(error) {
10
+ if (!(error instanceof Error)) {
11
+ return false;
12
+ }
13
+ const errorCode = error.__NEXT_ERROR_CODE;
14
+ if (missingNextCacheContext.test(error.message)) {
15
+ return errorCode === undefined || errorCode === 'E263';
16
+ }
17
+ if (unsupportedUpdateTagContext.test(error.message)) {
18
+ return errorCode === undefined || errorCode === 'E872';
19
+ }
20
+ return false;
21
+ }
22
+ function reportIgnoredRevalidation(args, hookName) {
23
+ const hookArgs = args[0];
24
+ hookArgs?.req?.payload?.logger?.warn({
25
+ hook: hookName,
26
+ msg: 'Ignored Next cache invalidation outside a supported request context'
27
+ });
28
+ }
29
+ function wrapHook(hook, hookName) {
30
+ return async (...args)=>{
31
+ try {
32
+ return await hook(...args);
33
+ } catch (error) {
34
+ if (isUnsupportedNextCacheContextError(error)) {
35
+ reportIgnoredRevalidation(args, hookName);
36
+ return undefined;
37
+ }
38
+ throw error;
39
+ }
40
+ };
41
+ }
42
+ function wrapHooks(hooks) {
43
+ if (!hooks) {
44
+ return hooks;
45
+ }
46
+ return Object.fromEntries(Object.entries(hooks).map(([name, value])=>[
47
+ name,
48
+ Array.isArray(value) ? value.map((hook)=>typeof hook === 'function' ? wrapHook(hook, name) : hook) : value
49
+ ]));
50
+ }
51
+ /**
52
+ * Prevent Next cache invalidation from turning a successful Payload mutation
53
+ * into an apparent failure when the mutation runs outside a Next request.
54
+ */ export function createCacheRevalidationHooksPlugin() {
55
+ const plugin = (config)=>({
56
+ ...config,
57
+ collections: config.collections?.map((collection)=>({
58
+ ...collection,
59
+ hooks: wrapHooks(collection.hooks)
60
+ })),
61
+ globals: config.globals?.map((global)=>({
62
+ ...global,
63
+ hooks: wrapHooks(global.hooks)
64
+ }))
65
+ });
66
+ // Run after tenant plugins so hooks they add receive the same guard.
67
+ plugin.order = Number.POSITIVE_INFINITY;
68
+ return plugin;
69
+ }
@@ -1,8 +1,9 @@
1
+ import type { ReactElement } from 'react';
1
2
  import './index.scss';
2
3
  type Props = {
3
4
  collectionLabel?: string;
4
5
  collectionListURL?: string;
5
6
  onRetry: () => void;
6
7
  };
7
- export declare function FigmaCloudLimitDocumentCountModal({ collectionLabel, collectionListURL, onRetry, }: Props): import("react").JSX.Element;
8
+ export declare function FigmaCloudLimitDocumentCountModal({ collectionLabel, collectionListURL, onRetry, }: Props): ReactElement;
8
9
  export {};
@@ -1,2 +1,3 @@
1
+ import type { ReactElement } from 'react';
1
2
  /** External link icon (box with arrow pointing out). Used in cloud-limit UI. */
2
- export declare function ExternalLinkIcon(): import("react").JSX.Element;
3
+ export declare function ExternalLinkIcon(): ReactElement;
@@ -0,0 +1,8 @@
1
+ import type { Access, BaseAccess } from 'payload';
2
+ /**
3
+ * we will still let a user edit if makePermission is null or undefined, because we are
4
+ * specifically restricting users for a figma cloud project backed by make
5
+ */
6
+ export declare function passesMakeViewerWriteGate(user: unknown): boolean;
7
+ export declare const makeViewerWriteBaseAccess: Access;
8
+ export declare function withMakeViewerWriteBaseAccessDefaults(existingBaseAccess?: BaseAccess): BaseAccess;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * we will still let a user edit if makePermission is null or undefined, because we are
3
+ * specifically restricting users for a figma cloud project backed by make
4
+ */ export function passesMakeViewerWriteGate(user) {
5
+ const makePermission = user?.makePermission;
6
+ return makePermission === undefined || makePermission === null || makePermission === 'edit';
7
+ }
8
+ export const makeViewerWriteBaseAccess = ({ req })=>passesMakeViewerWriteGate(req.user);
9
+ export function withMakeViewerWriteBaseAccessDefaults(existingBaseAccess = {}) {
10
+ return {
11
+ ...existingBaseAccess,
12
+ collections: {
13
+ ...existingBaseAccess.collections,
14
+ create: existingBaseAccess.collections?.create ?? makeViewerWriteBaseAccess,
15
+ delete: existingBaseAccess.collections?.delete ?? makeViewerWriteBaseAccess,
16
+ unlock: existingBaseAccess.collections?.unlock ?? makeViewerWriteBaseAccess,
17
+ update: existingBaseAccess.collections?.update ?? makeViewerWriteBaseAccess
18
+ },
19
+ globals: {
20
+ ...existingBaseAccess.globals,
21
+ update: existingBaseAccess.globals?.update ?? makeViewerWriteBaseAccess
22
+ }
23
+ };
24
+ }
@@ -34,7 +34,7 @@ export type UploadPaths = {
34
34
  };
35
35
  };
36
36
  };
37
- };
37
+ } & UploadErrorResponses;
38
38
  };
39
39
  };
40
40
  '/api/v0/uploads/download/sign': {
@@ -45,6 +45,9 @@ export type UploadPaths = {
45
45
  collectionId: string;
46
46
  expiresIn: number;
47
47
  filename: string;
48
+ responseHeaders: {
49
+ cacheControl: string;
50
+ };
48
51
  };
49
52
  };
50
53
  };
@@ -56,7 +59,7 @@ export type UploadPaths = {
56
59
  };
57
60
  };
58
61
  };
59
- };
62
+ } & UploadErrorResponses;
60
63
  };
61
64
  };
62
65
  '/api/v0/uploads/multipart/abort': {
@@ -1 +1 @@
1
- export declare const buildBaseMediaResponseHeaders: () => Headers;
1
+ export declare function buildBaseMediaResponseHeaders(): Headers;
@@ -1,6 +1,8 @@
1
- export const buildBaseMediaResponseHeaders = ()=>new Headers({
1
+ export function buildBaseMediaResponseHeaders() {
2
+ return new Headers({
2
3
  'Accept-Ranges': 'bytes',
3
4
  'Cache-Control': 'private, no-store',
4
5
  Vary: 'Cookie',
5
6
  'X-Content-Type-Options': 'nosniff'
6
7
  });
8
+ }
@@ -1,10 +1,12 @@
1
1
  /**
2
- * Payload's server-side upload fetch-back uses the response Content-Type to decide whether to
3
- * inspect image dimensions. For an active image type such as SVG, omit the sanitized type so
4
- * Payload falls back to the original upload MIME type. Public file requests never use this helper.
2
+ * After a client upload, Payload reads the file from storage to determine image dimensions.
3
+ * For types outside the inline allowlist, such as SVG (which can contain scripts), omit
4
+ * Content-Type so Payload uses the original upload MIME type instead of application/octet-stream.
5
+ * Attachment and sandbox protections remain. This helper is only used when uploadReference
6
+ * is present; normal file requests use buildMediaResponseHeaders.
5
7
  */
6
- export declare const buildClientUploadFetchBackHeaders: ({ fallbackContentType, filename, upstream, }: {
8
+ export declare function buildClientUploadFetchBackHeaders({ fallbackContentType, filename, upstreamHeaders, }: {
7
9
  fallbackContentType?: string;
8
10
  filename: string;
9
- upstream: Headers;
10
- }) => Headers;
11
+ upstreamHeaders: Headers;
12
+ }): Headers;
@@ -1,21 +1,26 @@
1
1
  import { buildMediaResponseHeaders } from './buildMediaResponseHeaders.js';
2
- import { getInlineContentType } from './getInlineContentType.js';
2
+ import { shouldAttachMedia } from './shouldAttachMedia.js';
3
3
  /**
4
- * Payload's server-side upload fetch-back uses the response Content-Type to decide whether to
5
- * inspect image dimensions. For an active image type such as SVG, omit the sanitized type so
6
- * Payload falls back to the original upload MIME type. Public file requests never use this helper.
7
- */ export const buildClientUploadFetchBackHeaders = ({ fallbackContentType, filename, upstream })=>{
8
- const effectiveContentType = upstream.get('Content-Type') || fallbackContentType;
9
- const upstreamWithFallback = new Headers(upstream);
10
- if (effectiveContentType && !upstream.get('Content-Type')) {
11
- upstreamWithFallback.set('Content-Type', effectiveContentType);
4
+ * After a client upload, Payload reads the file from storage to determine image dimensions.
5
+ * For types outside the inline allowlist, such as SVG (which can contain scripts), omit
6
+ * Content-Type so Payload uses the original upload MIME type instead of application/octet-stream.
7
+ * Attachment and sandbox protections remain. This helper is only used when uploadReference
8
+ * is present; normal file requests use buildMediaResponseHeaders.
9
+ */ export function buildClientUploadFetchBackHeaders({ fallbackContentType, filename, upstreamHeaders }) {
10
+ const effectiveContentType = upstreamHeaders.get('Content-Type') || fallbackContentType;
11
+ const upstreamHeadersWithFallback = new Headers(upstreamHeaders);
12
+ if (effectiveContentType) {
13
+ upstreamHeadersWithFallback.set('Content-Type', effectiveContentType);
12
14
  }
13
15
  const headers = buildMediaResponseHeaders({
14
16
  filename,
15
- upstream: upstreamWithFallback
17
+ upstreamHeaders: upstreamHeadersWithFallback
16
18
  });
17
- if (effectiveContentType && !getInlineContentType(effectiveContentType)) {
19
+ if (effectiveContentType && shouldAttachMedia(upstreamHeadersWithFallback)) {
20
+ // Payload uses the response content type when processing an uploaded image.
21
+ // The sanitized type can hide the original upload MIME type.
22
+ // Remove it so Payload falls back to the original type.
18
23
  headers.delete('Content-Type');
19
24
  }
20
25
  return headers;
21
- };
26
+ }
@@ -0,0 +1 @@
1
+ export declare function buildMediaRequestHeaders(incomingHeaders: Headers): Headers;
@@ -0,0 +1,14 @@
1
+ export function buildMediaRequestHeaders(incomingHeaders) {
2
+ const headers = new Headers({
3
+ 'Accept-Encoding': 'identity'
4
+ });
5
+ const range = incomingHeaders.get('Range');
6
+ if (range) {
7
+ headers.set('Range', range);
8
+ const ifRange = incomingHeaders.get('If-Range');
9
+ if (ifRange) {
10
+ headers.set('If-Range', ifRange);
11
+ }
12
+ }
13
+ return headers;
14
+ }
@@ -1,4 +1,4 @@
1
- export declare const buildMediaResponseHeaders: ({ filename, upstream, }: {
1
+ export declare function buildMediaResponseHeaders({ filename, upstreamHeaders, }: {
2
2
  filename: string;
3
- upstream: Headers;
4
- }) => Headers;
3
+ upstreamHeaders: Headers;
4
+ }): Headers;