@payloadcms/figma 0.1.0-alpha.1 → 0.1.0-alpha.11

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 (321) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/{utils → adapters}/asset-collection.d.ts +17 -3
  3. package/dist/adapters/asset-collection.js +242 -0
  4. package/dist/{utils → adapters}/build-lambda-zip.d.ts +8 -7
  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/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +1 -0
  9. package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +15 -0
  10. package/dist/adapters/deploy-output/inspectNextjsOutput.d.ts +12 -0
  11. package/dist/adapters/deploy-output/inspectNextjsOutput.js +28 -0
  12. package/dist/adapters/deploy-output/inspectNitroOutput.d.ts +9 -0
  13. package/dist/adapters/deploy-output/inspectNitroOutput.js +13 -0
  14. package/dist/adapters/deploy-output/isFile.d.ts +1 -0
  15. package/dist/adapters/deploy-output/isFile.js +4 -0
  16. package/dist/adapters/deploy-output/readJson.d.ts +1 -0
  17. package/dist/adapters/deploy-output/readJson.js +9 -0
  18. package/dist/adapters/deploy-output/resolveNitroOutputLayout.d.ts +8 -0
  19. package/dist/adapters/deploy-output/resolveNitroOutputLayout.js +16 -0
  20. package/dist/adapters/deploy-output/resolveOutputPath.d.ts +2 -0
  21. package/dist/adapters/deploy-output/resolveOutputPath.js +9 -0
  22. package/dist/adapters/deploy-output/resolveWithin.d.ts +1 -0
  23. package/dist/adapters/deploy-output/resolveWithin.js +12 -0
  24. package/dist/adapters/fs-utils.d.ts +39 -0
  25. package/dist/adapters/fs-utils.js +135 -0
  26. package/dist/adapters/index.d.ts +4 -0
  27. package/dist/adapters/index.js +3 -0
  28. package/dist/adapters/lambda-runtime/nextjs-cache.d.ts +40 -0
  29. package/dist/adapters/lambda-runtime/nextjs-cache.js +174 -0
  30. package/dist/adapters/nextjs.d.ts +12 -0
  31. package/dist/adapters/nextjs.js +67 -0
  32. package/dist/adapters/nitro.d.ts +8 -0
  33. package/dist/adapters/nitro.js +193 -0
  34. package/dist/adapters/secret-files.d.ts +25 -0
  35. package/dist/adapters/secret-files.js +50 -0
  36. package/dist/adapters/types.d.ts +42 -0
  37. package/dist/adapters/types.js +1 -0
  38. package/dist/{utils/adapters → adapters}/vite.d.ts +2 -2
  39. package/dist/adapters/vite.js +33 -0
  40. package/dist/api/check-project-subdomain-availability.d.ts +12 -0
  41. package/dist/api/check-project-subdomain-availability.js +32 -0
  42. package/dist/api/control-plane-error.d.ts +6 -0
  43. package/dist/api/control-plane-error.js +8 -0
  44. package/dist/api/control-plane-fetch.d.ts +7 -0
  45. package/dist/api/control-plane-fetch.js +37 -0
  46. package/dist/api/control-plane.d.ts +10 -9
  47. package/dist/api/control-plane.js +27 -48
  48. package/dist/api/create-project.d.ts +18 -0
  49. package/dist/api/create-project.js +37 -0
  50. package/dist/api/list-project-workspaces.d.ts +8 -0
  51. package/dist/api/list-project-workspaces.js +28 -0
  52. package/dist/api/project-resource-type.d.ts +1 -0
  53. package/dist/api/project-resource-type.js +1 -0
  54. package/dist/auth/headless-oauth-flow.d.ts +23 -0
  55. package/dist/auth/headless-oauth-flow.js +69 -0
  56. package/dist/auth/oauth-flow.d.ts +2 -0
  57. package/dist/auth/oauth-flow.js +13 -8
  58. package/dist/auth/token-store.d.ts +20 -1
  59. package/dist/auth/token-store.js +47 -0
  60. package/dist/auth/types.d.ts +12 -0
  61. package/dist/cli.d.ts +39 -0
  62. package/dist/cli.js +71 -36
  63. package/dist/commands/bootstrap.js +2 -1
  64. package/dist/commands/build-lambda-zip.js +1 -1
  65. package/dist/commands/deploy.d.ts +12 -0
  66. package/dist/commands/deploy.js +63 -25
  67. package/dist/commands/detect-project-resource-type.d.ts +3 -0
  68. package/dist/commands/detect-project-resource-type.js +28 -0
  69. package/dist/commands/init.d.ts +2 -2
  70. package/dist/commands/init.js +235 -80
  71. package/dist/commands/login.d.ts +11 -1
  72. package/dist/commands/login.js +66 -4
  73. package/dist/commands/prompt-to-create-project/format-project-subdomain.d.ts +1 -0
  74. package/dist/commands/prompt-to-create-project/format-project-subdomain.js +3 -0
  75. package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.d.ts +1 -0
  76. package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.js +7 -0
  77. package/dist/commands/prompt-to-create-project/get-default-project-name.d.ts +1 -0
  78. package/dist/commands/prompt-to-create-project/get-default-project-name.js +13 -0
  79. package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.d.ts +7 -0
  80. package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.js +32 -0
  81. package/dist/commands/prompt-to-create-project/resolve-project-region.d.ts +8 -0
  82. package/dist/commands/prompt-to-create-project/resolve-project-region.js +27 -0
  83. package/dist/commands/prompt-to-create-project/resolve-project-subdomain.d.ts +9 -0
  84. package/dist/commands/prompt-to-create-project/resolve-project-subdomain.js +54 -0
  85. package/dist/commands/prompt-to-create-project/resolve-text-input.d.ts +9 -0
  86. package/dist/commands/prompt-to-create-project/resolve-text-input.js +23 -0
  87. package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.d.ts +12 -0
  88. package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.js +36 -0
  89. package/dist/commands/prompt-to-create-project/validate-subdomain.d.ts +1 -0
  90. package/dist/commands/prompt-to-create-project/validate-subdomain.js +9 -0
  91. package/dist/commands/prompt-to-create-project.d.ts +24 -0
  92. package/dist/commands/prompt-to-create-project.js +69 -0
  93. package/dist/commands/setup-agent.d.ts +12 -0
  94. package/dist/commands/setup-agent.js +123 -0
  95. package/dist/commands/upgrade.js +65 -1
  96. package/dist/commands/write-project-configuration.d.ts +12 -0
  97. package/dist/commands/write-project-configuration.js +16 -0
  98. package/dist/db-content-api/generated/content-api-types.d.ts +6 -2
  99. package/dist/db-content-api/index.d.ts +1 -1
  100. package/dist/db-content-api/index.js +121 -72
  101. package/dist/db-content-api/utilities/data/index.js +8 -2
  102. package/dist/db-content-api/utilities/data/injectGlobalType.d.ts +6 -0
  103. package/dist/db-content-api/utilities/data/injectGlobalType.js +11 -0
  104. package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +3 -11
  105. package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
  106. package/dist/db-content-api/utilities/isRecord.d.ts +9 -0
  107. package/dist/db-content-api/utilities/isRecord.js +19 -0
  108. package/dist/db-content-api/utilities/joins.js +5 -1
  109. package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.d.ts +10 -0
  110. package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.js +95 -0
  111. package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.d.ts +9 -0
  112. package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.js +112 -0
  113. package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +9 -4
  114. package/dist/db-content-api/utilities/schema/getDocumentSchema.d.ts +3 -0
  115. package/dist/db-content-api/utilities/schema/getDocumentSchema.js +24 -0
  116. package/dist/db-content-api/utilities/where.d.ts +2 -6
  117. package/dist/db-content-api/utilities/where.js +20 -9
  118. package/dist/exports/client.d.ts +2 -0
  119. package/dist/exports/client.js +2 -0
  120. package/dist/exports/views.d.ts +1 -0
  121. package/dist/exports/views.js +1 -0
  122. package/dist/imageSizeOptions.d.ts +23 -0
  123. package/dist/imageSizeOptions.js +26 -0
  124. package/dist/index.d.ts +2 -0
  125. package/dist/index.js +2 -0
  126. package/dist/lib/write-agent-config.d.ts +12 -0
  127. package/dist/lib/write-agent-config.js +52 -0
  128. package/dist/next/image-loader.d.ts +6 -0
  129. package/dist/next/image-loader.js +14 -0
  130. package/dist/oauth/components/LoginButton/index.js +66 -19
  131. package/dist/oauth/components/LoginButton/index.scss +121 -15
  132. package/dist/oauth/defaults.js +4 -1
  133. package/dist/oauth/endpoints/getLoginEndpoint.js +5 -2
  134. package/dist/oauth/index.js +8 -7
  135. package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +1 -1
  136. package/dist/oauth/utilities/getAuthorizeURL.d.ts +1 -0
  137. package/dist/oauth/utilities/getAuthorizeURL.js +5 -1
  138. package/dist/plugin/build-config.d.ts +13 -3
  139. package/dist/plugin/build-config.js +181 -36
  140. package/dist/plugin/cache-revalidation-hooks.d.ts +6 -0
  141. package/dist/plugin/cache-revalidation-hooks.js +69 -0
  142. package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +9 -0
  143. package/dist/plugin/cloud-limits/CloudLimitModal/index.js +66 -0
  144. package/dist/plugin/cloud-limits/CloudLimitModal/index.scss +56 -0
  145. package/dist/plugin/cloud-limits/CloudLimitProvider/index.d.ts +4 -0
  146. package/dist/plugin/cloud-limits/CloudLimitProvider/index.js +110 -0
  147. package/dist/plugin/cloud-limits/LimitReachedView/index.css +14 -0
  148. package/dist/plugin/cloud-limits/LimitReachedView/index.d.ts +4 -0
  149. package/dist/plugin/cloud-limits/LimitReachedView/index.js +52 -0
  150. package/dist/plugin/cloud-limits/SlugRegistryContext/index.d.ts +7 -0
  151. package/dist/plugin/cloud-limits/SlugRegistryContext/index.js +3 -0
  152. package/dist/plugin/cloud-limits/SlugTracker/index.d.ts +1 -0
  153. package/dist/plugin/cloud-limits/SlugTracker/index.js +27 -0
  154. package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +3 -0
  155. package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.js +30 -0
  156. package/dist/plugin/cloud-limits/routes.d.ts +2 -0
  157. package/dist/plugin/cloud-limits/routes.js +4 -0
  158. package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.d.ts +9 -0
  159. package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.js +28 -0
  160. package/dist/plugin/cloud-limits/shared.d.ts +10 -0
  161. package/dist/plugin/cloud-limits/shared.js +52 -0
  162. package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.d.ts +2 -0
  163. package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.js +134 -0
  164. package/dist/plugin/cloud-limits/utilities/toasts.d.ts +4 -0
  165. package/dist/plugin/cloud-limits/utilities/toasts.js +19 -0
  166. package/dist/plugin/make-permission-access/make-permission-access.d.ts +8 -0
  167. package/dist/plugin/make-permission-access/make-permission-access.js +24 -0
  168. package/dist/plugin/sandbox-upload-fetch.d.ts +32 -0
  169. package/dist/plugin/sandbox-upload-fetch.js +53 -0
  170. package/dist/skills/deploy-to-figma/SKILL.md +234 -0
  171. package/dist/skills/deploy-to-figma/references/cli-reference.md +146 -0
  172. package/dist/storage-content-api/api-types.d.ts +3 -0
  173. package/dist/storage-content-api/buildBaseMediaResponseHeaders.d.ts +1 -0
  174. package/dist/storage-content-api/buildBaseMediaResponseHeaders.js +8 -0
  175. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +12 -0
  176. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +26 -0
  177. package/dist/storage-content-api/buildMediaRequestHeaders.d.ts +1 -0
  178. package/dist/storage-content-api/buildMediaRequestHeaders.js +14 -0
  179. package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +4 -0
  180. package/dist/storage-content-api/buildMediaResponseHeaders.js +52 -0
  181. package/dist/storage-content-api/client-uploads/generate.js +2 -1
  182. package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +11 -0
  183. package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +33 -0
  184. package/dist/storage-content-api/getMediaType.d.ts +1 -0
  185. package/dist/storage-content-api/getMediaType.js +3 -0
  186. package/dist/storage-content-api/hasSupportedContentEncoding.d.ts +1 -0
  187. package/dist/storage-content-api/hasSupportedContentEncoding.js +6 -0
  188. package/dist/storage-content-api/index.js +1 -0
  189. package/dist/storage-content-api/mediaErrorResponse.d.ts +1 -0
  190. package/dist/storage-content-api/mediaErrorResponse.js +12 -0
  191. package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
  192. package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
  193. package/dist/storage-content-api/shouldAttachMedia.d.ts +1 -0
  194. package/dist/storage-content-api/shouldAttachMedia.js +34 -0
  195. package/dist/storage-content-api/staticHandler.js +93 -25
  196. package/dist/storage-content-api/types.d.ts +4 -1
  197. package/dist/translations/ar.d.ts +12 -0
  198. package/dist/translations/ar.js +12 -0
  199. package/dist/translations/az.d.ts +12 -0
  200. package/dist/translations/az.js +12 -0
  201. package/dist/translations/bg.d.ts +12 -0
  202. package/dist/translations/bg.js +12 -0
  203. package/dist/translations/bnBd.d.ts +12 -0
  204. package/dist/translations/bnBd.js +12 -0
  205. package/dist/translations/bnIn.d.ts +12 -0
  206. package/dist/translations/bnIn.js +12 -0
  207. package/dist/translations/ca.d.ts +12 -0
  208. package/dist/translations/ca.js +12 -0
  209. package/dist/translations/cs.d.ts +12 -0
  210. package/dist/translations/cs.js +12 -0
  211. package/dist/translations/da.d.ts +12 -0
  212. package/dist/translations/da.js +12 -0
  213. package/dist/translations/de.d.ts +12 -0
  214. package/dist/translations/de.js +12 -0
  215. package/dist/translations/en.d.ts +12 -0
  216. package/dist/translations/en.js +12 -0
  217. package/dist/translations/es.d.ts +12 -0
  218. package/dist/translations/es.js +12 -0
  219. package/dist/translations/et.d.ts +12 -0
  220. package/dist/translations/et.js +12 -0
  221. package/dist/translations/fa.d.ts +12 -0
  222. package/dist/translations/fa.js +12 -0
  223. package/dist/translations/fr.d.ts +12 -0
  224. package/dist/translations/fr.js +12 -0
  225. package/dist/translations/he.d.ts +12 -0
  226. package/dist/translations/he.js +12 -0
  227. package/dist/translations/hr.d.ts +12 -0
  228. package/dist/translations/hr.js +12 -0
  229. package/dist/translations/hu.d.ts +12 -0
  230. package/dist/translations/hu.js +12 -0
  231. package/dist/translations/hy.d.ts +12 -0
  232. package/dist/translations/hy.js +12 -0
  233. package/dist/translations/id.d.ts +12 -0
  234. package/dist/translations/id.js +12 -0
  235. package/dist/translations/index.d.ts +533 -0
  236. package/dist/translations/index.js +90 -0
  237. package/dist/translations/is.d.ts +12 -0
  238. package/dist/translations/is.js +12 -0
  239. package/dist/translations/it.d.ts +12 -0
  240. package/dist/translations/it.js +12 -0
  241. package/dist/translations/ja.d.ts +12 -0
  242. package/dist/translations/ja.js +12 -0
  243. package/dist/translations/ko.d.ts +12 -0
  244. package/dist/translations/ko.js +12 -0
  245. package/dist/translations/lt.d.ts +12 -0
  246. package/dist/translations/lt.js +12 -0
  247. package/dist/translations/lv.d.ts +12 -0
  248. package/dist/translations/lv.js +12 -0
  249. package/dist/translations/my.d.ts +12 -0
  250. package/dist/translations/my.js +12 -0
  251. package/dist/translations/nb.d.ts +12 -0
  252. package/dist/translations/nb.js +12 -0
  253. package/dist/translations/nl.d.ts +12 -0
  254. package/dist/translations/nl.js +12 -0
  255. package/dist/translations/pl.d.ts +12 -0
  256. package/dist/translations/pl.js +12 -0
  257. package/dist/translations/pt.d.ts +12 -0
  258. package/dist/translations/pt.js +12 -0
  259. package/dist/translations/ro.d.ts +12 -0
  260. package/dist/translations/ro.js +12 -0
  261. package/dist/translations/rs.d.ts +12 -0
  262. package/dist/translations/rs.js +12 -0
  263. package/dist/translations/rsLatin.d.ts +12 -0
  264. package/dist/translations/rsLatin.js +12 -0
  265. package/dist/translations/ru.d.ts +12 -0
  266. package/dist/translations/ru.js +12 -0
  267. package/dist/translations/sk.d.ts +12 -0
  268. package/dist/translations/sk.js +12 -0
  269. package/dist/translations/sl.d.ts +12 -0
  270. package/dist/translations/sl.js +12 -0
  271. package/dist/translations/sv.d.ts +12 -0
  272. package/dist/translations/sv.js +12 -0
  273. package/dist/translations/ta.d.ts +12 -0
  274. package/dist/translations/ta.js +12 -0
  275. package/dist/translations/th.d.ts +12 -0
  276. package/dist/translations/th.js +12 -0
  277. package/dist/translations/tr.d.ts +12 -0
  278. package/dist/translations/tr.js +12 -0
  279. package/dist/translations/uk.d.ts +12 -0
  280. package/dist/translations/uk.js +12 -0
  281. package/dist/translations/vi.d.ts +12 -0
  282. package/dist/translations/vi.js +12 -0
  283. package/dist/translations/zh.d.ts +12 -0
  284. package/dist/translations/zh.js +12 -0
  285. package/dist/translations/zhTw.d.ts +12 -0
  286. package/dist/translations/zhTw.js +12 -0
  287. package/dist/types.d.ts +11 -0
  288. package/dist/utils/assert-never.d.ts +1 -0
  289. package/dist/utils/assert-never.js +3 -0
  290. package/dist/utils/build-detection.d.ts +6 -1
  291. package/dist/utils/build-detection.js +68 -89
  292. package/dist/utils/deploy-adapter.d.ts +3 -35
  293. package/dist/utils/deploy-adapter.js +25 -14
  294. package/dist/utils/env-management.d.ts +15 -0
  295. package/dist/utils/env-management.js +47 -0
  296. package/dist/utils/lambda-config.js +18 -23
  297. package/dist/utils/messages.js +24 -3
  298. package/dist/utils/next-image-loader-config.d.ts +2 -0
  299. package/dist/utils/next-image-loader-config.js +63 -0
  300. package/dist/utils/next-image-loader-file.d.ts +2 -0
  301. package/dist/utils/next-image-loader-file.js +11 -0
  302. package/dist/utils/payload-config-ast.js +5 -2
  303. package/dist/utils/payload-generate.d.ts +10 -0
  304. package/dist/utils/payload-generate.js +59 -0
  305. package/dist/utils/payload-secret.d.ts +28 -0
  306. package/dist/utils/payload-secret.js +34 -0
  307. package/dist/utils/pnpm-builds.d.ts +14 -0
  308. package/dist/utils/pnpm-builds.js +125 -0
  309. package/dist/utils/s3-upload.js +4 -1
  310. package/package.json +33 -7
  311. package/dist/lib/download-skill.d.ts +0 -12
  312. package/dist/lib/download-skill.js +0 -77
  313. package/dist/utils/adapters/nextjs.d.ts +0 -8
  314. package/dist/utils/adapters/nextjs.js +0 -61
  315. package/dist/utils/adapters/nitro.d.ts +0 -8
  316. package/dist/utils/adapters/nitro.js +0 -172
  317. package/dist/utils/adapters/vite.js +0 -31
  318. package/dist/utils/asset-collection.js +0 -144
  319. package/dist/utils/build-lambda-zip.js +0 -90
  320. package/dist/utils/fs-utils.d.ts +0 -12
  321. package/dist/utils/fs-utils.js +0 -55
