@payloadcms/figma 0.0.1-alpha.9 → 0.1.0-alpha.0

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 (470) hide show
  1. package/dist/api/control-plane.d.ts +56 -7
  2. package/dist/api/control-plane.js +188 -74
  3. package/dist/api/error-response.d.ts +36 -0
  4. package/dist/api/error-response.js +66 -0
  5. package/dist/api/figma-api.d.ts +24 -3
  6. package/dist/api/figma-api.js +110 -34
  7. package/dist/auth/browser.d.ts +0 -1
  8. package/dist/auth/browser.js +0 -2
  9. package/dist/auth/callback-server.d.ts +19 -8
  10. package/dist/auth/callback-server.js +72 -32
  11. package/dist/auth/credentials.d.ts +20 -0
  12. package/dist/auth/credentials.js +19 -0
  13. package/dist/auth/crypto-utils.d.ts +28 -1
  14. package/dist/auth/crypto-utils.js +132 -23
  15. package/dist/auth/jwt-validator.d.ts +23 -6
  16. package/dist/auth/jwt-validator.js +35 -9
  17. package/dist/auth/oauth-flow.d.ts +19 -4
  18. package/dist/auth/oauth-flow.js +151 -34
  19. package/dist/auth/paste-code.d.ts +33 -0
  20. package/dist/auth/paste-code.js +87 -0
  21. package/dist/auth/pkce.d.ts +0 -1
  22. package/dist/auth/pkce.js +0 -2
  23. package/dist/auth/project-token.d.ts +32 -17
  24. package/dist/auth/project-token.js +176 -68
  25. package/dist/auth/refresh.d.ts +2 -2
  26. package/dist/auth/refresh.js +25 -14
  27. package/dist/auth/token-store-migration.d.ts +57 -0
  28. package/dist/auth/token-store-migration.js +154 -0
  29. package/dist/auth/token-store.d.ts +63 -98
  30. package/dist/auth/token-store.js +405 -124
  31. package/dist/auth/types.d.ts +40 -6
  32. package/dist/auth/types.js +1 -3
  33. package/dist/cli.d.ts +0 -1
  34. package/dist/cli.js +102 -8
  35. package/dist/commands/bootstrap.d.ts +17 -0
  36. package/dist/commands/bootstrap.js +88 -0
  37. package/dist/commands/build-lambda-zip.d.ts +4 -0
  38. package/dist/commands/build-lambda-zip.js +17 -0
  39. package/dist/commands/debug.d.ts +7 -0
  40. package/dist/commands/debug.js +178 -0
  41. package/dist/commands/deploy.d.ts +11 -1
  42. package/dist/commands/deploy.js +193 -153
  43. package/dist/commands/dump-tokens.d.ts +11 -0
  44. package/dist/commands/dump-tokens.js +67 -0
  45. package/dist/commands/env.d.ts +12 -0
  46. package/dist/commands/env.js +86 -0
  47. package/dist/commands/init.d.ts +9 -6
  48. package/dist/commands/init.js +232 -152
  49. package/dist/commands/list-tokens.d.ts +3 -4
  50. package/dist/commands/list-tokens.js +24 -11
  51. package/dist/commands/login.d.ts +8 -2
  52. package/dist/commands/login.js +34 -18
  53. package/dist/commands/logout.d.ts +5 -5
  54. package/dist/commands/logout.js +77 -17
  55. package/dist/commands/upgrade.d.ts +4 -0
  56. package/dist/commands/upgrade.js +329 -0
  57. package/dist/commands/upload-schema.d.ts +8 -0
  58. package/dist/commands/upload-schema.js +91 -0
  59. package/dist/config/oauth.d.ts +17 -12
  60. package/dist/config/oauth.js +38 -39
  61. package/dist/constants.d.ts +63 -19
  62. package/dist/constants.js +158 -20
  63. package/dist/db-content-api/generated/content-api-types.d.ts +7574 -0
  64. package/dist/db-content-api/generated/content-api-types.js +5 -0
  65. package/dist/db-content-api/index.d.ts +37 -0
  66. package/dist/db-content-api/index.js +938 -0
  67. package/dist/db-content-api/temp-utilities/slug.d.ts +1 -0
  68. package/dist/db-content-api/temp-utilities/slug.js +1 -0
  69. package/dist/db-content-api/temp-utilities/sorting.d.ts +2 -0
  70. package/dist/db-content-api/temp-utilities/sorting.js +37 -0
  71. package/dist/db-content-api/temp-utilities/types.d.ts +21 -0
  72. package/dist/db-content-api/temp-utilities/types.js +13 -0
  73. package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts +38 -0
  74. package/dist/db-content-api/temp-utilities/unwrapDocument.js +62 -0
  75. package/dist/db-content-api/utilities/auth.d.ts +29 -0
  76. package/dist/db-content-api/utilities/auth.js +82 -0
  77. package/dist/db-content-api/utilities/data/applyDefaults.d.ts +6 -0
  78. package/dist/db-content-api/utilities/data/applyDefaults.js +75 -0
  79. package/dist/db-content-api/utilities/data/castFieldValue.d.ts +10 -0
  80. package/dist/db-content-api/utilities/data/castFieldValue.js +66 -0
  81. package/dist/db-content-api/utilities/data/index.d.ts +48 -0
  82. package/dist/db-content-api/utilities/data/index.js +299 -0
  83. package/dist/db-content-api/utilities/data/pointShape.d.ts +3 -0
  84. package/dist/db-content-api/utilities/data/pointShape.js +43 -0
  85. package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +11 -0
  86. package/dist/db-content-api/utilities/data/removeVirtualFields.js +52 -0
  87. package/dist/db-content-api/utilities/data/richTextShape.d.ts +3 -0
  88. package/dist/db-content-api/utilities/data/richTextShape.js +56 -0
  89. package/dist/db-content-api/utilities/data/stripFields.d.ts +47 -0
  90. package/dist/db-content-api/utilities/data/stripFields.js +170 -0
  91. package/dist/db-content-api/utilities/data/transformPublishedLocale.d.ts +22 -0
  92. package/dist/db-content-api/utilities/data/transformPublishedLocale.js +40 -0
  93. package/dist/db-content-api/utilities/data/validateRelationships.d.ts +6 -0
  94. package/dist/db-content-api/utilities/data/validateRelationships.js +100 -0
  95. package/dist/db-content-api/utilities/joins.d.ts +52 -0
  96. package/dist/db-content-api/utilities/joins.js +137 -0
  97. package/dist/db-content-api/utilities/locale/index.d.ts +9 -0
  98. package/dist/db-content-api/utilities/locale/index.js +19 -0
  99. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +10 -0
  100. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +71 -0
  101. package/dist/db-content-api/utilities/meta/buildMeta.d.ts +41 -0
  102. package/dist/db-content-api/utilities/meta/buildMeta.js +39 -0
  103. package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +16 -0
  104. package/dist/db-content-api/utilities/meta/buildPathTypes.js +243 -0
  105. package/dist/db-content-api/utilities/meta/buildUniquePaths.d.ts +12 -0
  106. package/dist/db-content-api/utilities/meta/buildUniquePaths.js +60 -0
  107. package/dist/db-content-api/utilities/meta/normalizeLocaleInWhere.d.ts +9 -0
  108. package/dist/db-content-api/utilities/meta/normalizeLocaleInWhere.js +100 -0
  109. package/dist/db-content-api/utilities/resolveBlocks.d.ts +19 -0
  110. package/dist/db-content-api/utilities/resolveBlocks.js +31 -0
  111. package/dist/db-content-api/utilities/schema/buildDocumentSchema.d.ts +55 -0
  112. package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +182 -0
  113. package/dist/db-content-api/utilities/where.d.ts +19 -0
  114. package/dist/db-content-api/utilities/where.js +106 -0
  115. package/dist/deploy/schedule-extract-plugin.d.ts +10 -0
  116. package/dist/deploy/schedule-extract-plugin.js +32 -0
  117. package/dist/endpoints/health.d.ts +2 -0
  118. package/dist/endpoints/health.js +9 -0
  119. package/dist/endpoints/schema.d.ts +2 -0
  120. package/dist/endpoints/schema.js +27 -0
  121. package/dist/exports/client.d.ts +2 -1
  122. package/dist/exports/client.js +2 -2
  123. package/dist/index.d.ts +2 -2
  124. package/dist/index.js +3 -3
  125. package/dist/lib/download-skill.d.ts +12 -0
  126. package/dist/lib/download-skill.js +77 -0
  127. package/dist/oauth/components/FigmaAvatar/index.d.ts +3 -0
  128. package/dist/oauth/components/FigmaAvatar/index.js +25 -0
  129. package/dist/oauth/components/FigmaAvatar/index.scss +12 -0
  130. package/dist/oauth/components/FigmaAvatarCell/index.d.ts +4 -0
  131. package/dist/oauth/components/FigmaAvatarCell/index.js +23 -0
  132. package/dist/oauth/components/FigmaAvatarCell/index.scss +5 -0
  133. package/dist/oauth/components/FigmaAvatarPlaceholder/index.d.ts +8 -0
  134. package/dist/oauth/components/FigmaAvatarPlaceholder/index.js +35 -0
  135. package/dist/oauth/components/FigmaAvatarPlaceholder/index.scss +28 -0
  136. package/dist/oauth/components/LoginButton/iframeAutoLogin.d.ts +81 -0
  137. package/dist/oauth/components/LoginButton/iframeAutoLogin.js +168 -0
  138. package/dist/oauth/components/LoginButton/index.d.ts +0 -1
  139. package/dist/oauth/components/LoginButton/index.js +156 -18
  140. package/dist/oauth/components/LoginButton/index.scss +75 -3
  141. package/dist/oauth/components/LogoutButton/index.d.ts +0 -1
  142. package/dist/oauth/components/LogoutButton/index.js +20 -9
  143. package/dist/oauth/defaults.d.ts +3 -2
  144. package/dist/oauth/defaults.js +79 -12
  145. package/dist/oauth/endpoints/getLoginEndpoint.d.ts +0 -1
  146. package/dist/oauth/endpoints/getLoginEndpoint.js +87 -84
  147. package/dist/oauth/endpoints/getLogoutEndpoint.d.ts +0 -1
  148. package/dist/oauth/endpoints/getLogoutEndpoint.js +7 -6
  149. package/dist/oauth/endpoints/getMetaEndpoint.d.ts +0 -1
  150. package/dist/oauth/endpoints/getMetaEndpoint.js +18 -5
  151. package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts +0 -1
  152. package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js +11 -4
  153. package/dist/oauth/exports/client.d.ts +0 -1
  154. package/dist/oauth/exports/client.js +0 -2
  155. package/dist/oauth/hooks/afterLogout.d.ts +0 -1
  156. package/dist/oauth/hooks/afterLogout.js +0 -2
  157. package/dist/oauth/hooks/me.d.ts +0 -1
  158. package/dist/oauth/hooks/me.js +0 -2
  159. package/dist/oauth/hooks/refresh.d.ts +0 -1
  160. package/dist/oauth/hooks/refresh.js +2 -3
  161. package/dist/oauth/index.d.ts +0 -1
  162. package/dist/oauth/index.js +27 -7
  163. package/dist/oauth/strategy/index.d.ts +0 -3
  164. package/dist/oauth/strategy/index.js +55 -34
  165. package/dist/oauth/types.d.ts +23 -7
  166. package/dist/oauth/types.js +0 -2
  167. package/dist/oauth/utilities/buildUnauthorizedRedirect.d.ts +14 -0
  168. package/dist/oauth/utilities/buildUnauthorizedRedirect.js +28 -0
  169. package/dist/oauth/utilities/clearCookie.d.ts +0 -1
  170. package/dist/oauth/utilities/clearCookie.js +5 -3
  171. package/dist/oauth/utilities/createCookieOptions.d.ts +0 -1
  172. package/dist/oauth/utilities/createCookieOptions.js +9 -4
  173. package/dist/oauth/utilities/createDebugLogger.d.ts +0 -1
  174. package/dist/oauth/utilities/createDebugLogger.js +0 -2
  175. package/dist/oauth/utilities/establishSession.d.ts +22 -0
  176. package/dist/oauth/utilities/establishSession.js +80 -0
  177. package/dist/oauth/utilities/exchangeCodeForAccessToken.d.ts +23 -0
  178. package/dist/oauth/utilities/exchangeCodeForAccessToken.js +26 -0
  179. package/dist/oauth/utilities/extractOrigin.d.ts +0 -1
  180. package/dist/oauth/utilities/extractOrigin.js +0 -2
  181. package/dist/oauth/utilities/figmaHostnames.d.ts +2 -0
  182. package/dist/oauth/utilities/figmaHostnames.js +24 -0
  183. package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +0 -1
  184. package/dist/oauth/utilities/getAdminCollectionSlug.js +0 -2
  185. package/dist/oauth/utilities/getAuthorizeURL.d.ts +65 -2
  186. package/dist/oauth/utilities/getAuthorizeURL.js +57 -4
  187. package/dist/oauth/utilities/getCookieExpiration.d.ts +0 -1
  188. package/dist/oauth/utilities/getCookieExpiration.js +0 -2
  189. package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts +0 -1
  190. package/dist/oauth/utilities/getSecondsFromTokenExp.js +0 -2
  191. package/dist/oauth/utilities/getTokenExp.d.ts +0 -1
  192. package/dist/oauth/utilities/getTokenExp.js +0 -2
  193. package/dist/oauth/utilities/getUsernameField.d.ts +0 -1
  194. package/dist/oauth/utilities/getUsernameField.js +0 -2
  195. package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts +0 -1
  196. package/dist/oauth/utilities/hasUserTokenPropsChanged.js +0 -2
  197. package/dist/oauth/utilities/isAbsoluteURL.d.ts +1 -0
  198. package/dist/oauth/utilities/isAbsoluteURL.js +1 -0
  199. package/dist/oauth/utilities/isDuplicateKeyError.d.ts +6 -0
  200. package/dist/oauth/utilities/isDuplicateKeyError.js +12 -0
  201. package/dist/oauth/utilities/mergeHeaders.d.ts +0 -1
  202. package/dist/oauth/utilities/mergeHeaders.js +0 -2
  203. package/dist/oauth/utilities/refreshTokens.d.ts +0 -1
  204. package/dist/oauth/utilities/refreshTokens.js +21 -13
  205. package/dist/oauth/utilities/withPartitionedCookie.d.ts +19 -0
  206. package/dist/oauth/utilities/withPartitionedCookie.js +26 -0
  207. package/dist/oauth/utils/getSearchParam.d.ts +17 -0
  208. package/dist/oauth/utils/getSearchParam.js +22 -0
  209. package/dist/plugin/adapter.d.ts +0 -1
  210. package/dist/plugin/adapter.js +0 -2
  211. package/dist/plugin/auth-preflight.d.ts +7 -0
  212. package/dist/plugin/auth-preflight.js +18 -0
  213. package/dist/plugin/bootstrap-preflight.d.ts +22 -0
  214. package/dist/plugin/bootstrap-preflight.js +43 -0
  215. package/dist/plugin/build-config.d.ts +27 -15
  216. package/dist/plugin/build-config.js +380 -16
  217. package/dist/plugin/dev-cookie-names.d.ts +13 -0
  218. package/dist/plugin/dev-cookie-names.js +17 -0
  219. package/dist/scss.d.js +2 -0
  220. package/dist/storage-content-api/api-types.d.ts +183 -0
  221. package/dist/storage-content-api/api-types.js +4 -0
  222. package/dist/storage-content-api/client-uploads/generate.d.ts +14 -0
  223. package/dist/storage-content-api/client-uploads/generate.js +69 -0
  224. package/dist/storage-content-api/client.d.ts +5 -0
  225. package/dist/storage-content-api/client.js +37 -0
  226. package/dist/storage-content-api/generateURL.d.ts +6 -0
  227. package/dist/storage-content-api/generateURL.js +6 -0
  228. package/dist/storage-content-api/handleDelete.d.ts +7 -0
  229. package/dist/storage-content-api/handleDelete.js +15 -0
  230. package/dist/storage-content-api/handleUpload.d.ts +10 -0
  231. package/dist/storage-content-api/handleUpload.js +162 -0
  232. package/dist/storage-content-api/index.d.ts +4 -0
  233. package/dist/storage-content-api/index.js +37 -0
  234. package/dist/storage-content-api/staticHandler.d.ts +9 -0
  235. package/dist/storage-content-api/staticHandler.js +61 -0
  236. package/dist/storage-content-api/types.d.ts +9 -0
  237. package/dist/storage-content-api/types.js +1 -0
  238. package/dist/storage-content-api/utilities/getSafeFilename.d.ts +11 -0
  239. package/dist/storage-content-api/utilities/getSafeFilename.js +59 -0
  240. package/dist/storage-content-api/utilities/index.d.ts +2 -0
  241. package/dist/storage-content-api/utilities/index.js +2 -0
  242. package/dist/storage-content-api/utilities/parseUploadReference.d.ts +17 -0
  243. package/dist/storage-content-api/utilities/parseUploadReference.js +27 -0
  244. package/dist/templates/.env.example +5 -0
  245. package/dist/templates/README.md +19 -0
  246. package/dist/types/config.d.ts +2 -2
  247. package/dist/types/config.js +0 -4
  248. package/dist/types.d.ts +10 -2
  249. package/dist/types.js +0 -2
  250. package/dist/utils/adapters/nextjs.d.ts +8 -0
  251. package/dist/utils/adapters/nextjs.js +61 -0
  252. package/dist/utils/adapters/nitro.d.ts +8 -0
  253. package/dist/utils/adapters/nitro.js +172 -0
  254. package/dist/utils/adapters/vite.d.ts +9 -0
  255. package/dist/utils/adapters/vite.js +31 -0
  256. package/dist/utils/asset-collection.d.ts +27 -7
  257. package/dist/utils/asset-collection.js +59 -32
  258. package/dist/utils/build-detection.d.ts +5 -12
  259. package/dist/utils/build-detection.js +74 -13
  260. package/dist/utils/build-lambda-zip.d.ts +25 -0
  261. package/dist/utils/build-lambda-zip.js +90 -0
  262. package/dist/utils/cache-bootstrap.d.ts +7 -0
  263. package/dist/utils/cache-bootstrap.js +16 -0
  264. package/dist/utils/config.d.ts +0 -1
  265. package/dist/utils/config.js +1 -3
  266. package/dist/utils/deploy-adapter.d.ts +45 -0
  267. package/dist/utils/deploy-adapter.js +56 -0
  268. package/dist/utils/download-template.d.ts +9 -2
  269. package/dist/utils/download-template.js +24 -20
  270. package/dist/utils/env-management.d.ts +24 -8
  271. package/dist/utils/env-management.js +119 -66
  272. package/dist/utils/format-env-suffix.d.ts +11 -0
  273. package/dist/utils/format-env-suffix.js +11 -0
  274. package/dist/utils/format.d.ts +0 -1
  275. package/dist/utils/format.js +0 -2
  276. package/dist/utils/formatter.d.ts +0 -1
  277. package/dist/utils/formatter.js +23 -13
  278. package/dist/utils/fs-utils.d.ts +12 -0
  279. package/dist/utils/fs-utils.js +55 -0
  280. package/dist/utils/git.d.ts +0 -1
  281. package/dist/utils/git.js +0 -2
  282. package/dist/utils/handle-upgrade.d.ts +8 -0
  283. package/dist/utils/handle-upgrade.js +39 -0
  284. package/dist/utils/is-debug.d.ts +0 -1
  285. package/dist/utils/is-debug.js +0 -2
  286. package/dist/utils/lambda-config.d.ts +3 -2
  287. package/dist/utils/lambda-config.js +75 -80
  288. package/dist/utils/load-payload-config.d.ts +9 -0
  289. package/dist/utils/load-payload-config.js +27 -0
  290. package/dist/utils/log.d.ts +0 -1
  291. package/dist/utils/log.js +0 -2
  292. package/dist/utils/messages.d.ts +1 -3
  293. package/dist/utils/messages.js +47 -13
  294. package/dist/utils/package-manager.d.ts +24 -1
  295. package/dist/utils/package-manager.js +53 -2
  296. package/dist/utils/parse-template-spec.d.ts +11 -0
  297. package/dist/utils/parse-template-spec.js +60 -0
  298. package/dist/utils/payload-config-ast.d.ts +27 -7
  299. package/dist/utils/payload-config-ast.js +106 -60
  300. package/dist/utils/payload-config-finder.d.ts +2 -3
  301. package/dist/utils/payload-config-finder.js +48 -11
  302. package/dist/utils/payload-config-modifier.d.ts +1 -2
  303. package/dist/utils/payload-config-modifier.js +114 -68
  304. package/dist/utils/payload-package-check.d.ts +28 -3
  305. package/dist/utils/payload-package-check.js +90 -31
  306. package/dist/utils/project.d.ts +8 -4
  307. package/dist/utils/project.js +63 -37
  308. package/dist/utils/resolve-environment.d.ts +13 -0
  309. package/dist/utils/resolve-environment.js +29 -0
  310. package/dist/utils/s3-upload.d.ts +7 -3
  311. package/dist/utils/s3-upload.js +44 -9
  312. package/dist/utils/token-display.d.ts +5 -2
  313. package/dist/utils/token-display.js +49 -24
  314. package/dist/utils/typescript-validator.d.ts +0 -1
  315. package/dist/utils/typescript-validator.js +4 -8
  316. package/dist/utils/version-check.d.ts +2 -0
  317. package/dist/utils/version-check.js +43 -0
  318. package/package.json +47 -16
  319. package/dist/api/control-plane.d.ts.map +0 -1
  320. package/dist/api/control-plane.js.map +0 -1
  321. package/dist/api/figma-api.d.ts.map +0 -1
  322. package/dist/api/figma-api.js.map +0 -1
  323. package/dist/auth/browser.d.ts.map +0 -1
  324. package/dist/auth/browser.js.map +0 -1
  325. package/dist/auth/callback-server.d.ts.map +0 -1
  326. package/dist/auth/callback-server.js.map +0 -1
  327. package/dist/auth/crypto-utils.d.ts.map +0 -1
  328. package/dist/auth/crypto-utils.js.map +0 -1
  329. package/dist/auth/jwt-validator.d.ts.map +0 -1
  330. package/dist/auth/jwt-validator.js.map +0 -1
  331. package/dist/auth/oauth-flow.d.ts.map +0 -1
  332. package/dist/auth/oauth-flow.js.map +0 -1
  333. package/dist/auth/pkce.d.ts.map +0 -1
  334. package/dist/auth/pkce.js.map +0 -1
  335. package/dist/auth/project-token.d.ts.map +0 -1
  336. package/dist/auth/project-token.js.map +0 -1
  337. package/dist/auth/refresh.d.ts.map +0 -1
  338. package/dist/auth/refresh.js.map +0 -1
  339. package/dist/auth/token-store.d.ts.map +0 -1
  340. package/dist/auth/token-store.js.map +0 -1
  341. package/dist/auth/types.d.ts.map +0 -1
  342. package/dist/auth/types.js.map +0 -1
  343. package/dist/cli.d.ts.map +0 -1
  344. package/dist/cli.js.map +0 -1
  345. package/dist/commands/deploy.d.ts.map +0 -1
  346. package/dist/commands/deploy.js.map +0 -1
  347. package/dist/commands/init.d.ts.map +0 -1
  348. package/dist/commands/init.js.map +0 -1
  349. package/dist/commands/list-tokens.d.ts.map +0 -1
  350. package/dist/commands/list-tokens.js.map +0 -1
  351. package/dist/commands/login.d.ts.map +0 -1
  352. package/dist/commands/login.js.map +0 -1
  353. package/dist/commands/logout.d.ts.map +0 -1
  354. package/dist/commands/logout.js.map +0 -1
  355. package/dist/config/oauth.d.ts.map +0 -1
  356. package/dist/config/oauth.js.map +0 -1
  357. package/dist/constants.d.ts.map +0 -1
  358. package/dist/constants.js.map +0 -1
  359. package/dist/exports/client.d.ts.map +0 -1
  360. package/dist/exports/client.js.map +0 -1
  361. package/dist/index.d.ts.map +0 -1
  362. package/dist/index.js.map +0 -1
  363. package/dist/oauth/components/LoginButton/index.d.ts.map +0 -1
  364. package/dist/oauth/components/LoginButton/index.js.map +0 -1
  365. package/dist/oauth/components/LogoutButton/index.d.ts.map +0 -1
  366. package/dist/oauth/components/LogoutButton/index.js.map +0 -1
  367. package/dist/oauth/defaults.d.ts.map +0 -1
  368. package/dist/oauth/defaults.js.map +0 -1
  369. package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +0 -1
  370. package/dist/oauth/endpoints/getLoginEndpoint.js.map +0 -1
  371. package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +0 -1
  372. package/dist/oauth/endpoints/getLogoutEndpoint.js.map +0 -1
  373. package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +0 -1
  374. package/dist/oauth/endpoints/getMetaEndpoint.js.map +0 -1
  375. package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +0 -1
  376. package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +0 -1
  377. package/dist/oauth/exports/client.d.ts.map +0 -1
  378. package/dist/oauth/exports/client.js.map +0 -1
  379. package/dist/oauth/hooks/afterLogout.d.ts.map +0 -1
  380. package/dist/oauth/hooks/afterLogout.js.map +0 -1
  381. package/dist/oauth/hooks/me.d.ts.map +0 -1
  382. package/dist/oauth/hooks/me.js.map +0 -1
  383. package/dist/oauth/hooks/refresh.d.ts.map +0 -1
  384. package/dist/oauth/hooks/refresh.js.map +0 -1
  385. package/dist/oauth/index.d.ts.map +0 -1
  386. package/dist/oauth/index.js.map +0 -1
  387. package/dist/oauth/strategy/index.d.ts.map +0 -1
  388. package/dist/oauth/strategy/index.js.map +0 -1
  389. package/dist/oauth/types.d.ts.map +0 -1
  390. package/dist/oauth/types.js.map +0 -1
  391. package/dist/oauth/utilities/clearCookie.d.ts.map +0 -1
  392. package/dist/oauth/utilities/clearCookie.js.map +0 -1
  393. package/dist/oauth/utilities/createCookieOptions.d.ts.map +0 -1
  394. package/dist/oauth/utilities/createCookieOptions.js.map +0 -1
  395. package/dist/oauth/utilities/createDebugLogger.d.ts.map +0 -1
  396. package/dist/oauth/utilities/createDebugLogger.js.map +0 -1
  397. package/dist/oauth/utilities/extractOrigin.d.ts.map +0 -1
  398. package/dist/oauth/utilities/extractOrigin.js.map +0 -1
  399. package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +0 -1
  400. package/dist/oauth/utilities/getAdminCollectionSlug.js.map +0 -1
  401. package/dist/oauth/utilities/getAdminPath.d.ts +0 -8
  402. package/dist/oauth/utilities/getAdminPath.d.ts.map +0 -1
  403. package/dist/oauth/utilities/getAdminPath.js +0 -9
  404. package/dist/oauth/utilities/getAdminPath.js.map +0 -1
  405. package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +0 -1
  406. package/dist/oauth/utilities/getAuthorizeURL.js.map +0 -1
  407. package/dist/oauth/utilities/getCookieExpiration.d.ts.map +0 -1
  408. package/dist/oauth/utilities/getCookieExpiration.js.map +0 -1
  409. package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +0 -1
  410. package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +0 -1
  411. package/dist/oauth/utilities/getTokenExp.d.ts.map +0 -1
  412. package/dist/oauth/utilities/getTokenExp.js.map +0 -1
  413. package/dist/oauth/utilities/getUsernameField.d.ts.map +0 -1
  414. package/dist/oauth/utilities/getUsernameField.js.map +0 -1
  415. package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +0 -1
  416. package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +0 -1
  417. package/dist/oauth/utilities/mergeHeaders.d.ts.map +0 -1
  418. package/dist/oauth/utilities/mergeHeaders.js.map +0 -1
  419. package/dist/oauth/utilities/refreshTokens.d.ts.map +0 -1
  420. package/dist/oauth/utilities/refreshTokens.js.map +0 -1
  421. package/dist/plugin/adapter.d.ts.map +0 -1
  422. package/dist/plugin/adapter.js.map +0 -1
  423. package/dist/plugin/build-config.d.ts.map +0 -1
  424. package/dist/plugin/build-config.js.map +0 -1
  425. package/dist/types/config.d.ts.map +0 -1
  426. package/dist/types/config.js.map +0 -1
  427. package/dist/types.d.ts.map +0 -1
  428. package/dist/types.js.map +0 -1
  429. package/dist/utils/asset-collection.d.ts.map +0 -1
  430. package/dist/utils/asset-collection.js.map +0 -1
  431. package/dist/utils/build-detection.d.ts.map +0 -1
  432. package/dist/utils/build-detection.js.map +0 -1
  433. package/dist/utils/config.d.ts.map +0 -1
  434. package/dist/utils/config.js.map +0 -1
  435. package/dist/utils/download-template.d.ts.map +0 -1
  436. package/dist/utils/download-template.js.map +0 -1
  437. package/dist/utils/env-management.d.ts.map +0 -1
  438. package/dist/utils/env-management.js.map +0 -1
  439. package/dist/utils/format.d.ts.map +0 -1
  440. package/dist/utils/format.js.map +0 -1
  441. package/dist/utils/formatter.d.ts.map +0 -1
  442. package/dist/utils/formatter.js.map +0 -1
  443. package/dist/utils/git.d.ts.map +0 -1
  444. package/dist/utils/git.js.map +0 -1
  445. package/dist/utils/is-debug.d.ts.map +0 -1
  446. package/dist/utils/is-debug.js.map +0 -1
  447. package/dist/utils/lambda-config.d.ts.map +0 -1
  448. package/dist/utils/lambda-config.js.map +0 -1
  449. package/dist/utils/log.d.ts.map +0 -1
  450. package/dist/utils/log.js.map +0 -1
  451. package/dist/utils/messages.d.ts.map +0 -1
  452. package/dist/utils/messages.js.map +0 -1
  453. package/dist/utils/package-manager.d.ts.map +0 -1
  454. package/dist/utils/package-manager.js.map +0 -1
  455. package/dist/utils/payload-config-ast.d.ts.map +0 -1
  456. package/dist/utils/payload-config-ast.js.map +0 -1
  457. package/dist/utils/payload-config-finder.d.ts.map +0 -1
  458. package/dist/utils/payload-config-finder.js.map +0 -1
  459. package/dist/utils/payload-config-modifier.d.ts.map +0 -1
  460. package/dist/utils/payload-config-modifier.js.map +0 -1
  461. package/dist/utils/payload-package-check.d.ts.map +0 -1
  462. package/dist/utils/payload-package-check.js.map +0 -1
  463. package/dist/utils/project.d.ts.map +0 -1
  464. package/dist/utils/project.js.map +0 -1
  465. package/dist/utils/s3-upload.d.ts.map +0 -1
  466. package/dist/utils/s3-upload.js.map +0 -1
  467. package/dist/utils/token-display.d.ts.map +0 -1
  468. package/dist/utils/token-display.js.map +0 -1
  469. package/dist/utils/typescript-validator.d.ts.map +0 -1
  470. package/dist/utils/typescript-validator.js.map +0 -1
