@payloadcms/figma 0.0.1-alpha.8 → 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 +381 -18
  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
@@ -1,22 +1,29 @@
1
1
  import * as p from '@clack/prompts';
2
2
  import pc from 'picocolors';
3
- import { executeOAuthFlow, getValidAccessToken, OAuthFlowError } from '../auth/oauth-flow.js';
4
- import { TokenStore } from '../auth/token-store.js';
5
- import { OAUTH_CONFIG } from '../config/oauth.js';
3
+ import { CallbackError } from '../auth/callback-server.js';
4
+ import { executeOAuthFlow, getValidCredential, OAuthFlowError } from '../auth/oauth-flow.js';
5
+ import { getTokenStore } from '../auth/token-store.js';
6
+ import { getOAuthConfig } from '../config/oauth.js';
7
+ import { getInfraEnvironment } from '../constants.js';
8
+ import { formatEnvSuffix } from '../utils/format-env-suffix.js';
6
9
  import * as log from '../utils/log.js';
7
10
  /**
8
11
  * Handle the `@payloadcms/figma login` command
9
12
  *
10
13
  * Authenticates the user with Figma OAuth2 and stores tokens locally.
11
14
  * If valid tokens already exist, shows an error message.
12
- */ export async function loginCommand() {
13
- const tokenStore = new TokenStore();
15
+ */ export async function loginCommand(args) {
16
+ const { showNextSteps } = args || {
17
+ showNextSteps: false
18
+ };
19
+ const env = getInfraEnvironment();
20
+ const tokenStore = getTokenStore(env);
14
21
  // Check for existing valid tokens
15
22
  try {
16
- const existingToken = await getValidAccessToken(tokenStore);
17
- if (existingToken) {
18
- const tokens = tokenStore.getTokens();
19
- p.log.warn(pc.yellow('Already logged in'));
23
+ const existingCredential = await getValidCredential(tokenStore);
24
+ if (existingCredential) {
25
+ const tokens = tokenStore.getOauthInfo();
26
+ p.log.warn(pc.yellow(`Already logged in${formatEnvSuffix(env)}`));
20
27
  if (tokens?.userId) {
21
28
  log.info(`User ID: ${tokens.userId}`);
22
29
  }
@@ -30,28 +37,39 @@ import * as log from '../utils/log.js';
30
37
  }
31
38
  // Start OAuth flow
32
39
  await handleAuthentication({
40
+ showNextSteps,
33
41
  tokenStore
34
42
  });
35
43
  }
36
44
  /**
37
45
  * Handle authentication flow
38
- */ async function handleAuthentication({ tokenStore }) {
46
+ */ async function handleAuthentication({ showNextSteps, tokenStore }) {
39
47
  try {
40
48
  // Execute OAuth flow
49
+ const oauthConfig = getOAuthConfig();
41
50
  const result = await executeOAuthFlow(tokenStore, {
42
- clientId: OAUTH_CONFIG.clientId,
43
- redirectUri: OAUTH_CONFIG.redirectUri,
44
- scopes: OAUTH_CONFIG.scopes
51
+ clientId: oauthConfig.clientId,
52
+ redirectUri: oauthConfig.redirectUri,
53
+ scopes: oauthConfig.scopes
45
54
  });
46
- p.log.success(pc.green('✓ You are now authenticated with Figma'));
55
+ const env = getInfraEnvironment();
56
+ p.log.success(pc.green(`✓ Logged in${formatEnvSuffix(env)}`));
47
57
  if (result.userId) {
48
58
  log.debug(`User ID: ${result.userId}`);
49
59
  }
50
60
  log.debug(`Token storage: ${pc.dim(tokenStore.getStoragePath())}`);
51
- // Show next steps
52
- p.note(` ${pc.cyan('@payloadcms/figma init')} Create a new CMS instance`, 'Next Steps');
61
+ // Show next steps unless disabled
62
+ if (showNextSteps !== false) {
63
+ p.note(` ${pc.cyan('@payloadcms/figma init')} Create a new CMS instance`, 'Next Steps');
64
+ }
53
65
  } catch (error) {
54
66
  if (error instanceof OAuthFlowError) {
67
+ const isTimeout = error.cause instanceof CallbackError && error.cause.code === 'timeout';
68
+ if (isTimeout) {
69
+ p.log.error(pc.red('✗ Authentication timed out.'));
70
+ p.note(`Run ${pc.cyan('@payloadcms/figma login')} to try again.`, 'Tip');
71
+ process.exit(1);
72
+ }
55
73
  log.error(error.message);
56
74
  if (error.cause) {
57
75
  log.debug(`Cause: ${error.cause.message}`);
@@ -62,5 +80,3 @@ import * as log from '../utils/log.js';
62
80
  process.exit(1);
63
81
  }
64
82
  }
65
-
66
- //# sourceMappingURL=login.js.map
@@ -2,15 +2,15 @@
2
2
  * Options for logout command
3
3
  */
4
4
  export interface LogoutCommandOptions {
5
+ /** Logout from all environments */
6
+ all?: boolean;
5
7
  /** Enable debug mode */
6
8
  debug?: boolean;
7
9
  }
8
10
  /**
9
11
  * Handle the `@payloadcms/figma logout` command
10
12
  *
11
- * Clears all stored tokens (OAuth and project tokens) after confirmation.
12
- *
13
- * @param _options - Command options (unused)
13
+ * Clears stored tokens (OAuth and project tokens) after confirmation.
14
+ * By default clears only current environment. Use --all for all environments.
14
15
  */
15
- export declare function logoutCommand(_options?: LogoutCommandOptions): Promise<void>;
16
- //# sourceMappingURL=logout.d.ts.map
16
+ export declare function logoutCommand(options?: LogoutCommandOptions): Promise<void>;
@@ -1,24 +1,37 @@
1
1
  import * as p from '@clack/prompts';
2
2
  import pc from 'picocolors';
3
- import { TokenStore } from '../auth/token-store.js';
3
+ import { getTokenStore } from '../auth/token-store.js';
4
+ import { getInfraEnvironment } from '../constants.js';
5
+ import { getEnvVarSync } from '../utils/env-management.js';
6
+ import { formatEnvSuffix } from '../utils/format-env-suffix.js';
4
7
  import * as log from '../utils/log.js';
8
+ const ALL_ENVIRONMENTS = [
9
+ 'production',
10
+ 'staging'
11
+ ];
5
12
  /**
6
13
  * Handle the `@payloadcms/figma logout` command
7
14
  *
8
- * Clears all stored tokens (OAuth and project tokens) after confirmation.
9
- *
10
- * @param _options - Command options (unused)
11
- */ export async function logoutCommand(_options = {}) {
12
- const tokenStore = new TokenStore();
13
- const hasTokens = tokenStore.getTokens() !== null;
15
+ * Clears stored tokens (OAuth and project tokens) after confirmation.
16
+ * By default clears only current environment. Use --all for all environments.
17
+ */ export async function logoutCommand(options = {}) {
18
+ const currentEnv = getInfraEnvironment();
19
+ if (options.all) {
20
+ await logoutAllEnvironments();
21
+ } else {
22
+ await logoutSingleEnvironment(currentEnv);
23
+ }
24
+ }
25
+ async function logoutSingleEnvironment(env) {
26
+ const tokenStore = getTokenStore(env);
27
+ const hasTokens = tokenStore.getOauthInfo() !== null;
14
28
  if (!hasTokens) {
15
- p.log.warn(pc.yellow('No tokens found. Already logged out.'));
29
+ p.log.warn(pc.yellow(`No tokens found${formatEnvSuffix(env, ' for ')}. Already logged out.`));
16
30
  return;
17
31
  }
18
- // Confirm logout
19
32
  const confirmed = await p.confirm({
20
33
  initialValue: false,
21
- message: 'This will clear all OAuth and project tokens. Continue?'
34
+ message: `This will clear all OAuth and project tokens${formatEnvSuffix(env, ' for ')}. Continue?`
22
35
  });
23
36
  if (p.isCancel(confirmed) || !confirmed) {
24
37
  p.log.info('Logout cancelled');
@@ -27,17 +40,64 @@ import * as log from '../utils/log.js';
27
40
  const s = p.spinner();
28
41
  s.start('Clearing tokens...');
29
42
  try {
30
- // Clear OAuth tokens
31
43
  tokenStore.clearTokens();
32
- // Clear all project tokens
33
- tokenStore.clearAllProjectTokens();
34
- s.stop(pc.green('✓ Logged out successfully'));
35
- p.log.step('All OAuth and project tokens have been cleared');
44
+ clearCurrentProjectToken(tokenStore, env);
45
+ s.stop(pc.green(`✓ Logged out${formatEnvSuffix(env, ' from ')}`));
46
+ } catch (error) {
47
+ s.stop(pc.red(' Failed to clear tokens'));
48
+ log.error(error instanceof Error ? error.message : 'Unknown error');
49
+ process.exit(1);
50
+ }
51
+ }
52
+ async function logoutAllEnvironments() {
53
+ // Check which environments have tokens
54
+ const envsWithTokens = ALL_ENVIRONMENTS.filter((env)=>{
55
+ const store = getTokenStore(env);
56
+ return store.getOauthInfo() !== null;
57
+ });
58
+ if (envsWithTokens.length === 0) {
59
+ p.log.warn(pc.yellow('No tokens found in any environment. Already logged out.'));
60
+ return;
61
+ }
62
+ const envList = envsWithTokens.join(' and ');
63
+ const confirmed = await p.confirm({
64
+ initialValue: false,
65
+ message: `This will clear all OAuth and project tokens for ${envList}. Continue?`
66
+ });
67
+ if (p.isCancel(confirmed) || !confirmed) {
68
+ p.log.info('Logout cancelled');
69
+ return;
70
+ }
71
+ const s = p.spinner();
72
+ s.start('Clearing tokens...');
73
+ try {
74
+ for (const env of envsWithTokens){
75
+ const store = getTokenStore(env);
76
+ store.clearTokens();
77
+ clearCurrentProjectToken(store, env);
78
+ }
79
+ s.stop(pc.green('✓ Logged out from all environments'));
36
80
  } catch (error) {
37
81
  s.stop(pc.red('✗ Failed to clear tokens'));
38
82
  log.error(error instanceof Error ? error.message : 'Unknown error');
39
83
  process.exit(1);
40
84
  }
41
85
  }
42
-
43
- //# sourceMappingURL=logout.js.map
86
+ function clearCurrentProjectToken(store, env) {
87
+ const projectId = getEnvVarSync(process.cwd(), 'FIGMA_PROJECT_ID');
88
+ if (!projectId) {
89
+ return;
90
+ }
91
+ const bootstrapData = store.getBootstrapData(projectId, env);
92
+ if (!bootstrapData?.contentSystemId) {
93
+ return;
94
+ }
95
+ const projectInfo = {
96
+ environmentName: env,
97
+ projectId
98
+ };
99
+ // Clear scoped token for this tenant.
100
+ store.clearProjectToken({
101
+ projectInfo
102
+ });
103
+ }
@@ -0,0 +1,4 @@
1
+ export type UpgradeCommandOptions = {
2
+ isDryRun?: boolean;
3
+ };
4
+ export declare function upgradeCommand(options?: UpgradeCommandOptions): Promise<void>;
@@ -0,0 +1,329 @@
1
+ import * as p from '@clack/prompts';
2
+ import fs from 'fs/promises';
3
+ import path from 'path';
4
+ import pc from 'picocolors';
5
+ import { Project } from 'ts-morph';
6
+ import { fileURLToPath } from 'url';
7
+ import { getBootstrapInfo, getCmsResourceId } from '../api/control-plane.js';
8
+ import { getValidCredential } from '../auth/oauth-flow.js';
9
+ import { getTokenStore } from '../auth/token-store.js';
10
+ import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
11
+ import { addOrUpdateEnvVar, getEnvVar, removeEnvVar } from '../utils/env-management.js';
12
+ import { formatFile } from '../utils/formatter.js';
13
+ import { getPackageManager } from '../utils/package-manager.js';
14
+ import { removeFigmaContentSystemId } from '../utils/payload-config-ast.js';
15
+ import { findPayloadConfig } from '../utils/payload-config-finder.js';
16
+ import { checkPackageInstalled, installPackage } from '../utils/payload-package-check.js';
17
+ import { getOwnVersion } from '../utils/version-check.js';
18
+ export async function upgradeCommand(options = {}) {
19
+ const cwd = process.cwd();
20
+ const { isDryRun = false } = options;
21
+ const changes = [];
22
+ const warnings = [];
23
+ const spinner = p.spinner();
24
+ spinner.start('Checking for needed migrations...');
25
+ spinner.stop('Checking for needed migrations...');
26
+ await migrateEnvRename({
27
+ changes,
28
+ cwd,
29
+ isDryRun
30
+ });
31
+ await migrateProjectId({
32
+ changes,
33
+ cwd,
34
+ isDryRun,
35
+ warnings
36
+ });
37
+ await ensureBootstrapCached({
38
+ changes,
39
+ cwd,
40
+ isDryRun
41
+ });
42
+ await migrateRemoveDeprecatedEnvVars({
43
+ changes,
44
+ cwd,
45
+ isDryRun,
46
+ warnings
47
+ });
48
+ await migrateConfigAst({
49
+ changes,
50
+ cwd,
51
+ isDryRun
52
+ });
53
+ await migratePackageVersion({
54
+ changes,
55
+ cwd,
56
+ isDryRun
57
+ });
58
+ for (const warning of warnings){
59
+ p.log.warning(warning);
60
+ }
61
+ if (changes.length === 0) {
62
+ p.log.success('Everything is up to date.');
63
+ return;
64
+ }
65
+ if (isDryRun) {
66
+ p.log.info(`Dry run: ${changes.length} change(s) detected.`);
67
+ } else {
68
+ p.log.success(`${changes.length} change(s) applied.`);
69
+ }
70
+ }
71
+ const DEPRECATED_ENV_VARS = [
72
+ 'FIGMA_CONTENT_API_CONTENT_SYSTEM_ID',
73
+ 'FIGMA_TENANT_ID',
74
+ 'FIGMA_OAUTH_CLIENT_ID',
75
+ 'FIGMA_OAUTH_CLIENT_SECRET'
76
+ ];
77
+ async function migrateEnvRename({ changes, cwd, isDryRun }) {
78
+ try {
79
+ const oldValue = await getEnvVar(cwd, 'FIGMA_ENV');
80
+ if (oldValue === null) {
81
+ return;
82
+ }
83
+ if (isDryRun) {
84
+ p.log.message(`${pc.dim('○')} Would rename FIGMA_ENV → FIGMA_INFRA_ENV`);
85
+ changes.push('Rename FIGMA_ENV → FIGMA_INFRA_ENV');
86
+ return;
87
+ }
88
+ await addOrUpdateEnvVar(cwd, 'FIGMA_INFRA_ENV', oldValue);
89
+ await removeEnvVar(cwd, 'FIGMA_ENV');
90
+ p.log.message(`${pc.green('●')} Env: Renamed FIGMA_ENV → FIGMA_INFRA_ENV`);
91
+ changes.push('Renamed FIGMA_ENV → FIGMA_INFRA_ENV');
92
+ } catch (error) {
93
+ const msg = error instanceof Error ? error.message : 'Unknown error';
94
+ p.log.warning(`Env rename migration failed: ${msg}`);
95
+ }
96
+ }
97
+ async function migrateProjectId({ changes, cwd, isDryRun, warnings = [] }) {
98
+ try {
99
+ const existingProjectId = await getEnvVar(cwd, 'FIGMA_PROJECT_ID');
100
+ if (existingProjectId) {
101
+ return;
102
+ }
103
+ const oldContentSystemId = await getEnvVar(cwd, 'FIGMA_CONTENT_API_CONTENT_SYSTEM_ID');
104
+ if (!oldContentSystemId) {
105
+ return;
106
+ }
107
+ if (isDryRun) {
108
+ p.log.message(`${pc.dim('○')} Would resolve FIGMA_PROJECT_ID from content system ID`);
109
+ changes.push('Resolve FIGMA_PROJECT_ID from content system ID');
110
+ return;
111
+ }
112
+ const store = getTokenStore();
113
+ const credential = await getValidCredential(store);
114
+ if (!credential) {
115
+ warnings.push('Not authenticated — could not resolve FIGMA_PROJECT_ID. Run `npx @payloadcms/figma login` first.');
116
+ return;
117
+ }
118
+ const cmsResourceId = await getCmsResourceId(credential, oldContentSystemId);
119
+ await addOrUpdateEnvVar(cwd, 'FIGMA_PROJECT_ID', cmsResourceId);
120
+ // Resolve actual environment name from bootstrap API
121
+ try {
122
+ const bootstrapInfo = await getBootstrapInfo(credential, cmsResourceId);
123
+ cacheAllEnvironments(store, cmsResourceId, bootstrapInfo);
124
+ const envName = bootstrapInfo.environments[0]?.name ?? 'production';
125
+ await addOrUpdateEnvVar(cwd, 'FIGMA_ENVIRONMENT_NAME', envName);
126
+ } catch {
127
+ await addOrUpdateEnvVar(cwd, 'FIGMA_ENVIRONMENT_NAME', 'production');
128
+ }
129
+ p.log.message(`${pc.green('●')} Env: Resolved FIGMA_PROJECT_ID from content system ID`);
130
+ changes.push('Resolved FIGMA_PROJECT_ID from content system ID');
131
+ } catch (error) {
132
+ const msg = error instanceof Error ? error.message : 'Unknown error';
133
+ p.log.warning(`Project ID migration failed: ${msg}`);
134
+ }
135
+ }
136
+ async function ensureBootstrapCached(params) {
137
+ try {
138
+ const projectId = await getEnvVar(params.cwd, 'FIGMA_PROJECT_ID');
139
+ if (!projectId) {
140
+ return;
141
+ }
142
+ const environmentName = await getEnvVar(params.cwd, 'FIGMA_ENVIRONMENT_NAME') ?? 'production';
143
+ const store = getTokenStore();
144
+ if (store.getBootstrapData(projectId, environmentName)) {
145
+ return;
146
+ }
147
+ const credential = await getValidCredential(store);
148
+ if (!credential) {
149
+ return;
150
+ }
151
+ const bootstrapInfo = await getBootstrapInfo(credential, projectId);
152
+ cacheAllEnvironments(store, projectId, bootstrapInfo);
153
+ // Fix FIGMA_ENVIRONMENT_NAME if it doesn't match any actual environment
154
+ const envNames = bootstrapInfo.environments.map((e)=>e.name);
155
+ if (!envNames.includes(environmentName) && envNames.length > 0) {
156
+ const correctName = envNames[0];
157
+ if (params.isDryRun) {
158
+ p.log.message(`${pc.dim('○')} Would fix FIGMA_ENVIRONMENT_NAME: ${environmentName} → ${correctName}`);
159
+ params.changes.push(`Fix FIGMA_ENVIRONMENT_NAME`);
160
+ return;
161
+ }
162
+ await addOrUpdateEnvVar(params.cwd, 'FIGMA_ENVIRONMENT_NAME', correctName);
163
+ p.log.message(`${pc.green('●')} Env: Fixed FIGMA_ENVIRONMENT_NAME: ${environmentName} → ${correctName}`);
164
+ params.changes.push(`Fixed FIGMA_ENVIRONMENT_NAME: ${environmentName} → ${correctName}`);
165
+ }
166
+ } catch {
167
+ // Best-effort — runtime will retry if needed
168
+ }
169
+ }
170
+ async function migrateRemoveDeprecatedEnvVars({ changes, cwd, isDryRun, warnings = [] }) {
171
+ try {
172
+ const presentVars = [];
173
+ for (const key of DEPRECATED_ENV_VARS){
174
+ const value = await getEnvVar(cwd, key);
175
+ if (value !== null) {
176
+ presentVars.push(key);
177
+ }
178
+ }
179
+ if (presentVars.length === 0) {
180
+ return;
181
+ }
182
+ // Only remove when bootstrap data is available (proves the project is set up correctly)
183
+ const projectId = await getEnvVar(cwd, 'FIGMA_PROJECT_ID');
184
+ if (!projectId) {
185
+ warnings.push('Cannot remove deprecated env vars without FIGMA_PROJECT_ID. Run upgrade again after project ID migration.');
186
+ return;
187
+ }
188
+ const environmentName = await getEnvVar(cwd, 'FIGMA_ENVIRONMENT_NAME') ?? 'production';
189
+ const store = getTokenStore();
190
+ const bootstrapData = store.getBootstrapData(projectId, environmentName);
191
+ if (!bootstrapData) {
192
+ // Try fetching from API
193
+ const credential = await getValidCredential(store);
194
+ if (credential) {
195
+ try {
196
+ const bootstrapInfo = await getBootstrapInfo(credential, projectId);
197
+ cacheAllEnvironments(store, projectId, bootstrapInfo);
198
+ } catch {
199
+ warnings.push('Could not verify bootstrap data — keeping deprecated env vars. Run `npx @payloadcms/figma init` to complete migration.');
200
+ return;
201
+ }
202
+ } else {
203
+ warnings.push('Not authenticated — keeping deprecated env vars. Run `npx @payloadcms/figma login` first.');
204
+ return;
205
+ }
206
+ }
207
+ if (isDryRun) {
208
+ p.log.message(`${pc.dim('○')} Would remove deprecated env vars: ${presentVars.join(', ')}`);
209
+ changes.push(`Remove deprecated env vars: ${presentVars.join(', ')}`);
210
+ return;
211
+ }
212
+ const removed = [];
213
+ for (const key of presentVars){
214
+ await removeEnvVar(cwd, key);
215
+ removed.push(key);
216
+ }
217
+ p.log.message(`${pc.green('●')} Env: Removed deprecated env vars: ${removed.join(', ')}`);
218
+ changes.push(`Removed deprecated env vars: ${removed.join(', ')}`);
219
+ } catch (error) {
220
+ const msg = error instanceof Error ? error.message : 'Unknown error';
221
+ p.log.warning(`Deprecated env var removal failed: ${msg}`);
222
+ }
223
+ }
224
+ async function migrateConfigAst({ changes, cwd, isDryRun }) {
225
+ try {
226
+ const configPath = await findPayloadConfig(cwd);
227
+ if (!configPath) {
228
+ return;
229
+ }
230
+ const project = new Project({
231
+ skipAddingFilesFromTsConfig: true
232
+ });
233
+ const sourceFile = project.addSourceFileAtPath(configPath);
234
+ const wouldRemove = removeFigmaContentSystemId(sourceFile);
235
+ if (!wouldRemove) {
236
+ return;
237
+ }
238
+ if (isDryRun) {
239
+ p.log.message(`${pc.dim('○')} Would remove contentSystemId from payload.config.ts`);
240
+ changes.push('Remove contentSystemId from payload.config.ts');
241
+ return;
242
+ }
243
+ // Re-parse fresh since the detection already mutated the AST
244
+ const freshProject = new Project({
245
+ skipAddingFilesFromTsConfig: true
246
+ });
247
+ const freshSourceFile = freshProject.addSourceFileAtPath(configPath);
248
+ removeFigmaContentSystemId(freshSourceFile);
249
+ await freshSourceFile.save();
250
+ try {
251
+ const packageManager = await getPackageManager(cwd);
252
+ await formatFile(configPath, packageManager);
253
+ } catch {
254
+ // Formatting is best-effort
255
+ }
256
+ p.log.message(`${pc.green('●')} Config: Removed contentSystemId from payload.config.ts`);
257
+ changes.push('Removed contentSystemId from payload.config.ts');
258
+ } catch (error) {
259
+ const msg = error instanceof Error ? error.message : 'Unknown error';
260
+ p.log.warning(`Config AST migration failed: ${msg}`);
261
+ }
262
+ }
263
+ async function migratePackageVersion({ changes, cwd, isDryRun }) {
264
+ try {
265
+ const isInstalled = await checkPackageInstalled(cwd, '@payloadcms/figma');
266
+ if (!isInstalled) {
267
+ return;
268
+ }
269
+ const cliDir = path.dirname(fileURLToPath(import.meta.url));
270
+ const isFromRegistry = cliDir.includes('node_modules') || cliDir.includes('.npm');
271
+ if (isFromRegistry) {
272
+ await migrateRegistryPackageVersion({
273
+ changes,
274
+ cliDir,
275
+ cwd,
276
+ isDryRun
277
+ });
278
+ } else {
279
+ await migrateLocalPackageVersion({
280
+ changes,
281
+ cliDir,
282
+ cwd,
283
+ isDryRun
284
+ });
285
+ }
286
+ } catch (error) {
287
+ const msg = error instanceof Error ? error.message : 'Unknown error';
288
+ p.log.warning(`Package version sync failed: ${msg}`);
289
+ }
290
+ }
291
+ async function migrateRegistryPackageVersion({ changes, cliDir: _cliDir, cwd, isDryRun }) {
292
+ const cliVersion = await getOwnVersion();
293
+ const pkgJsonPath = path.join(cwd, 'package.json');
294
+ const pkgJson = JSON.parse(await fs.readFile(pkgJsonPath, 'utf-8'));
295
+ const installedVersion = pkgJson.dependencies?.['@payloadcms/figma']?.replace(/^[\^~>=<]+/, '');
296
+ if (!installedVersion || installedVersion === cliVersion) {
297
+ return;
298
+ }
299
+ if (isDryRun) {
300
+ p.log.message(`${pc.dim('○')} Would update @payloadcms/figma ${installedVersion} → ${cliVersion}`);
301
+ changes.push(`Update @payloadcms/figma ${installedVersion} → ${cliVersion}`);
302
+ return;
303
+ }
304
+ const packageManager = await getPackageManager(cwd);
305
+ await installPackage(cwd, '@payloadcms/figma', packageManager, cliVersion);
306
+ p.log.message(`${pc.green('●')} Package: Updated @payloadcms/figma ${installedVersion} → ${cliVersion}`);
307
+ changes.push(`Updated @payloadcms/figma ${installedVersion} → ${cliVersion}`);
308
+ }
309
+ async function migrateLocalPackageVersion({ changes, cliDir, cwd, isDryRun }) {
310
+ if (isDryRun) {
311
+ p.log.message(`${pc.dim('○')} Would install @payloadcms/figma from local build`);
312
+ changes.push('Install @payloadcms/figma from local build');
313
+ return;
314
+ }
315
+ // Dynamic import — findPackageRoot and packLocalPackage will be exported in a later task
316
+ const { findPackageRoot, packLocalPackage } = await import('../utils/handle-upgrade.js');
317
+ const pkgDir = await findPackageRoot(cliDir);
318
+ if (!pkgDir) {
319
+ return;
320
+ }
321
+ const packageManager = await getPackageManager(cwd);
322
+ const tgzPath = packLocalPackage(pkgDir);
323
+ const destTgz = path.join(cwd, path.basename(tgzPath));
324
+ await fs.rename(tgzPath, destTgz);
325
+ await installPackage(cwd, destTgz, packageManager);
326
+ await fs.unlink(destTgz).catch(()=>{});
327
+ p.log.message(`${pc.green('●')} Package: Installed @payloadcms/figma from local build`);
328
+ changes.push('Installed @payloadcms/figma from local build');
329
+ }
@@ -0,0 +1,8 @@
1
+ export interface UploadSchemaCommandOptions {
2
+ /** Environment name (overrides FIGMA_ENVIRONMENT_NAME). */
3
+ env?: string;
4
+ /** CMS Resource ID (overrides FIGMA_PROJECT_ID). */
5
+ id?: string;
6
+ }
7
+ /** Upload the current Payload collection schema for Content API migration tooling. */
8
+ export declare function uploadSchemaCommand(options?: UploadSchemaCommandOptions): Promise<void>;
@@ -0,0 +1,91 @@
1
+ import * as p from '@clack/prompts';
2
+ import pc from 'picocolors';
3
+ import { getBootstrapInfo } from '../api/control-plane.js';
4
+ import { tryGetCredential } from '../auth/oauth-flow.js';
5
+ import { getValidProjectToken } from '../auth/project-token.js';
6
+ import { getTokenStore } from '../auth/token-store.js';
7
+ import { getEnvConfig } from '../constants.js';
8
+ import { buildDocumentSchema } from '../db-content-api/utilities/schema/buildDocumentSchema.js';
9
+ import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
10
+ import { getEnvVar } from '../utils/env-management.js';
11
+ import { loadPayloadConfig } from '../utils/load-payload-config.js';
12
+ import { resolveEnvironment } from '../utils/resolve-environment.js';
13
+ import { loginCommand } from './login.js';
14
+ /** Upload the current Payload collection schema for Content API migration tooling. */ export async function uploadSchemaCommand(options = {}) {
15
+ const projectPath = process.cwd();
16
+ const projectId = options.id ?? await getEnvVar(projectPath, 'FIGMA_PROJECT_ID') ?? undefined;
17
+ const environmentName = options.env ?? await getEnvVar(projectPath, 'FIGMA_ENVIRONMENT_NAME') ?? undefined;
18
+ if (!projectId) {
19
+ p.log.error(pc.red('Project ID not found. Run `@payloadcms/figma init` first, or use --id.'));
20
+ process.exit(1);
21
+ }
22
+ // Bootstrap still requires a CLI login when the upload uses the Content API key.
23
+ const tokenStore = getTokenStore();
24
+ let credential = await tryGetCredential(tokenStore);
25
+ if (!credential) {
26
+ p.log.message('Please log in to continue');
27
+ await loginCommand();
28
+ credential = await tryGetCredential(tokenStore);
29
+ }
30
+ if (!credential) {
31
+ p.log.error(pc.red('Authentication failed'));
32
+ process.exit(1);
33
+ }
34
+ const spinner = p.spinner();
35
+ spinner.start('Resolving schema upload target...');
36
+ try {
37
+ const bootstrapInfo = await getBootstrapInfo(credential, projectId);
38
+ const environment = resolveEnvironment({
39
+ environmentName,
40
+ environments: bootstrapInfo.environments
41
+ });
42
+ cacheAllEnvironments(tokenStore, projectId, bootstrapInfo);
43
+ spinner.message('Loading Payload config...');
44
+ // --id/--env select the upload target only. Collections conditionally configured from
45
+ // FIGMA_ENVIRONMENT_NAME still use process.env/.env and may not match that upload target.
46
+ const config = await loadPayloadConfig(projectPath);
47
+ const documentSchema = buildDocumentSchema(config);
48
+ spinner.message('Uploading collection schema...');
49
+ const apiKey = process.env.FIGMA_CONTENT_API_ACCESS_KEY;
50
+ const projectToken = apiKey ? null : await getValidProjectToken({
51
+ projectInfo: {
52
+ environmentName: environment.name,
53
+ projectId
54
+ },
55
+ tenantId: environment.contentSystemId,
56
+ tokenStore
57
+ });
58
+ if (!apiKey && !projectToken) {
59
+ throw new Error('Could not get a project token. Run `@payloadcms/figma login` and retry.');
60
+ }
61
+ // --infra-env is applied by the CLI before this fallback selects the Content API URL.
62
+ const contentApiUrl = process.env.FIGMA_CONTENT_API_URL || getEnvConfig().contentApiUrl;
63
+ if (!contentApiUrl) {
64
+ throw new Error('FIGMA_CONTENT_API_URL is required for this infrastructure environment.');
65
+ }
66
+ const response = await fetch(`${contentApiUrl}/api/v0/content_systems/${encodeURIComponent(environment.contentSystemId)}/jsonb_to_index_migration_schema`, {
67
+ body: JSON.stringify({
68
+ documentSchema
69
+ }),
70
+ headers: {
71
+ 'Content-Type': 'application/json',
72
+ ...apiKey ? {
73
+ 'X-Api-Key': apiKey
74
+ } : {
75
+ Authorization: `Bearer ${projectToken}`
76
+ }
77
+ },
78
+ method: 'PUT'
79
+ });
80
+ if (!response.ok) {
81
+ const responseBody = await response.text();
82
+ throw new Error(`Content API returned ${response.status}${responseBody ? `: ${responseBody}` : ''}`);
83
+ }
84
+ const collectionCount = Object.keys(documentSchema.collections).length;
85
+ spinner.stop(pc.green(`Uploaded ${collectionCount} collection schema${collectionCount === 1 ? '' : 's'} to ${environment.name}`));
86
+ } catch (error) {
87
+ spinner.stop(pc.red('Failed to upload collection schema'));
88
+ p.log.error(error instanceof Error ? error.message : 'Unknown error');
89
+ process.exit(1);
90
+ }
91
+ }