@@ -8,12 +8,13 @@ import { getBootstrapInfo, getCmsResourceId } from '../api/control-plane.js';
8
8
  import { getValidCredential } from '../auth/oauth-flow.js';
9
9
  import { getTokenStore } from '../auth/token-store.js';
10
10
  import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
11
- import { addOrUpdateEnvVar, getEnvVar, removeEnvVar } from '../utils/env-management.js';
11
+ import { addOrUpdateEnvVar, commentOutEnvVar, getEnvVar, removeEnvVar } from '../utils/env-management.js';
12
12
  import { formatFile } from '../utils/formatter.js';
13
13
  import { getPackageManager } from '../utils/package-manager.js';
14
14
  import { removeFigmaContentSystemId } from '../utils/payload-config-ast.js';
15
15
  import { findPayloadConfig } from '../utils/payload-config-finder.js';
16
16
  import { checkPackageInstalled, installPackage } from '../utils/payload-package-check.js';
17
+ import { ensurePayloadSecret } from '../utils/payload-secret.js';
17
18
  import { getOwnVersion } from '../utils/version-check.js';
18
19
  export async function upgradeCommand(options = {}) {
19
20
  const cwd = process.cwd();
@@ -45,6 +46,11 @@ export async function upgradeCommand(options = {}) {
45
46
  isDryRun,
46
47
  warnings
47
48
  });