@@ -0,0 +1,938 @@
1
+ import createClient from 'openapi-fetch';
2
+ import { APIError, createDatabaseAdapter } from 'payload';
3
+ import { v4 as uuid } from 'uuid';
4
+ import { FigmaApiError } from '../api/figma-api.js';
5
+ import { CONTENT_SYSTEM_NOT_FOUND_MESSAGE } from '../constants.js';
6
+ import { getGlobalSlug } from './temp-utilities/slug.js';
7
+ import { addFallbackSort } from './temp-utilities/sorting.js';
8
+ import { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js';
9
+ import { createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js';
10
+ import { dataToContentAPI, resolveVersionContent } from './utilities/data/index.js';
11
+ import { validateRelationshipIds } from './utilities/data/validateRelationships.js';
12
+ import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
13
+ import { addFallbackLocale } from './utilities/locale/index.js';
14
+ import { buildMeta } from './utilities/meta/buildMeta.js';
15
+ import { normalizeLocaleInWhere } from './utilities/meta/normalizeLocaleInWhere.js';
16
+ import { convertPayloadWhereToContentAPI } from './utilities/where.js';
17
+ /**
18
+ * Heads-up logged locally whenever a job is queued. Queued jobs are executed by Figma's deployed runner, so
19
+ * if a deployed environment exists its runner can pick up anything in the queue. The developer
20
+ * needs to know that a job they just created locally may run on their deployed app instead of their machine.
21
+ */ export const LOCAL_JOB_QUEUE_NOTICE = "A job was queued locally. Queued jobs may be run by Figma's deployed runner, not your local " + 'dev server. If this app has a deployed environment, your deployed app may pick this ' + 'job up and run it against deployed code. If this app has no deployed ' + 'environment, the job will not run automatically. To test job logic against your local ' + 'code, call the function your task runs directly instead of queueing a job. ';
22
+ /**
23
+ * Logs {@link LOCAL_JOB_QUEUE_NOTICE} for every job queued locally: if a deployed
24
+ * environment exists, its runner can pick up anything in the queue. No-op when
25
+ * `notifyLocalJobQueue` is false (i.e. not a local runtime).
26
+ */ export function maybeNotifyLocalJobQueue(adapter, args) {
27
+ if (!adapter.notifyLocalJobQueue) {
28
+ return;
29
+ }
30
+ if (args.collection !== 'payload-jobs') {
31
+ return;
32
+ }
33
+ adapter.payload.logger.warn(LOCAL_JOB_QUEUE_NOTICE);
34
+ }
35
+ async function syncCollections() {
36
+ let existingIds;
37
+ try {
38
+ const { data: response, error, response: httpResponse } = await this.client.GET('/api/v0/content_systems/{contentSystemId}/collections', {
39
+ params: {
40
+ path: {
41
+ contentSystemId: this.contentSystemId
42
+ }
43
+ }
44
+ });
45
+ if (httpResponse.status === 404 || httpResponse.status === 410) {
46
+ throw new Error(CONTENT_SYSTEM_NOT_FOUND_MESSAGE);
47
+ }
48
+ if (error) {
49
+ throw createContentAPIError('syncCollections', error, httpResponse.status);
50
+ }
51
+ if (!response) {
52
+ throw new Error('No response from collections endpoint');
53
+ }
54
+ existingIds = new Set(response.data.map((c)=>c.id));
55
+ this.payload.logger.info(`Found ${existingIds.size} existing collections`);
56
+ } catch (error) {
57
+ if (error instanceof Error && error.message === CONTENT_SYSTEM_NOT_FOUND_MESSAGE) {
58
+ throw error;
59
+ }
60
+ if (error instanceof FigmaApiError && (error.statusCode === 404 || error.statusCode === 410)) {
61
+ throw new Error(CONTENT_SYSTEM_NOT_FOUND_MESSAGE);
62
+ }
63
+ this.payload.logger.warn(`Failed to fetch collections, will attempt to create all: ${error.message}`);
64
+ existingIds = new Set();
65
+ }
66
+ for (const collection of this.payload.config.collections){
67
+ if (!existingIds.has(collection.slug)) {
68
+ await createCollection.call(this, collection.slug);
69
+ }
70
+ }
71
+ for (const global of this.payload.config.globals || []){
72
+ const globalId = `_global-${global.slug}`;
73
+ if (!existingIds.has(globalId)) {
74
+ await createCollection.call(this, globalId);
75
+ }
76
+ }
77
+ }
78
+ function init() {
79
+ if (this.auth.mode === 'apiKey') {
80
+ this.payload.logger.info('Using API Key authentication');
81
+ } else if (this.auth.mode === 'tokenStore') {
82
+ this.payload.logger.info('Using TokenStore authentication (local dev)');
83
+ } else {
84
+ this.payload.logger.info('Using Dev JWT authentication (testing)');
85
+ }
86
+ }
87
+ // connect is called after init — once on first startup (hotReload=false) and again on HMR
88
+ // (hotReload=true). Only clear the database on the first startup, never on hot reload.
89
+ async function connect(args) {
90
+ const hotReload = args?.hotReload ?? false;
91
+ if (!hotReload && process.env.PAYLOAD_DROP_DATABASE === 'true') {
92
+ // clearDatabase already calls syncCollections internally after clearing
93
+ await this.clearDatabase();
94
+ return;
95
+ }
96
+ await syncCollections.call(this);
97
+ }
98
+ async function createCollection(collectionId) {
99
+ try {
100
+ const { error, response: httpResponse } = await this.client.POST('/api/v0/content_systems/{contentSystemId}/collections', {
101
+ body: {
102
+ id: collectionId
103
+ },
104
+ params: {
105
+ path: {
106
+ contentSystemId: this.contentSystemId
107
+ }
108
+ }
109
+ });
110
+ if (error) {
111
+ throw createContentAPIError('createCollection', error, httpResponse.status);
112
+ }
113
+ this.payload.logger.info(`Created collection: ${collectionId}`);
114
+ } catch (error) {
115
+ const errorMessage = error.message;
116
+ if (!errorMessage.includes('already exists') && !errorMessage.includes('409')) {
117
+ this.payload.logger.warn(`Failed to create collection ${collectionId}: ${errorMessage}`);
118
+ }
119
+ }
120
+ }
121
+ async function findMany({ collection, joins, limit, locale: localeArg, page, pagination: _pagination, sort, where }) {
122
+ const locale = addFallbackLocale(localeArg, this.payload);
123
+ const normalizedWhere = normalizeLocaleInWhere(where, this.payload, collection, locale);
124
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:find', {
125
+ body: {
126
+ collection,
127
+ contentSystemId: this.contentSystemId,
128
+ join: convertPayloadJoinsToContentAPI(this.payload, collection, joins, locale),
129
+ limit,
130
+ locale,
131
+ page: page ?? 1,
132
+ sort: addFallbackSort(sort, this.payload, collection),
133
+ where: convertPayloadWhereToContentAPI(normalizedWhere ?? {}),
134
+ ...buildMeta(this.payload, {
135
+ collection,
136
+ locale,
137
+ where: normalizedWhere
138
+ })
139
+ }
140
+ });
141
+ if (error) {
142
+ throw createContentAPIError('findMany', error, httpResponse.status);
143
+ }
144
+ if (!response) {
145
+ throw new Error('No response from findMany');
146
+ }
147
+ return unwrapFindResponse(this.payload, response.result, collection, localeArg);
148
+ }
149
+ async function find(args) {
150
+ const collectionConfig = this.payload.config.collections.find((c)=>c.slug === args.collection);
151
+ return findMany.call(this, {
152
+ collection: args.collection,
153
+ joins: args.joins,
154
+ // TODO: FindArgs.limit should be 'number' not 'number | undefined'
155
+ // Payload Core sanitizes limit before calling the adapter when going through findOperation
156
+ // (defaults to 10 or 0 based on pagination), but some callers (e.g. deleteOperation) call
157
+ // db.find() directly without a limit. Default to 0 (unlimited) to avoid the Content API
158
+ // falling back to its own default of 10.
159
+ limit: args.limit ?? 0,
160
+ locale: args.locale,
161
+ page: args.page ?? 1,
162
+ pagination: args.pagination,
163
+ sort: args.sort || collectionConfig?.defaultSort,
164
+ where: args.where
165
+ });
166
+ }
167
+ // TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183
168
+ async function findVersions(args) {
169
+ const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
170
+ const whereClause = convertPayloadWhereToContentAPI(args.where ?? {}, {
171
+ parentToDocumentId: true,
172
+ stripVersionPrefix: true
173
+ });
174
+ const locale = addFallbackLocale(args.locale, this.payload);
175
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:find', {
176
+ body: {
177
+ collection: args.collection,
178
+ contentSystemId: this.contentSystemId,
179
+ // TODO: FindVersionsArgs.limit should be 'number' not 'number | undefined'
180
+ // is sanitized by Payload Core before calling the adapter (defaults to 10 or 0 based on pagination)
181
+ limit: args.limit,
182
+ locale,
183
+ page: args.page ?? 1,
184
+ sort: sortWithFallback,
185
+ where: whereClause,
186
+ ...buildMeta(this.payload, {
187
+ collection: args.collection,
188
+ locale,
189
+ where: args.where
190
+ })
191
+ }
192
+ });
193
+ if (error) {
194
+ throw createContentAPIError('findVersions', error, httpResponse.status);
195
+ }
196
+ if (!response) {
197
+ throw new Error('No response from findVersions');
198
+ }
199
+ return unwrapFindResponse(this.payload, response.result, args.collection, args.locale);
200
+ }
201
+ async function queryDrafts(args) {
202
+ const versionsResult = await this.findVersions({
203
+ collection: args.collection,
204
+ limit: args.limit,
205
+ locale: args.locale,
206
+ page: args.page,
207
+ pagination: args.pagination,
208
+ sort: args.sort,
209
+ where: {
210
+ ...args.where,
211
+ latest: {
212
+ equals: true
213
+ }
214
+ }
215
+ });
216
+ // queryDrafts returns documents at root level, not nested in 'version'.
217
+ // Only spread version content; version metadata (latest, parent) must not leak.
218
+ const docs = versionsResult.docs.map((versionDoc)=>({
219
+ ...versionDoc.version,
220
+ id: versionDoc.parent
221
+ }));
222
+ return {
223
+ ...versionsResult,
224
+ docs
225
+ };
226
+ }
227
+ async function createVersion(args) {
228
+ const versionContent = dataToContentAPI(this.payload, args.collectionSlug, args.versionData, {
229
+ applyDefaults: true,
230
+ publishedLocale: args.publishedLocale
231
+ });
232
+ if (args.autosave) {
233
+ versionContent._payloadAutosave = true;
234
+ }
235
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:create', {
236
+ body: {
237
+ collection: args.collectionSlug,
238
+ contentSystemId: this.contentSystemId,
239
+ versionDoc: {
240
+ createdAt: args.createdAt,
241
+ latest: true,
242
+ parent: String(args.parent),
243
+ updatedAt: args.updatedAt,
244
+ version: versionContent
245
+ }
246
+ }
247
+ });
248
+ if (error) {
249
+ throw createContentAPIError('createVersion', error, httpResponse.status);
250
+ }
251
+ if (!response) {
252
+ throw new Error('No response from createVersion');
253
+ }
254
+ return unwrapDocument({
255
+ collectionSlug: args.collectionSlug,
256
+ doc: response.result,
257
+ payload: this.payload
258
+ });
259
+ }
260
+ async function updateVersion(args) {
261
+ const where = args.where ?? {
262
+ id: {
263
+ equals: args.id
264
+ }
265
+ };
266
+ const locale = addFallbackLocale(args.locale, this.payload);
267
+ const { publishedLocale, version, ...versionMeta } = args.versionData;
268
+ const resolvedVersion = resolveVersionContent(version, versionMeta);
269
+ const versionContent = dataToContentAPI(this.payload, args.collection, resolvedVersion, {
270
+ publishedLocale
271
+ });
272
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:update', {
273
+ body: {
274
+ collection: args.collection,
275
+ contentSystemId: this.contentSystemId,
276
+ createOnMissing: false,
277
+ locale,
278
+ versionDoc: {
279
+ createdAt: versionMeta.createdAt,
280
+ latest: versionMeta.latest,
281
+ parent: versionMeta.parent != null ? String(versionMeta.parent) : undefined,
282
+ updatedAt: versionMeta.updatedAt,
283
+ version: versionContent
284
+ },
285
+ where: convertPayloadWhereToContentAPI(where, {
286
+ stripVersionPrefix: true
287
+ }),
288
+ ...buildMeta(this.payload, {
289
+ collection: args.collection,
290
+ locale,
291
+ where
292
+ })
293
+ }
294
+ });
295
+ if (error) {
296
+ throw createContentAPIError('updateVersion', error, httpResponse.status);
297
+ }
298
+ if (!response?.result || !('data' in response.result)) {
299
+ throw new Error('No document data in updateVersion response');
300
+ }
301
+ const doc = response.result.data[0];
302
+ if (!doc) {
303
+ return null;
304
+ }
305
+ return unwrapDocument({
306
+ collectionSlug: args.collection,
307
+ doc,
308
+ locale: args.locale,
309
+ payload: this.payload
310
+ });
311
+ }
312
+ async function deleteVersions(args) {
313
+ if (!args.collection) {
314
+ throw new Error('deleteVersions requires a collection');
315
+ }
316
+ const locale = addFallbackLocale(args.locale, this.payload);
317
+ const { error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:delete', {
318
+ body: {
319
+ collection: args.collection,
320
+ contentSystemId: this.contentSystemId,
321
+ locale,
322
+ where: convertPayloadWhereToContentAPI(args.where, {
323
+ stripVersionPrefix: true
324
+ }),
325
+ ...buildMeta(this.payload, {
326
+ collection: args.collection,
327
+ locale,
328
+ where: args.where
329
+ })
330
+ }
331
+ });
332
+ if (error) {
333
+ throw createContentAPIError('deleteVersions', error, httpResponse.status);
334
+ }
335
+ }
336
+ async function findOne(args) {
337
+ const { docs } = await this.find({
338
+ collection: args.collection,
339
+ joins: args.joins,
340
+ limit: 1,
341
+ locale: args.locale,
342
+ pagination: false,
343
+ where: args.where
344
+ });
345
+ return docs[0] ?? null;
346
+ }
347
+ async function findDistinct(args) {
348
+ const locale = addFallbackLocale(args.locale, this.payload);
349
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:findDistinct', {
350
+ body: {
351
+ collection: args.collection,
352
+ contentSystemId: this.contentSystemId,
353
+ distinctBy: args.field,
354
+ limit: args.limit,
355
+ locale,
356
+ page: args.page ?? 1,
357
+ sort: addFallbackSort(args.sort, this.payload, args.collection),
358
+ where: convertPayloadWhereToContentAPI(args.where ?? {}),
359
+ ...buildMeta(this.payload, {
360
+ collection: args.collection,
361
+ locale,
362
+ where: args.where
363
+ })
364
+ }
365
+ });
366
+ if (error) {
367
+ throw createContentAPIError('findDistinct', error, httpResponse.status);
368
+ }
369
+ const { data, ...pagination } = response.result;
370
+ return {
371
+ ...pagination,
372
+ // Content API returns flat values; Payload expects objects keyed by field name.
373
+ values: data.map((value)=>({
374
+ [args.field]: value
375
+ }))
376
+ };
377
+ }
378
+ async function updateMany(args) {
379
+ const locale = addFallbackLocale(args.locale, this.payload);
380
+ validateRelationshipIds({
381
+ collectionSlug: args.collection,
382
+ data: args.data,
383
+ payload: this.payload
384
+ });
385
+ const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v0/documents:update', {
386
+ body: {
387
+ collection: args.collection,
388
+ contentSystemId: this.contentSystemId,
389
+ createOnMissing: false,
390
+ doc: dataToContentAPI(this.payload, args.collection, args.data),
391
+ environmentName: this.environmentName,
392
+ limit: args.limit,
393
+ locale,
394
+ returning: {},
395
+ sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),
396
+ where: convertPayloadWhereToContentAPI(args.where),
397
+ ...buildMeta(this.payload, {
398
+ collection: args.collection,
399
+ locale,
400
+ where: args.where
401
+ })
402
+ }
403
+ });
404
+ if (error) {
405
+ throw createContentAPIError('updateMany', error, httpResponse.status);
406
+ }
407
+ if (!contentAPIResponse) {
408
+ throw new Error('No response from updateMany');
409
+ }
410
+ if (contentAPIResponse.result && 'data' in contentAPIResponse.result) {
411
+ return contentAPIResponse.result.data.map((doc)=>unwrapDocument({
412
+ collectionSlug: args.collection,
413
+ doc,
414
+ locale: args.locale,
415
+ payload: this.payload
416
+ }));
417
+ }
418
+ return null;
419
+ }
420
+ async function updateOne(args) {
421
+ const locale = addFallbackLocale(args.locale, this.payload);
422
+ const where = args.where ?? {
423
+ id: {
424
+ equals: args.id
425
+ }
426
+ };
427
+ validateRelationshipIds({
428
+ collectionSlug: args.collection,
429
+ data: args.data,
430
+ payload: this.payload
431
+ });
432
+ const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v0/documents:update', {
433
+ body: {
434
+ collection: args.collection,
435
+ contentSystemId: this.contentSystemId,
436
+ createOnMissing: false,
437
+ doc: dataToContentAPI(this.payload, args.collection, args.data),
438
+ environmentName: this.environmentName,
439
+ locale,
440
+ returning: {},
441
+ where: convertPayloadWhereToContentAPI(where),
442
+ ...buildMeta(this.payload, {
443
+ collection: args.collection,
444
+ locale,
445
+ where
446
+ })
447
+ }
448
+ });
449
+ if (error) {
450
+ throw createContentAPIError('updateOne', error, httpResponse.status);
451
+ }
452
+ if (!contentAPIResponse) {
453
+ throw new Error('No response from updateOne');
454
+ }
455
+ if (!contentAPIResponse.result || !('data' in contentAPIResponse.result)) {
456
+ throw new Error('Unexpected response format from updateOne');
457
+ }
458
+ const doc = contentAPIResponse.result.data[0];
459
+ if (!doc) {
460
+ return null;
461
+ }
462
+ return unwrapDocument({
463
+ collectionSlug: args.collection,
464
+ doc,
465
+ locale: args.locale,
466
+ payload: this.payload
467
+ });
468
+ }
469
+ async function deleteMany(args) {
470
+ const locale = addFallbackLocale(args.req?.locale, this.payload);
471
+ const { error, response: httpResponse } = await this.client.POST('/api/v0/documents:delete', {
472
+ body: {
473
+ collection: args.collection,
474
+ contentSystemId: this.contentSystemId,
475
+ environmentName: this.environmentName,
476
+ locale,
477
+ where: convertPayloadWhereToContentAPI(args.where),
478
+ ...buildMeta(this.payload, {
479
+ collection: args.collection,
480
+ locale,
481
+ where: args.where
482
+ })
483
+ }
484
+ });
485
+ if (error) {
486
+ throw createContentAPIError('deleteMany', error, httpResponse.status);
487
+ }
488
+ }
489
+ async function deleteOne(args) {
490
+ const locale = addFallbackLocale(args.req?.locale, this.payload);
491
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:delete', {
492
+ body: {
493
+ collection: args.collection,
494
+ contentSystemId: this.contentSystemId,
495
+ environmentName: this.environmentName,
496
+ locale,
497
+ returning: {},
498
+ where: convertPayloadWhereToContentAPI(args.where),
499
+ ...buildMeta(this.payload, {
500
+ collection: args.collection,
501
+ locale,
502
+ where: args.where
503
+ })
504
+ }
505
+ });
506
+ if (error) {
507
+ throw createContentAPIError('deleteOne', error, httpResponse.status);
508
+ }
509
+ if (!response?.result || !('data' in response.result)) {
510
+ throw new Error('No document data in deleteOne response');
511
+ }
512
+ const doc = response.result.data[0];
513
+ if (!doc) {
514
+ return null;
515
+ }
516
+ return unwrapDocument({
517
+ collectionSlug: args.collection,
518
+ doc,
519
+ locale: args.req?.locale === null ? undefined : args.req?.locale,
520
+ payload: this.payload
521
+ });
522
+ }
523
+ async function create(args) {
524
+ const isGlobalCollection = args.collection.startsWith('_global-');
525
+ const customIDType = this.payload.collections[args.collection]?.customIDType;
526
+ // See test: "should allow creating docs with payload.db.create with custom ID".
527
+ // TODO: customID is not yet in our installed types. Remove this when it is.
528
+ // When provided (e.g. from payload.db.create), it takes priority over data.id.
529
+ const customID = args.customID;
530
+ let id;
531
+ if (customID != null) {
532
+ id = String(customID);
533
+ } else if ((isGlobalCollection || customIDType || this.allowIDOnCreate) && args.data.id != null && (typeof args.data.id === 'string' || typeof args.data.id === 'number')) {
534
+ id = String(args.data.id);
535
+ } else {
536
+ id = uuid();
537
+ }
538
+ const locale = addFallbackLocale(args.locale, this.payload);
539
+ validateRelationshipIds({
540
+ collectionSlug: args.collection,
541
+ data: args.data,
542
+ payload: this.payload
543
+ });
544
+ const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v0/documents:create', {
545
+ body: {
546
+ collection: args.collection,
547
+ contentSystemId: this.contentSystemId,
548
+ doc: {
549
+ ...dataToContentAPI(this.payload, args.collection, args.data, {
550
+ applyDefaults: true,
551
+ createdAt: true
552
+ }),
553
+ id
554
+ },
555
+ environmentName: this.environmentName,
556
+ locale,
557
+ ...buildMeta(this.payload, {
558
+ collection: args.collection,
559
+ data: args.data,
560
+ locale
561
+ })
562
+ }
563
+ });
564
+ if (error) {
565
+ throw createContentAPIError('create', error, httpResponse.status);
566
+ }
567
+ if (!contentAPIResponse) {
568
+ throw new Error('No response from create');
569
+ }
570
+ maybeNotifyLocalJobQueue(this, args);
571
+ return unwrapDocument({
572
+ collectionSlug: args.collection,
573
+ doc: contentAPIResponse.result,
574
+ locale: args.locale,
575
+ payload: this.payload
576
+ });
577
+ }
578
+ async function clearDatabase() {
579
+ this.payload.logger.info(`---- CLEARING CONTENT API DATABASE ----`);
580
+ try {
581
+ const response = await fetch(getClearDatabaseUrl(this.url, process.env.FIGMA_CONTENT_API_CUTOVER_STATE), {
582
+ headers: {
583
+ 'Content-Type': 'application/json'
584
+ },
585
+ method: 'POST'
586
+ });
587
+ if (!response.ok) {
588
+ throw new Error(`Content API database reset failed: ${response.status} ${response.statusText}`);
589
+ }
590
+ this.payload.logger.info('---- CONTENT API DATABASE CLEARED ----');
591
+ // Re-sync collections after clearing
592
+ await syncCollections.call(this);
593
+ } catch (error) {
594
+ this.payload.logger.error(`Failed to clear database: ${error.message}`);
595
+ throw error;
596
+ }
597
+ }
598
+ export function getClearDatabaseUrl(url, cutoverState) {
599
+ const clearDatabaseUrl = new URL('/dev/clear-db', url);
600
+ if (cutoverState != null) {
601
+ clearDatabaseUrl.searchParams.set('cutoverState', cutoverState);
602
+ }
603
+ return clearDatabaseUrl.toString();
604
+ }
605
+ async function count(args) {
606
+ const locale = addFallbackLocale(args.locale, this.payload);
607
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:count', {
608
+ body: {
609
+ collection: args.collection,
610
+ contentSystemId: this.contentSystemId,
611
+ locale,
612
+ where: convertPayloadWhereToContentAPI(args.where),
613
+ ...buildMeta(this.payload, {
614
+ collection: args.collection,
615
+ locale,
616
+ where: args.where
617
+ })
618
+ }
619
+ });
620
+ if (error) {
621
+ throw createContentAPIError('count', error, httpResponse.status);
622
+ }
623
+ if (!response) {
624
+ throw new Error('No response from count');
625
+ }
626
+ return {
627
+ totalDocs: response.result.count
628
+ };
629
+ }
630
+ async function countVersions(args) {
631
+ const locale = addFallbackLocale(args.locale, this.payload);
632
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:count', {
633
+ body: {
634
+ collection: args.collection,
635
+ contentSystemId: this.contentSystemId,
636
+ locale,
637
+ where: convertPayloadWhereToContentAPI(args.where, {
638
+ parentToDocumentId: true,
639
+ stripVersionPrefix: true
640
+ }),
641
+ ...buildMeta(this.payload, {
642
+ collection: args.collection,
643
+ locale,
644
+ where: args.where
645
+ })
646
+ }
647
+ });
648
+ if (error) {
649
+ throw createContentAPIError('countVersions', error, httpResponse.status);
650
+ }
651
+ if (!response) {
652
+ throw new Error('No response from countVersions');
653
+ }
654
+ return {
655
+ totalDocs: response.result.count
656
+ };
657
+ }
658
+ async function upsert(args) {
659
+ let documentId = args.data.id;
660
+ if (!documentId && args.where && 'id' in args.where) {
661
+ const idClause = args.where.id;
662
+ if (idClause && 'equals' in idClause) {
663
+ documentId = idClause.equals;
664
+ }
665
+ }
666
+ if (!documentId) {
667
+ documentId = uuid();
668
+ }
669
+ const locale = addFallbackLocale(args.locale, this.payload);
670
+ validateRelationshipIds({
671
+ collectionSlug: args.collection,
672
+ data: args.data,
673
+ payload: this.payload
674
+ });
675
+ const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v0/documents:update', {
676
+ body: {
677
+ collection: args.collection,
678
+ contentSystemId: this.contentSystemId,
679
+ createOnMissing: {
680
+ id: documentId
681
+ },
682
+ doc: dataToContentAPI(this.payload, args.collection, args.data, {
683
+ applyDefaults: true,
684
+ createdAt: true
685
+ }),
686
+ environmentName: this.environmentName,
687
+ locale,
688
+ where: convertPayloadWhereToContentAPI(args.where),
689
+ ...buildMeta(this.payload, {
690
+ collection: args.collection,
691
+ data: args.data,
692
+ locale,
693
+ where: args.where
694
+ })
695
+ }
696
+ });
697
+ if (error) {
698
+ throw createContentAPIError('upsert', error, httpResponse.status);
699
+ }
700
+ if (!contentAPIResponse) {
701
+ throw new Error('No response from upsert');
702
+ }
703
+ if (!contentAPIResponse.result || !('data' in contentAPIResponse.result)) {
704
+ throw new Error('Unexpected response format from upsert');
705
+ }
706
+ const doc = contentAPIResponse.result.data[0];
707
+ if (!doc) {
708
+ throw new Error('No document data in upsert response');
709
+ }
710
+ return unwrapDocument({
711
+ collectionSlug: args.collection,
712
+ doc,
713
+ locale: args.locale,
714
+ payload: this.payload
715
+ });
716
+ }
717
+ async function updateJobs(args) {
718
+ const { id, limit, returning, sort, where } = args;
719
+ if (id == null && where == null) {
720
+ throw new Error('updateJobs requires either id or a where clause');
721
+ }
722
+ // Copy data to avoid mutating the caller's object.
723
+ const data = {
724
+ ...args.data
725
+ };
726
+ // Strip log if empty/absent. The content API's deep merge replaces arrays entirely
727
+ // (it does not concatenate), so sending log: [] would wipe existing log entries.
728
+ // Only include log when it carries new content: a non-empty array or a $push operation.
729
+ const log = data.log;
730
+ if (!(Array.isArray(log) && log.length > 0) && !(log && typeof log === 'object' && '$push' in log)) {
731
+ delete data.log;
732
+ }
733
+ const whereClause = id != null ? {
734
+ id: {
735
+ equals: String(id)
736
+ }
737
+ } : where;
738
+ const docData = dataToContentAPI(this.payload, 'payload-jobs', data);
739
+ const sortClause = addFallbackSort(sort || '-updatedAt', this.payload, 'payload-jobs');
740
+ const whereQuery = convertPayloadWhereToContentAPI(whereClause);
741
+ const meta = buildMeta(this.payload, {
742
+ collection: 'payload-jobs',
743
+ locale: undefined,
744
+ where: whereClause
745
+ });
746
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:update', {
747
+ body: {
748
+ collection: 'payload-jobs',
749
+ contentSystemId: this.contentSystemId,
750
+ createOnMissing: false,
751
+ doc: docData,
752
+ environmentName: this.environmentName,
753
+ ...limit != null && {
754
+ limit
755
+ },
756
+ returning: {},
757
+ sort: sortClause,
758
+ where: whereQuery,
759
+ ...meta
760
+ }
761
+ });
762
+ if (error) {
763
+ throw createContentAPIError('updateJobs', error, httpResponse.status);
764
+ }
765
+ if (!response) {
766
+ throw new Error('No response from updateJobs');
767
+ }
768
+ if (returning === false) {
769
+ return null;
770
+ }
771
+ if (!response.result || !('data' in response.result)) {
772
+ return [];
773
+ }
774
+ return response.result.data.map((doc)=>unwrapDocument({
775
+ collectionSlug: 'payload-jobs',
776
+ doc,
777
+ payload: this.payload
778
+ }));
779
+ }
780
+ function createGlobal(args) {
781
+ // Globals are singletons identified by their slug. Use upsert so concurrent calls
782
+ // (e.g. handleSchedules processing multiple queueables with the same null jobStats)
783
+ // don't fail with "A record with this field already exists". The deep-merge semantics
784
+ // of the update path are safe here: callers that want a fresh create (first run) get
785
+ // an effective create, and callers that race a prior create get a merge instead.
786
+ return this.upsert({
787
+ collection: getGlobalSlug(args.slug),
788
+ data: {
789
+ ...args.data,
790
+ id: args.slug,
791
+ globalType: args.slug
792
+ },
793
+ where: {
794
+ id: {
795
+ equals: args.slug
796
+ }
797
+ }
798
+ });
799
+ }
800
+ function findGlobal(args) {
801
+ return this.findOne({
802
+ collection: getGlobalSlug(args.slug),
803
+ locale: args.locale,
804
+ where: args.where ?? {}
805
+ });
806
+ }
807
+ async function updateGlobal(args) {
808
+ // TODO: upsert's `createOnMissing` path generates a new `createdAt` on every call,
809
+ // which overwrites the original timestamp on updates. The fix belongs in the Content API:
810
+ // `createOnMissing` should preserve `createdAt` on updates and only set it on creates.
811
+ return this.upsert({
812
+ collection: getGlobalSlug(args.slug),
813
+ data: args.data,
814
+ where: {
815
+ id: {
816
+ equals: args.slug
817
+ }
818
+ }
819
+ });
820
+ }
821
+ // TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183
822
+ function findGlobalVersions(args) {
823
+ return this.findVersions({
824
+ collection: getGlobalSlug(args.global),
825
+ limit: args.limit,
826
+ locale: args.locale,
827
+ page: args.page,
828
+ pagination: args.pagination,
829
+ sort: args.sort,
830
+ where: args.where
831
+ });
832
+ }
833
+ function createGlobalVersion(args) {
834
+ // For globals, use the globalSlug as the consistent document ID
835
+ // This matches what we do in updateGlobal
836
+ return this.createVersion({
837
+ autosave: args.autosave,
838
+ collectionSlug: getGlobalSlug(args.globalSlug),
839
+ createdAt: args.createdAt,
840
+ parent: args.globalSlug,
841
+ publishedLocale: args.publishedLocale,
842
+ updatedAt: args.updatedAt,
843
+ versionData: args.versionData
844
+ });
845
+ }
846
+ function updateGlobalVersion(args) {
847
+ // UpdateVersion requires either id OR where, not both
848
+ if (args.id !== undefined) {
849
+ return this.updateVersion({
850
+ id: args.id,
851
+ collection: getGlobalSlug(args.global),
852
+ locale: args.locale,
853
+ versionData: args.versionData
854
+ });
855
+ }
856
+ // args.where is guaranteed by Payload when args.id is undefined
857
+ return this.updateVersion({
858
+ collection: getGlobalSlug(args.global),
859
+ locale: args.locale,
860
+ versionData: args.versionData,
861
+ where: args.where
862
+ });
863
+ }
864
+ function countGlobalVersions(args) {
865
+ return this.countVersions({
866
+ collection: getGlobalSlug(args.global),
867
+ locale: args.locale,
868
+ where: args.where
869
+ });
870
+ }
871
+ function createContentAPIError(operation, error, status) {
872
+ return new APIError(`Content API ${operation} error: ${error.message}`, status, {
873
+ code: error.code,
874
+ constraint: error.constraint,
875
+ field: error.field
876
+ });
877
+ }
878
+ export const contentAPIAdapter = (opts)=>({
879
+ name: 'content-api',
880
+ defaultIDType: 'text',
881
+ init: ({ payload })=>{
882
+ const client = createClient({
883
+ baseUrl: opts.url
884
+ });
885
+ const middlewareOpts = {
886
+ auth: opts.auth,
887
+ contentSystemId: opts.contentSystemId,
888
+ logger: payload.logger,
889
+ url: opts.url
890
+ };
891
+ client.use(createAuthMiddleware(middlewareOpts));
892
+ client.use(createErrorMiddleware(middlewareOpts));
893
+ return createDatabaseAdapter({
894
+ name: 'content-api',
895
+ allowIDOnCreate: opts.allowIDOnCreate ?? false,
896
+ auth: opts.auth,
897
+ beginTransaction: ()=>Promise.resolve(null),
898
+ clearDatabase: clearDatabase,
899
+ client,
900
+ commitTransaction: async ()=>{},
901
+ connect: connect,
902
+ contentSystemId: opts.contentSystemId,
903
+ count: count,
904
+ countGlobalVersions: countGlobalVersions,
905
+ countVersions: countVersions,
906
+ create: create,
907
+ createGlobal: createGlobal,
908
+ createGlobalVersion: createGlobalVersion,
909
+ createVersion: createVersion,
910
+ defaultIDType: 'text',
911
+ deleteMany: deleteMany,
912
+ deleteOne: deleteOne,
913
+ deleteVersions: deleteVersions,
914
+ environmentName: opts.environmentName,
915
+ find: find,
916
+ findDistinct: findDistinct,
917
+ findGlobal: findGlobal,
918
+ findGlobalVersions: findGlobalVersions,
919
+ findOne: findOne,
920
+ findVersions: findVersions,
921
+ idType: 'uuid',
922
+ init,
923
+ notifyLocalJobQueue: opts.notifyLocalJobQueue,
924
+ packageName: '@payloadcms/db-content-api',
925
+ payload,
926
+ queryDrafts: queryDrafts,
927
+ rollbackTransaction: async ()=>{},
928
+ updateGlobal: updateGlobal,
929
+ updateGlobalVersion: updateGlobalVersion,
930
+ updateJobs: updateJobs,
931
+ updateMany: updateMany,
932
+ updateOne: updateOne,
933
+ updateVersion: updateVersion,
934
+ upsert: upsert,
935
+ url: opts.url
936
+ });
937
+ }
938
+ });