49
+ await migrateCommentOutPayloadSecret({
50
+ changes,
51
+ cwd,
52
+ isDryRun
53
+ });
48
54
  await migrateConfigAst({
49
55
  changes,
50
56
  cwd,
@@ -221,6 +227,64 @@ async function migrateRemoveDeprecatedEnvVars({ changes, cwd, isDryRun, warnings
221
227
  p.log.warning(`Deprecated env var removal failed: ${msg}`);
222
228
  }
223
229
  }
230
+ async function migrateCommentOutPayloadSecret({ changes, cwd, isDryRun }) {
231
+ try {
232
+ // Only touch active (uncommented) assignments — commentOutEnvVar already
233
+ // no-ops on commented lines, but checking here avoids the dry-run message
234
+ // when there's nothing left to do.
235
+ const existing = await getEnvVar(cwd, 'PAYLOAD_SECRET');
236
+ if (existing === null) {
237
+ return;
238
+ }
239
+ if (isDryRun) {
240
+ p.log.message(`${pc.dim('○')} Would comment out PAYLOAD_SECRET in .env after caching the platform secret`);
241
+ changes.push('Comment out PAYLOAD_SECRET in .env');
242
+ return;
243
+ }
244
+ const projectId = await getEnvVar(cwd, 'FIGMA_PROJECT_ID');
245
+ const environmentName = await getEnvVar(cwd, 'FIGMA_ENVIRONMENT_NAME');
246
+ if (!projectId || !environmentName) {
247
+ p.log.warning('Keeping PAYLOAD_SECRET in .env: initialize the project before migrating its secret.');
248
+ return;
249
+ }
250
+ const store = getTokenStore();
251
+ const credential = await getValidCredential(store);
252
+ if (!credential) {
253
+ p.log.warning('Keeping PAYLOAD_SECRET in .env: run `npx @payloadcms/figma login` and retry upgrade.');
254
+ return;
255
+ }
256
+ let bootstrapData = store.getBootstrapData(projectId, environmentName);
257
+ if (!bootstrapData) {
258
+ const bootstrapInfo = await getBootstrapInfo(credential, projectId);
259
+ cacheAllEnvironments(store, projectId, bootstrapInfo);
260
+ bootstrapData = store.getBootstrapData(projectId, environmentName);
261
+ }
262
+ if (!bootstrapData?.tenantInstanceId) {
263
+ p.log.warning('Keeping PAYLOAD_SECRET in .env: the project environment could not be resolved.');
264
+ return;
265
+ }
266
+ await ensurePayloadSecret({
267
+ credential,
268
+ projectInfo: {
269
+ environmentName,
270
+ projectId
271
+ },
272
+ refresh: true,
273
+ tenantInstanceId: bootstrapData.tenantInstanceId,
274
+ tokenStore: store
275
+ });
276
+ const changed = await commentOutEnvVar(cwd, 'PAYLOAD_SECRET', 'disabled by @payloadcms/figma: platform owns PAYLOAD_SECRET');
277
+ if (!changed) {
278
+ p.log.warning('Could not comment out PAYLOAD_SECRET in .env; the platform secret is cached. Retry upgrade.');
279
+ return;
280
+ }
281
+ p.log.message(`${pc.green('●')} Env: Commented out PAYLOAD_SECRET (Figma platform owns this value; ` + `a local copy would silently diverge from the deployed secret)`);
282
+ changes.push('Commented out PAYLOAD_SECRET in .env');
283
+ } catch (error) {
284
+ const msg = error instanceof Error ? error.message : 'Unknown error';
285
+ p.log.warning(`PAYLOAD_SECRET migration failed; keeping the existing .env value: ${msg}`);
286
+ }
287
+ }
224
288
  async function migrateConfigAst({ changes, cwd, isDryRun }) {
225
289
  try {
226
290
  const configPath = await findPayloadConfig(cwd);
@@ -0,0 +1,12 @@
1
+ import type { BootstrapInfo } from '../api/control-plane.js';
2
+ import type { TokenStore } from '../auth/token-store.js';
3
+ interface WriteProjectConfigurationArgs {
4
+ bootstrapInfo: BootstrapInfo | null;
5
+ environmentName: string;
6
+ projectDir: string;
7
+ projectId: string;
8
+ shouldWriteEnvironmentVariables?: boolean;
9
+ tokenStore: TokenStore;
10
+ }
11
+ export declare function writeProjectConfiguration({ bootstrapInfo, environmentName, projectDir, projectId, shouldWriteEnvironmentVariables, tokenStore, }: WriteProjectConfigurationArgs): Promise<void>;
12
+ export {};
@@ -0,0 +1,16 @@
1
+ import { getInfraEnvironment } from '../constants.js';
2
+ import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
3
+ import { addOrUpdateEnvVar } from '../utils/env-management.js';
4
+ export async function writeProjectConfiguration({ bootstrapInfo, environmentName, projectDir, projectId, shouldWriteEnvironmentVariables = true, tokenStore }) {
5
+ if (shouldWriteEnvironmentVariables) {
6
+ await addOrUpdateEnvVar(projectDir, 'FIGMA_PROJECT_ID', projectId);
7
+ await addOrUpdateEnvVar(projectDir, 'FIGMA_ENVIRONMENT_NAME', environmentName);
8
+ const infraEnvironment = getInfraEnvironment();
9
+ if (infraEnvironment !== 'production') {
10
+ await addOrUpdateEnvVar(projectDir, 'FIGMA_INFRA_ENV', infraEnvironment);
11
+ }
12
+ }
13
+ if (bootstrapInfo) {
14
+ cacheAllEnvironments(tokenStore, projectId, bootstrapInfo);
15
+ }
16
+ }
@@ -8062,12 +8062,16 @@ export type components = {
8062
8062
  /** @example document.pdf */
8063
8063
  filename: string;
8064
8064
  /**
8065
- * @default 3600
8066
- * @example 3600
8065
+ * @default 300
8066
+ * @example 300
8067
8067
  */
8068
8068
  expiresIn: number;
8069
8069
  /** @example media */
8070
8070
  collectionId: string;
8071
+ responseHeaders?: {
8072
+ /** @example public, max-age=3600 */
8073
+ cacheControl: string;
8074
+ };
8071
8075
  };
8072
8076
  InitiateMultipartUploadResponse: {
8073
8077
  /** @example abc123xyz789 */
@@ -29,7 +29,7 @@ export type ContentAPIAdapter = {
29
29
  client: ReturnType<typeof createClient<paths>>;
30
30
  clientVersionHeaders: Record<string, string>;
31
31
  contentSystemId: string;
32
- documentSchema: DocumentSchemaWire;
32
+ documentSchema: () => DocumentSchemaWire;
33
33
  environmentName?: string;
34
34
  idType: 'uuid';
35
35
  notifyLocalJobQueue: boolean;
@@ -1,19 +1,21 @@
1
1
  import createClient from 'openapi-fetch';
2
- import { APIError, createDatabaseAdapter } from 'payload';
2
+ import { APIError, createDatabaseAdapter, ValidationError } from 'payload';
3
3
  import { v4 as uuid } from 'uuid';
4
4
  import { FigmaApiError } from '../api/figma-api.js';
5
5
  import { CONTENT_SYSTEM_NOT_FOUND_MESSAGE } from '../constants.js';
6
+ import { redirectInitialAutosaveCreate } from '../plugin/cloud-limits/server/redirectInitialAutosaveCreate.js';
6
7
  import { getGlobalSlug } from './temp-utilities/slug.js';
7
8
  import { addFallbackSort } from './temp-utilities/sorting.js';
8
9
  import { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js';
9
10
  import { createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js';
10
11
  import { getClientVersionHeaders } from './utilities/clientVersionHeaders.js';
11
12
  import { dataToContentAPI, resolveVersionContent } from './utilities/data/index.js';
13
+ import { injectGlobalType } from './utilities/data/injectGlobalType.js';
12
14
  import { validateRelationshipIds } from './utilities/data/validateRelationships.js';
13
15
  import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
14
16
  import { addFallbackLocale } from './utilities/locale/index.js';
15
17
  import { normalizeLocaleInWhere } from './utilities/meta/normalizeLocaleInWhere.js';
16
- import { buildDocumentSchema } from './utilities/schema/buildDocumentSchema.js';
18
+ import { getDocumentSchema } from './utilities/schema/getDocumentSchema.js';
17
19
  import { convertPayloadWhereToContentAPI } from './utilities/where.js';
18
20
  /**
19
21
  * Heads-up logged locally whenever a job is queued. Queued jobs are executed by Figma's deployed runner, so
@@ -109,7 +111,7 @@ async function createCollection(collectionId) {
109
111
  }
110
112
  });
111
113
  if (error) {
112
- throw createContentAPIError('createCollection', error, httpResponse.status);
114
+ throw createDocumentContentAPIError(this, 'createCollection', error, httpResponse.status, collectionId);
113
115
  }
114
116
  this.payload.logger.info(`Created collection: ${collectionId}`);
115
117
  } catch (error) {
@@ -121,7 +123,7 @@ async function createCollection(collectionId) {
121
123
  }
122
124
  async function findMany({ collection, joins, limit, locale: localeArg, page, pagination: _pagination, sort, where }) {
123
125
  const locale = addFallbackLocale(localeArg, this.payload);
124
- const normalizedWhere = normalizeLocaleInWhere(where, this.payload, collection, locale);
126
+ const localeNormalizedWhere = normalizeLocaleInWhere(where, this.payload, collection, locale);
125
127
  const joinClause = convertPayloadJoinsToContentAPI(this.payload, collection, joins);
126
128
  const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:find', {
127
129
  body: {
@@ -131,13 +133,13 @@ async function findMany({ collection, joins, limit, locale: localeArg, page, pag
131
133
  limit,
132
134
  locale,
133
135
  page: page ?? 1,
134
- schema: this.documentSchema,
136
+ schema: this.documentSchema(),
135
137
  sort: addFallbackSort(sort, this.payload, collection),
136
- where: convertPayloadWhereToContentAPI(normalizedWhere ?? {})
138
+ where: convertPayloadWhereToContentAPI(localeNormalizedWhere, this.payload, collection, false)
137
139
  }
138
140
  });
139
141
  if (error) {
140
- throw createContentAPIError('findMany', error, httpResponse.status);
142
+ throw createDocumentContentAPIError(this, 'findMany', error, httpResponse.status, collection);
141
143
  }
142
144
  if (!response) {
143
145
  throw new Error('No response from findMany');
@@ -165,7 +167,7 @@ async function find(args) {
165
167
  // TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183
166
168
  async function findVersions(args) {
167
169
  const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
168
- const whereClause = convertPayloadWhereToContentAPI(args.where ?? {});
170
+ const whereClause = convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, true);
169
171
  const locale = addFallbackLocale(args.locale, this.payload);
170
172
  const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:find', {
171
173
  body: {
@@ -176,13 +178,13 @@ async function findVersions(args) {
176
178
  limit: args.limit,
177
179
  locale,
178
180
  page: args.page ?? 1,
179
- schema: this.documentSchema,
181
+ schema: this.documentSchema(),
180
182
  sort: sortWithFallback,
181
183
  where: whereClause
182
184
  }
183
185
  });
184
186
  if (error) {
185
- throw createContentAPIError('findVersions', error, httpResponse.status);
187
+ throw createDocumentContentAPIError(this, 'findVersions', error, httpResponse.status, args.collection);
186
188
  }
187
189
  if (!response) {
188
190
  throw new Error('No response from findVersions');
@@ -230,7 +232,7 @@ async function createVersion(args) {
230
232
  body: {
231
233
  collection: args.collectionSlug,
232
234
  contentSystemId: this.contentSystemId,
233
- schema: this.documentSchema,
235
+ schema: this.documentSchema(),
234
236
  versionDoc: {
235
237
  createdAt: args.createdAt,
236
238
  latest: true,
@@ -241,7 +243,7 @@ async function createVersion(args) {
241
243
  }
242
244
  });
243
245
  if (error) {
244
- throw createContentAPIError('createVersion', error, httpResponse.status);
246
+ throw createDocumentContentAPIError(this, 'createVersion', error, httpResponse.status, args.collectionSlug);
245
247
  }
246
248
  if (!response) {
247
249
  throw new Error('No response from createVersion');
@@ -272,7 +274,7 @@ async function updateVersion(args) {
272
274
  contentSystemId: this.contentSystemId,
273
275
  createOnMissing: false,
274
276
  locale,
275
- schema: this.documentSchema,
277
+ schema: this.documentSchema(),
276
278
  versionDoc: {
277
279
  createdAt: versionMeta.createdAt,
278
280
  latest: versionMeta.latest,
@@ -280,11 +282,11 @@ async function updateVersion(args) {
280
282
  updatedAt: versionMeta.updatedAt,
281
283
  version: versionContent
282
284
  },
283
- where: convertPayloadWhereToContentAPI(where)
285
+ where: convertPayloadWhereToContentAPI(where, this.payload, args.collection, true)
284
286
  }
285
287
  });
286
288
  if (error) {
287
- throw createContentAPIError('updateVersion', error, httpResponse.status);
289
+ throw createDocumentContentAPIError(this, 'updateVersion', error, httpResponse.status, args.collection);
288
290
  }
289
291
  if (!response?.result || !('data' in response.result)) {
290
292
  throw new Error('No document data in updateVersion response');
@@ -301,21 +303,25 @@ async function updateVersion(args) {
301
303
  });
302
304
  }
303
305
  async function deleteVersions(args) {
304
- if (!args.collection) {
305
- throw new Error('deleteVersions requires a collection');
306
+ // Globals are addressed by `globalSlug` and map to the `_global-<slug>` collection.
307
+ // Only one of `collection`/`globalSlug` is set.
308
+ const globalSlug = args.globalSlug != null ? getGlobalSlug(args.globalSlug) : undefined;
309
+ const collection = args.collection ?? globalSlug;
310
+ if (collection == null) {
311
+ throw new Error('deleteVersions requires a collection or globalSlug');
306
312
  }
307
313
  const locale = addFallbackLocale(args.locale, this.payload);
308
314
  const { error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:delete', {
309
315
  body: {
310
- collection: args.collection,
316
+ collection,
311
317
  contentSystemId: this.contentSystemId,
312
318
  locale,
313
- schema: this.documentSchema,
314
- where: convertPayloadWhereToContentAPI(args.where)
319
+ schema: this.documentSchema(),
320
+ where: convertPayloadWhereToContentAPI(args.where, this.payload, collection, true)
315
321
  }
316
322
  });
317
323
  if (error) {
318
- throw createContentAPIError('deleteVersions', error, httpResponse.status);
324
+ throw createDocumentContentAPIError(this, 'deleteVersions', error, httpResponse.status, collection);
319
325
  }
320
326
  }
321
327
  async function findOne(args) {
@@ -339,13 +345,13 @@ async function findDistinct(args) {
339
345
  limit: args.limit,
340
346
  locale,
341
347
  page: args.page ?? 1,
342
- schema: this.documentSchema,
348
+ schema: this.documentSchema(),
343
349
  sort: addFallbackSort(args.sort, this.payload, args.collection),
344
- where: convertPayloadWhereToContentAPI(args.where ?? {})
350
+ where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
345
351
  }
346
352
  });
347
353
  if (error) {
348
- throw createContentAPIError('findDistinct', error, httpResponse.status);
354
+ throw createDocumentContentAPIError(this, 'findDistinct', error, httpResponse.status, args.collection);
349
355
  }
350
356
  const { data, ...pagination } = response.result;
351
357
  return {
@@ -372,13 +378,13 @@ async function updateMany(args) {
372
378
  environmentName: this.environmentName,
373
379
  limit: args.limit,
374
380
  locale,
375
- schema: this.documentSchema,
381
+ schema: this.documentSchema(),
376
382
  sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),
377
- where: convertPayloadWhereToContentAPI(args.where)
383
+ where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
378
384
  }
379
385
  });
380
386
  if (error) {
381
- throw createContentAPIError('updateMany', error, httpResponse.status);
387
+ throw createDocumentContentAPIError(this, 'updateMany', error, httpResponse.status, args.collection);
382
388
  }
383
389
  if (!contentAPIResponse) {
384
390
  throw new Error('No response from updateMany');
@@ -413,12 +419,12 @@ async function updateOne(args) {
413
419
  doc: dataToContentAPI(this.payload, args.collection, args.data),
414
420
  environmentName: this.environmentName,
415
421
  locale,
416
- schema: this.documentSchema,
417
- where: convertPayloadWhereToContentAPI(where)
422
+ schema: this.documentSchema(),
423
+ where: convertPayloadWhereToContentAPI(where, this.payload, args.collection, false)
418
424
  }
419
425
  });
420
426
  if (error) {
421
- throw createContentAPIError('updateOne', error, httpResponse.status);
427
+ throw createDocumentContentAPIError(this, 'updateOne', error, httpResponse.status, args.collection);
422
428
  }
423
429
  if (!contentAPIResponse) {
424
430
  throw new Error('No response from updateOne');
@@ -445,12 +451,12 @@ async function deleteMany(args) {
445
451
  contentSystemId: this.contentSystemId,
446
452
  environmentName: this.environmentName,
447
453
  locale,
448
- schema: this.documentSchema,
449
- where: convertPayloadWhereToContentAPI(args.where)
454
+ schema: this.documentSchema(),
455
+ where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
450
456
  }
451
457
  });
452
458
  if (error) {
453
- throw createContentAPIError('deleteMany', error, httpResponse.status);
459
+ throw createDocumentContentAPIError(this, 'deleteMany', error, httpResponse.status, args.collection);
454
460
  }
455
461
  }
456
462
  async function deleteOne(args) {
@@ -461,12 +467,12 @@ async function deleteOne(args) {
461
467
  contentSystemId: this.contentSystemId,
462
468
  environmentName: this.environmentName,
463
469
  locale,
464
- schema: this.documentSchema,
465
- where: convertPayloadWhereToContentAPI(args.where)
470
+ schema: this.documentSchema(),
471
+ where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
466
472
  }
467
473
  });
468
474
  if (error) {
469
- throw createContentAPIError('deleteOne', error, httpResponse.status);
475
+ throw createDocumentContentAPIError(this, 'deleteOne', error, httpResponse.status, args.collection);
470
476
  }
471
477
  if (!response?.result || !('data' in response.result)) {
472
478
  throw new Error('No document data in deleteOne response');
@@ -516,11 +522,17 @@ async function create(args) {
516
522
  },
517
523
  environmentName: this.environmentName,
518
524
  locale,
519
- schema: this.documentSchema
525
+ schema: this.documentSchema()
520
526
  }
521
527
  });
522
528
  if (error) {
523
- throw createContentAPIError('create', error, httpResponse.status);
529
+ redirectInitialAutosaveCreate({
530
+ collectionSlug: args.collection,
531
+ errorCode: error.code,
532
+ payload: this.payload,
533
+ req: args.req
534
+ });
535
+ throw createDocumentContentAPIError(this, 'create', error, httpResponse.status, args.collection);
524
536
  }
525
537
  if (!contentAPIResponse) {
526
538
  throw new Error('No response from create');
@@ -568,12 +580,12 @@ async function count(args) {
568
580
  collection: args.collection,
569
581
  contentSystemId: this.contentSystemId,
570
582
  locale,
571
- schema: this.documentSchema,
572
- where: convertPayloadWhereToContentAPI(args.where)
583
+ schema: this.documentSchema(),
584
+ where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
573
585
  }
574
586
  });
575
587
  if (error) {
576
- throw createContentAPIError('count', error, httpResponse.status);
588
+ throw createDocumentContentAPIError(this, 'count', error, httpResponse.status, args.collection);
577
589
  }
578
590
  if (!response) {
579
591
  throw new Error('No response from count');
@@ -589,12 +601,12 @@ async function countVersions(args) {
589
601
  collection: args.collection,
590
602
  contentSystemId: this.contentSystemId,
591
603
  locale,
592
- schema: this.documentSchema,
593
- where: convertPayloadWhereToContentAPI(args.where)
604
+ schema: this.documentSchema(),
605
+ where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, true)
594
606
  }
595
607
  });
596
608
  if (error) {
597
- throw createContentAPIError('countVersions', error, httpResponse.status);
609
+ throw createDocumentContentAPIError(this, 'countVersions', error, httpResponse.status, args.collection);
598
610
  }
599
611
  if (!response) {
600
612
  throw new Error('No response from countVersions');
@@ -603,12 +615,19 @@ async function countVersions(args) {
603
615
  totalDocs: response.result.count
604
616
  };
605
617
  }
618
+ // Content API document ids are text. A document id is only ever a string or a number
619
+ // (a custom numeric id), so coerce those to a string and treat anything else as absent.
620
+ function toIdString(value) {
621
+ return typeof value === 'string' || typeof value === 'number' ? String(value) : undefined;
622
+ }
606
623
  async function upsert(args) {
607
- let documentId = args.data.id;
624
+ // The Content API stores every document id as text; a custom numeric id arrives as a
625
+ // number, so coerce it (matching `create`) before it becomes `createOnMissing.id`.
626
+ let documentId = toIdString(args.data.id);
608
627
  if (!documentId && args.where && 'id' in args.where) {
609
628
  const idClause = args.where.id;
610
- if (idClause && 'equals' in idClause) {
611
- documentId = idClause.equals;
629
+ if (idClause) {
630
+ documentId = toIdString(idClause.equals);
612
631
  }
613
632
  }
614
633
  if (!documentId) {
@@ -620,25 +639,31 @@ async function upsert(args) {
620
639
  data: args.data,
621
640
  payload: this.payload
622
641
  });
642
+ // `createdAt` is create-time metadata, so seed it on `createOnMissing` (used only when no
643
+ // document matches) rather than on `doc`. The server preserves an existing document's
644
+ // `createdAt` on update precisely because `doc` omits it; `updatedAt` is still refreshed on
645
+ // every write via `dataToContentAPI`. Sending `createdAt` on `doc` would overwrite it on
646
+ // every update (e.g. repeated `updateGlobal` calls).
647
+ const createdAt = new Date().toISOString();
623
648
  const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
624
649
  body: {
625
650
  collection: args.collection,
626
651
  contentSystemId: this.contentSystemId,
627
652
  createOnMissing: {
628
- id: documentId
653
+ id: documentId,
654
+ createdAt
629
655
  },
630
656
  doc: dataToContentAPI(this.payload, args.collection, args.data, {
631
- applyDefaults: true,
632
- createdAt: true
657
+ applyDefaults: true
633
658
  }),
634
659
  environmentName: this.environmentName,
635
660
  locale,
636
- schema: this.documentSchema,
637
- where: convertPayloadWhereToContentAPI(args.where)
661
+ schema: this.documentSchema(),
662
+ where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
638
663
  }
639
664
  });
640
665
  if (error) {
641
- throw createContentAPIError('upsert', error, httpResponse.status);
666
+ throw createDocumentContentAPIError(this, 'upsert', error, httpResponse.status, args.collection);
642
667
  }
643
668
  if (!contentAPIResponse) {
644
669
  throw new Error('No response from upsert');
@@ -658,6 +683,7 @@ async function upsert(args) {
658
683
  });
659
684
  }
660
685
  async function updateJobs(args) {
686
+ const collection = 'payload-jobs';
661
687
  const { id, limit, returning, sort, where } = args;
662
688
  if (id == null && where == null) {
663
689
  throw new Error('updateJobs requires either id or a where clause');
@@ -678,12 +704,12 @@ async function updateJobs(args) {
678
704
  equals: String(id)
679
705
  }
680
706
  } : where;
681
- const docData = dataToContentAPI(this.payload, 'payload-jobs', data);
682
- const sortClause = addFallbackSort(sort || '-updatedAt', this.payload, 'payload-jobs');
683
- const whereQuery = convertPayloadWhereToContentAPI(whereClause);
707
+ const docData = dataToContentAPI(this.payload, collection, data);
708
+ const sortClause = addFallbackSort(sort || '-updatedAt', this.payload, collection);
709
+ const whereQuery = convertPayloadWhereToContentAPI(whereClause, this.payload, collection, false);
684
710
  const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
685
711
  body: {
686
- collection: 'payload-jobs',
712
+ collection,
687
713
  contentSystemId: this.contentSystemId,
688
714
  createOnMissing: false,
689
715
  doc: docData,
@@ -691,13 +717,13 @@ async function updateJobs(args) {
691
717
  ...limit != null && {
692
718
  limit
693
719
  },
694
- schema: this.documentSchema,
720
+ schema: this.documentSchema(),
695
721
  sort: sortClause,
696
722
  where: whereQuery
697
723
  }
698
724
  });
699
725
  if (error) {
700
- throw createContentAPIError('updateJobs', error, httpResponse.status);
726
+ throw createDocumentContentAPIError(this, 'updateJobs', error, httpResponse.status, collection);
701
727
  }
702
728
  if (!response) {
703
729
  throw new Error('No response from updateJobs');
@@ -709,18 +735,18 @@ async function updateJobs(args) {
709
735
  return [];
710
736
  }
711
737
  return response.result.data.map((doc)=>unwrapDocument({
712
- collectionSlug: 'payload-jobs',
738
+ collectionSlug: collection,
713
739
  doc,
714
740
  payload: this.payload
715
741
  }));
716
742
  }
717
- function createGlobal(args) {
743
+ async function createGlobal(args) {
718
744
  // Globals are singletons identified by their slug. Use upsert so concurrent calls
719
745
  // (e.g. handleSchedules processing multiple queueables with the same null jobStats)
720
746
  // don't fail with "A record with this field already exists". The deep-merge semantics
721
747
  // of the update path are safe here: callers that want a fresh create (first run) get
722
748
  // an effective create, and callers that race a prior create get a merge instead.
723
- return this.upsert({
749
+ const doc = await this.upsert({
724
750
  collection: getGlobalSlug(args.slug),
725
751
  data: {
726
752
  ...args.data,
@@ -732,6 +758,7 @@ function createGlobal(args) {
732
758
  }
733
759
  }
734
760
  });
761
+ return injectGlobalType(doc, args.slug);
735
762
  }
736
763
  async function findGlobal(args) {
737
764
  const doc = await this.findOne({
@@ -739,17 +766,10 @@ async function findGlobal(args) {
739
766
  locale: args.locale,
740
767
  where: args.where ?? {}
741
768
  });
742
- if (doc != null) {
743
- ;
744
- doc.globalType = args.slug;
745
- }
746
- return doc;
769
+ return injectGlobalType(doc, args.slug);
747
770
  }
748
771
  async function updateGlobal(args) {
749
- // TODO: upsert's `createOnMissing` path generates a new `createdAt` on every call,
750
- // which overwrites the original timestamp on updates. The fix belongs in the Content API:
751
- // `createOnMissing` should preserve `createdAt` on updates and only set it on creates.
752
- return this.upsert({
772
+ const doc = await this.upsert({
753
773
  collection: getGlobalSlug(args.slug),
754
774
  data: args.data,
755
775
  where: {
@@ -758,6 +778,7 @@ async function updateGlobal(args) {
758
778
  }
759
779
  }
760
780
  });
781
+ return injectGlobalType(doc, args.slug);
761
782
  }
762
783
  // TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183
763
784
  function findGlobalVersions(args) {
@@ -809,6 +830,13 @@ function countGlobalVersions(args) {
809
830
  where: args.where
810
831
  });
811
832
  }
833
+ function createDocumentContentAPIError(adapter, operation, error, status, collectionSlug) {
834
+ const validationError = maybeCreateUniqueValidationError(error, collectionSlug, adapter);
835
+ if (validationError != null) {
836
+ return validationError;
837
+ }
838
+ return createContentAPIError(operation, error, status);
839
+ }
812
840
  function createContentAPIError(operation, error, status) {
813
841
  return new APIError(`Content API ${operation} error: ${error.message}`, status, {
814
842
  code: error.code,
@@ -816,6 +844,27 @@ function createContentAPIError(operation, error, status) {
816
844
  field: error.field
817
845
  });
818
846
  }
847
+ // A unique-constraint violation from the Content API is Payload's `ValidationError` contract:
848
+ // reconstruct it with the offending field path(s) so callers can map the error back to a field
849
+ // (matching what Payload's other database adapters throw). Falls back to a generic APIError when
850
+ // the collection or offending field is unknown.
851
+ function maybeCreateUniqueValidationError(error, collectionSlug, adapter) {
852
+ if (error.constraint !== 'unique_constraint') {
853
+ return null;
854
+ }
855
+ const paths = (error.field ?? '').split(',').map((path)=>path.trim()).filter((path)=>path.length > 0);
856
+ if (paths.length === 0) {
857
+ adapter.payload.logger.error(`Unique constraint violation but no offending field.`);
858
+ return null;
859
+ }
860
+ return new ValidationError({
861
+ collection: collectionSlug,
862
+ errors: paths.map((path)=>({
863
+ message: error.message,
864
+ path
865
+ }))
866
+ });
867
+ }
819
868
  export const contentAPIAdapter = (opts)=>({
820
869
  name: 'content-api',
821
870
  defaultIDType: 'text',
@@ -855,7 +904,7 @@ export const contentAPIAdapter = (opts)=>({
855
904
  deleteMany: deleteMany,
856
905
  deleteOne: deleteOne,
857
906
  deleteVersions: deleteVersions,
858
- documentSchema: buildDocumentSchema(payload.config),
907
+ documentSchema: ()=>getDocumentSchema(payload.config),
859
908
  environmentName: opts.environmentName,
860
909
  find: find,
861
910
  findDistinct: findDistinct,