@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.
- package/dist/api/control-plane.d.ts +56 -7
- package/dist/api/control-plane.js +188 -74
- package/dist/api/error-response.d.ts +36 -0
- package/dist/api/error-response.js +66 -0
- package/dist/api/figma-api.d.ts +24 -3
- package/dist/api/figma-api.js +110 -34
- package/dist/auth/browser.d.ts +0 -1
- package/dist/auth/browser.js +0 -2
- package/dist/auth/callback-server.d.ts +19 -8
- package/dist/auth/callback-server.js +72 -32
- package/dist/auth/credentials.d.ts +20 -0
- package/dist/auth/credentials.js +19 -0
- package/dist/auth/crypto-utils.d.ts +28 -1
- package/dist/auth/crypto-utils.js +132 -23
- package/dist/auth/jwt-validator.d.ts +23 -6
- package/dist/auth/jwt-validator.js +35 -9
- package/dist/auth/oauth-flow.d.ts +19 -4
- package/dist/auth/oauth-flow.js +151 -34
- package/dist/auth/paste-code.d.ts +33 -0
- package/dist/auth/paste-code.js +87 -0
- package/dist/auth/pkce.d.ts +0 -1
- package/dist/auth/pkce.js +0 -2
- package/dist/auth/project-token.d.ts +32 -17
- package/dist/auth/project-token.js +176 -68
- package/dist/auth/refresh.d.ts +2 -2
- package/dist/auth/refresh.js +25 -14
- package/dist/auth/token-store-migration.d.ts +57 -0
- package/dist/auth/token-store-migration.js +154 -0
- package/dist/auth/token-store.d.ts +63 -98
- package/dist/auth/token-store.js +405 -124
- package/dist/auth/types.d.ts +40 -6
- package/dist/auth/types.js +1 -3
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +102 -8
- package/dist/commands/bootstrap.d.ts +17 -0
- package/dist/commands/bootstrap.js +88 -0
- package/dist/commands/build-lambda-zip.d.ts +4 -0
- package/dist/commands/build-lambda-zip.js +17 -0
- package/dist/commands/debug.d.ts +7 -0
- package/dist/commands/debug.js +178 -0
- package/dist/commands/deploy.d.ts +11 -1
- package/dist/commands/deploy.js +193 -153
- package/dist/commands/dump-tokens.d.ts +11 -0
- package/dist/commands/dump-tokens.js +67 -0
- package/dist/commands/env.d.ts +12 -0
- package/dist/commands/env.js +86 -0
- package/dist/commands/init.d.ts +9 -6
- package/dist/commands/init.js +232 -152
- package/dist/commands/list-tokens.d.ts +3 -4
- package/dist/commands/list-tokens.js +24 -11
- package/dist/commands/login.d.ts +8 -2
- package/dist/commands/login.js +34 -18
- package/dist/commands/logout.d.ts +5 -5
- package/dist/commands/logout.js +77 -17
- package/dist/commands/upgrade.d.ts +4 -0
- package/dist/commands/upgrade.js +329 -0
- package/dist/commands/upload-schema.d.ts +8 -0
- package/dist/commands/upload-schema.js +91 -0
- package/dist/config/oauth.d.ts +17 -12
- package/dist/config/oauth.js +38 -39
- package/dist/constants.d.ts +63 -19
- package/dist/constants.js +158 -20
- package/dist/db-content-api/generated/content-api-types.d.ts +7574 -0
- package/dist/db-content-api/generated/content-api-types.js +5 -0
- package/dist/db-content-api/index.d.ts +37 -0
- package/dist/db-content-api/index.js +938 -0
- package/dist/db-content-api/temp-utilities/slug.d.ts +1 -0
- package/dist/db-content-api/temp-utilities/slug.js +1 -0
- package/dist/db-content-api/temp-utilities/sorting.d.ts +2 -0
- package/dist/db-content-api/temp-utilities/sorting.js +37 -0
- package/dist/db-content-api/temp-utilities/types.d.ts +21 -0
- package/dist/db-content-api/temp-utilities/types.js +13 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts +38 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.js +62 -0
- package/dist/db-content-api/utilities/auth.d.ts +29 -0
- package/dist/db-content-api/utilities/auth.js +82 -0
- package/dist/db-content-api/utilities/data/applyDefaults.d.ts +6 -0
- package/dist/db-content-api/utilities/data/applyDefaults.js +75 -0
- package/dist/db-content-api/utilities/data/castFieldValue.d.ts +10 -0
- package/dist/db-content-api/utilities/data/castFieldValue.js +66 -0
- package/dist/db-content-api/utilities/data/index.d.ts +48 -0
- package/dist/db-content-api/utilities/data/index.js +299 -0
- package/dist/db-content-api/utilities/data/pointShape.d.ts +3 -0
- package/dist/db-content-api/utilities/data/pointShape.js +43 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +11 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +52 -0
- package/dist/db-content-api/utilities/data/richTextShape.d.ts +3 -0
- package/dist/db-content-api/utilities/data/richTextShape.js +56 -0
- package/dist/db-content-api/utilities/data/stripFields.d.ts +47 -0
- package/dist/db-content-api/utilities/data/stripFields.js +170 -0
- package/dist/db-content-api/utilities/data/transformPublishedLocale.d.ts +22 -0
- package/dist/db-content-api/utilities/data/transformPublishedLocale.js +40 -0
- package/dist/db-content-api/utilities/data/validateRelationships.d.ts +6 -0
- package/dist/db-content-api/utilities/data/validateRelationships.js +100 -0
- package/dist/db-content-api/utilities/joins.d.ts +52 -0
- package/dist/db-content-api/utilities/joins.js +137 -0
- package/dist/db-content-api/utilities/locale/index.d.ts +9 -0
- package/dist/db-content-api/utilities/locale/index.js +19 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +10 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +71 -0
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts +41 -0
- package/dist/db-content-api/utilities/meta/buildMeta.js +39 -0
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +16 -0
- package/dist/db-content-api/utilities/meta/buildPathTypes.js +243 -0
- package/dist/db-content-api/utilities/meta/buildUniquePaths.d.ts +12 -0
- package/dist/db-content-api/utilities/meta/buildUniquePaths.js +60 -0
- package/dist/db-content-api/utilities/meta/normalizeLocaleInWhere.d.ts +9 -0
- package/dist/db-content-api/utilities/meta/normalizeLocaleInWhere.js +100 -0
- package/dist/db-content-api/utilities/resolveBlocks.d.ts +19 -0
- package/dist/db-content-api/utilities/resolveBlocks.js +31 -0
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.d.ts +55 -0
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +182 -0
- package/dist/db-content-api/utilities/where.d.ts +19 -0
- package/dist/db-content-api/utilities/where.js +106 -0
- package/dist/deploy/schedule-extract-plugin.d.ts +10 -0
- package/dist/deploy/schedule-extract-plugin.js +32 -0
- package/dist/endpoints/health.d.ts +2 -0
- package/dist/endpoints/health.js +9 -0
- package/dist/endpoints/schema.d.ts +2 -0
- package/dist/endpoints/schema.js +27 -0
- package/dist/exports/client.d.ts +2 -1
- package/dist/exports/client.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/lib/download-skill.d.ts +12 -0
- package/dist/lib/download-skill.js +77 -0
- package/dist/oauth/components/FigmaAvatar/index.d.ts +3 -0
- package/dist/oauth/components/FigmaAvatar/index.js +25 -0
- package/dist/oauth/components/FigmaAvatar/index.scss +12 -0
- package/dist/oauth/components/FigmaAvatarCell/index.d.ts +4 -0
- package/dist/oauth/components/FigmaAvatarCell/index.js +23 -0
- package/dist/oauth/components/FigmaAvatarCell/index.scss +5 -0
- package/dist/oauth/components/FigmaAvatarPlaceholder/index.d.ts +8 -0
- package/dist/oauth/components/FigmaAvatarPlaceholder/index.js +35 -0
- package/dist/oauth/components/FigmaAvatarPlaceholder/index.scss +28 -0
- package/dist/oauth/components/LoginButton/iframeAutoLogin.d.ts +81 -0
- package/dist/oauth/components/LoginButton/iframeAutoLogin.js +168 -0
- package/dist/oauth/components/LoginButton/index.d.ts +0 -1
- package/dist/oauth/components/LoginButton/index.js +156 -18
- package/dist/oauth/components/LoginButton/index.scss +75 -3
- package/dist/oauth/components/LogoutButton/index.d.ts +0 -1
- package/dist/oauth/components/LogoutButton/index.js +20 -9
- package/dist/oauth/defaults.d.ts +3 -2
- package/dist/oauth/defaults.js +79 -12
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts +0 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js +87 -84
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts +0 -1
- package/dist/oauth/endpoints/getLogoutEndpoint.js +7 -6
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts +0 -1
- package/dist/oauth/endpoints/getMetaEndpoint.js +18 -5
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts +0 -1
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js +11 -4
- package/dist/oauth/exports/client.d.ts +0 -1
- package/dist/oauth/exports/client.js +0 -2
- package/dist/oauth/hooks/afterLogout.d.ts +0 -1
- package/dist/oauth/hooks/afterLogout.js +0 -2
- package/dist/oauth/hooks/me.d.ts +0 -1
- package/dist/oauth/hooks/me.js +0 -2
- package/dist/oauth/hooks/refresh.d.ts +0 -1
- package/dist/oauth/hooks/refresh.js +2 -3
- package/dist/oauth/index.d.ts +0 -1
- package/dist/oauth/index.js +27 -7
- package/dist/oauth/strategy/index.d.ts +0 -3
- package/dist/oauth/strategy/index.js +55 -34
- package/dist/oauth/types.d.ts +23 -7
- package/dist/oauth/types.js +0 -2
- package/dist/oauth/utilities/buildUnauthorizedRedirect.d.ts +14 -0
- package/dist/oauth/utilities/buildUnauthorizedRedirect.js +28 -0
- package/dist/oauth/utilities/clearCookie.d.ts +0 -1
- package/dist/oauth/utilities/clearCookie.js +5 -3
- package/dist/oauth/utilities/createCookieOptions.d.ts +0 -1
- package/dist/oauth/utilities/createCookieOptions.js +9 -4
- package/dist/oauth/utilities/createDebugLogger.d.ts +0 -1
- package/dist/oauth/utilities/createDebugLogger.js +0 -2
- package/dist/oauth/utilities/establishSession.d.ts +22 -0
- package/dist/oauth/utilities/establishSession.js +80 -0
- package/dist/oauth/utilities/exchangeCodeForAccessToken.d.ts +23 -0
- package/dist/oauth/utilities/exchangeCodeForAccessToken.js +26 -0
- package/dist/oauth/utilities/extractOrigin.d.ts +0 -1
- package/dist/oauth/utilities/extractOrigin.js +0 -2
- package/dist/oauth/utilities/figmaHostnames.d.ts +2 -0
- package/dist/oauth/utilities/figmaHostnames.js +24 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +0 -1
- package/dist/oauth/utilities/getAdminCollectionSlug.js +0 -2
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +65 -2
- package/dist/oauth/utilities/getAuthorizeURL.js +57 -4
- package/dist/oauth/utilities/getCookieExpiration.d.ts +0 -1
- package/dist/oauth/utilities/getCookieExpiration.js +0 -2
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts +0 -1
- package/dist/oauth/utilities/getSecondsFromTokenExp.js +0 -2
- package/dist/oauth/utilities/getTokenExp.d.ts +0 -1
- package/dist/oauth/utilities/getTokenExp.js +0 -2
- package/dist/oauth/utilities/getUsernameField.d.ts +0 -1
- package/dist/oauth/utilities/getUsernameField.js +0 -2
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts +0 -1
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js +0 -2
- package/dist/oauth/utilities/isAbsoluteURL.d.ts +1 -0
- package/dist/oauth/utilities/isAbsoluteURL.js +1 -0
- package/dist/oauth/utilities/isDuplicateKeyError.d.ts +6 -0
- package/dist/oauth/utilities/isDuplicateKeyError.js +12 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts +0 -1
- package/dist/oauth/utilities/mergeHeaders.js +0 -2
- package/dist/oauth/utilities/refreshTokens.d.ts +0 -1
- package/dist/oauth/utilities/refreshTokens.js +21 -13
- package/dist/oauth/utilities/withPartitionedCookie.d.ts +19 -0
- package/dist/oauth/utilities/withPartitionedCookie.js +26 -0
- package/dist/oauth/utils/getSearchParam.d.ts +17 -0
- package/dist/oauth/utils/getSearchParam.js +22 -0
- package/dist/plugin/adapter.d.ts +0 -1
- package/dist/plugin/adapter.js +0 -2
- package/dist/plugin/auth-preflight.d.ts +7 -0
- package/dist/plugin/auth-preflight.js +18 -0
- package/dist/plugin/bootstrap-preflight.d.ts +22 -0
- package/dist/plugin/bootstrap-preflight.js +43 -0
- package/dist/plugin/build-config.d.ts +27 -15
- package/dist/plugin/build-config.js +381 -18
- package/dist/plugin/dev-cookie-names.d.ts +13 -0
- package/dist/plugin/dev-cookie-names.js +17 -0
- package/dist/scss.d.js +2 -0
- package/dist/storage-content-api/api-types.d.ts +183 -0
- package/dist/storage-content-api/api-types.js +4 -0
- package/dist/storage-content-api/client-uploads/generate.d.ts +14 -0
- package/dist/storage-content-api/client-uploads/generate.js +69 -0
- package/dist/storage-content-api/client.d.ts +5 -0
- package/dist/storage-content-api/client.js +37 -0
- package/dist/storage-content-api/generateURL.d.ts +6 -0
- package/dist/storage-content-api/generateURL.js +6 -0
- package/dist/storage-content-api/handleDelete.d.ts +7 -0
- package/dist/storage-content-api/handleDelete.js +15 -0
- package/dist/storage-content-api/handleUpload.d.ts +10 -0
- package/dist/storage-content-api/handleUpload.js +162 -0
- package/dist/storage-content-api/index.d.ts +4 -0
- package/dist/storage-content-api/index.js +37 -0
- package/dist/storage-content-api/staticHandler.d.ts +9 -0
- package/dist/storage-content-api/staticHandler.js +61 -0
- package/dist/storage-content-api/types.d.ts +9 -0
- package/dist/storage-content-api/types.js +1 -0
- package/dist/storage-content-api/utilities/getSafeFilename.d.ts +11 -0
- package/dist/storage-content-api/utilities/getSafeFilename.js +59 -0
- package/dist/storage-content-api/utilities/index.d.ts +2 -0
- package/dist/storage-content-api/utilities/index.js +2 -0
- package/dist/storage-content-api/utilities/parseUploadReference.d.ts +17 -0
- package/dist/storage-content-api/utilities/parseUploadReference.js +27 -0
- package/dist/templates/.env.example +5 -0
- package/dist/templates/README.md +19 -0
- package/dist/types/config.d.ts +2 -2
- package/dist/types/config.js +0 -4
- package/dist/types.d.ts +10 -2
- package/dist/types.js +0 -2
- package/dist/utils/adapters/nextjs.d.ts +8 -0
- package/dist/utils/adapters/nextjs.js +61 -0
- package/dist/utils/adapters/nitro.d.ts +8 -0
- package/dist/utils/adapters/nitro.js +172 -0
- package/dist/utils/adapters/vite.d.ts +9 -0
- package/dist/utils/adapters/vite.js +31 -0
- package/dist/utils/asset-collection.d.ts +27 -7
- package/dist/utils/asset-collection.js +59 -32
- package/dist/utils/build-detection.d.ts +5 -12
- package/dist/utils/build-detection.js +74 -13
- package/dist/utils/build-lambda-zip.d.ts +25 -0
- package/dist/utils/build-lambda-zip.js +90 -0
- package/dist/utils/cache-bootstrap.d.ts +7 -0
- package/dist/utils/cache-bootstrap.js +16 -0
- package/dist/utils/config.d.ts +0 -1
- package/dist/utils/config.js +1 -3
- package/dist/utils/deploy-adapter.d.ts +45 -0
- package/dist/utils/deploy-adapter.js +56 -0
- package/dist/utils/download-template.d.ts +9 -2
- package/dist/utils/download-template.js +24 -20
- package/dist/utils/env-management.d.ts +24 -8
- package/dist/utils/env-management.js +119 -66
- package/dist/utils/format-env-suffix.d.ts +11 -0
- package/dist/utils/format-env-suffix.js +11 -0
- package/dist/utils/format.d.ts +0 -1
- package/dist/utils/format.js +0 -2
- package/dist/utils/formatter.d.ts +0 -1
- package/dist/utils/formatter.js +23 -13
- package/dist/utils/fs-utils.d.ts +12 -0
- package/dist/utils/fs-utils.js +55 -0
- package/dist/utils/git.d.ts +0 -1
- package/dist/utils/git.js +0 -2
- package/dist/utils/handle-upgrade.d.ts +8 -0
- package/dist/utils/handle-upgrade.js +39 -0
- package/dist/utils/is-debug.d.ts +0 -1
- package/dist/utils/is-debug.js +0 -2
- package/dist/utils/lambda-config.d.ts +3 -2
- package/dist/utils/lambda-config.js +75 -80
- package/dist/utils/load-payload-config.d.ts +9 -0
- package/dist/utils/load-payload-config.js +27 -0
- package/dist/utils/log.d.ts +0 -1
- package/dist/utils/log.js +0 -2
- package/dist/utils/messages.d.ts +1 -3
- package/dist/utils/messages.js +47 -13
- package/dist/utils/package-manager.d.ts +24 -1
- package/dist/utils/package-manager.js +53 -2
- package/dist/utils/parse-template-spec.d.ts +11 -0
- package/dist/utils/parse-template-spec.js +60 -0
- package/dist/utils/payload-config-ast.d.ts +27 -7
- package/dist/utils/payload-config-ast.js +106 -60
- package/dist/utils/payload-config-finder.d.ts +2 -3
- package/dist/utils/payload-config-finder.js +48 -11
- package/dist/utils/payload-config-modifier.d.ts +1 -2
- package/dist/utils/payload-config-modifier.js +114 -68
- package/dist/utils/payload-package-check.d.ts +28 -3
- package/dist/utils/payload-package-check.js +90 -31
- package/dist/utils/project.d.ts +8 -4
- package/dist/utils/project.js +63 -37
- package/dist/utils/resolve-environment.d.ts +13 -0
- package/dist/utils/resolve-environment.js +29 -0
- package/dist/utils/s3-upload.d.ts +7 -3
- package/dist/utils/s3-upload.js +44 -9
- package/dist/utils/token-display.d.ts +5 -2
- package/dist/utils/token-display.js +49 -24
- package/dist/utils/typescript-validator.d.ts +0 -1
- package/dist/utils/typescript-validator.js +4 -8
- package/dist/utils/version-check.d.ts +2 -0
- package/dist/utils/version-check.js +43 -0
- package/package.json +47 -16
- package/dist/api/control-plane.d.ts.map +0 -1
- package/dist/api/control-plane.js.map +0 -1
- package/dist/api/figma-api.d.ts.map +0 -1
- package/dist/api/figma-api.js.map +0 -1
- package/dist/auth/browser.d.ts.map +0 -1
- package/dist/auth/browser.js.map +0 -1
- package/dist/auth/callback-server.d.ts.map +0 -1
- package/dist/auth/callback-server.js.map +0 -1
- package/dist/auth/crypto-utils.d.ts.map +0 -1
- package/dist/auth/crypto-utils.js.map +0 -1
- package/dist/auth/jwt-validator.d.ts.map +0 -1
- package/dist/auth/jwt-validator.js.map +0 -1
- package/dist/auth/oauth-flow.d.ts.map +0 -1
- package/dist/auth/oauth-flow.js.map +0 -1
- package/dist/auth/pkce.d.ts.map +0 -1
- package/dist/auth/pkce.js.map +0 -1
- package/dist/auth/project-token.d.ts.map +0 -1
- package/dist/auth/project-token.js.map +0 -1
- package/dist/auth/refresh.d.ts.map +0 -1
- package/dist/auth/refresh.js.map +0 -1
- package/dist/auth/token-store.d.ts.map +0 -1
- package/dist/auth/token-store.js.map +0 -1
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/deploy.js.map +0 -1
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/list-tokens.d.ts.map +0 -1
- package/dist/commands/list-tokens.js.map +0 -1
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/logout.d.ts.map +0 -1
- package/dist/commands/logout.js.map +0 -1
- package/dist/config/oauth.d.ts.map +0 -1
- package/dist/config/oauth.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/exports/client.d.ts.map +0 -1
- package/dist/exports/client.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/oauth/components/LoginButton/index.d.ts.map +0 -1
- package/dist/oauth/components/LoginButton/index.js.map +0 -1
- package/dist/oauth/components/LogoutButton/index.d.ts.map +0 -1
- package/dist/oauth/components/LogoutButton/index.js.map +0 -1
- package/dist/oauth/defaults.d.ts.map +0 -1
- package/dist/oauth/defaults.js.map +0 -1
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +0 -1
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getLogoutEndpoint.js.map +0 -1
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getMetaEndpoint.js.map +0 -1
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +0 -1
- package/dist/oauth/exports/client.d.ts.map +0 -1
- package/dist/oauth/exports/client.js.map +0 -1
- package/dist/oauth/hooks/afterLogout.d.ts.map +0 -1
- package/dist/oauth/hooks/afterLogout.js.map +0 -1
- package/dist/oauth/hooks/me.d.ts.map +0 -1
- package/dist/oauth/hooks/me.js.map +0 -1
- package/dist/oauth/hooks/refresh.d.ts.map +0 -1
- package/dist/oauth/hooks/refresh.js.map +0 -1
- package/dist/oauth/index.d.ts.map +0 -1
- package/dist/oauth/index.js.map +0 -1
- package/dist/oauth/strategy/index.d.ts.map +0 -1
- package/dist/oauth/strategy/index.js.map +0 -1
- package/dist/oauth/types.d.ts.map +0 -1
- package/dist/oauth/types.js.map +0 -1
- package/dist/oauth/utilities/clearCookie.d.ts.map +0 -1
- package/dist/oauth/utilities/clearCookie.js.map +0 -1
- package/dist/oauth/utilities/createCookieOptions.d.ts.map +0 -1
- package/dist/oauth/utilities/createCookieOptions.js.map +0 -1
- package/dist/oauth/utilities/createDebugLogger.d.ts.map +0 -1
- package/dist/oauth/utilities/createDebugLogger.js.map +0 -1
- package/dist/oauth/utilities/extractOrigin.d.ts.map +0 -1
- package/dist/oauth/utilities/extractOrigin.js.map +0 -1
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +0 -1
- package/dist/oauth/utilities/getAdminCollectionSlug.js.map +0 -1
- package/dist/oauth/utilities/getAdminPath.d.ts +0 -8
- package/dist/oauth/utilities/getAdminPath.d.ts.map +0 -1
- package/dist/oauth/utilities/getAdminPath.js +0 -9
- package/dist/oauth/utilities/getAdminPath.js.map +0 -1
- package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +0 -1
- package/dist/oauth/utilities/getAuthorizeURL.js.map +0 -1
- package/dist/oauth/utilities/getCookieExpiration.d.ts.map +0 -1
- package/dist/oauth/utilities/getCookieExpiration.js.map +0 -1
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +0 -1
- package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +0 -1
- package/dist/oauth/utilities/getTokenExp.d.ts.map +0 -1
- package/dist/oauth/utilities/getTokenExp.js.map +0 -1
- package/dist/oauth/utilities/getUsernameField.d.ts.map +0 -1
- package/dist/oauth/utilities/getUsernameField.js.map +0 -1
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +0 -1
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +0 -1
- package/dist/oauth/utilities/mergeHeaders.d.ts.map +0 -1
- package/dist/oauth/utilities/mergeHeaders.js.map +0 -1
- package/dist/oauth/utilities/refreshTokens.d.ts.map +0 -1
- package/dist/oauth/utilities/refreshTokens.js.map +0 -1
- package/dist/plugin/adapter.d.ts.map +0 -1
- package/dist/plugin/adapter.js.map +0 -1
- package/dist/plugin/build-config.d.ts.map +0 -1
- package/dist/plugin/build-config.js.map +0 -1
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/config.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/asset-collection.d.ts.map +0 -1
- package/dist/utils/asset-collection.js.map +0 -1
- package/dist/utils/build-detection.d.ts.map +0 -1
- package/dist/utils/build-detection.js.map +0 -1
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/download-template.d.ts.map +0 -1
- package/dist/utils/download-template.js.map +0 -1
- package/dist/utils/env-management.d.ts.map +0 -1
- package/dist/utils/env-management.js.map +0 -1
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js.map +0 -1
- package/dist/utils/formatter.d.ts.map +0 -1
- package/dist/utils/formatter.js.map +0 -1
- package/dist/utils/git.d.ts.map +0 -1
- package/dist/utils/git.js.map +0 -1
- package/dist/utils/is-debug.d.ts.map +0 -1
- package/dist/utils/is-debug.js.map +0 -1
- package/dist/utils/lambda-config.d.ts.map +0 -1
- package/dist/utils/lambda-config.js.map +0 -1
- package/dist/utils/log.d.ts.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/messages.d.ts.map +0 -1
- package/dist/utils/messages.js.map +0 -1
- package/dist/utils/package-manager.d.ts.map +0 -1
- package/dist/utils/package-manager.js.map +0 -1
- package/dist/utils/payload-config-ast.d.ts.map +0 -1
- package/dist/utils/payload-config-ast.js.map +0 -1
- package/dist/utils/payload-config-finder.d.ts.map +0 -1
- package/dist/utils/payload-config-finder.js.map +0 -1
- package/dist/utils/payload-config-modifier.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.js.map +0 -1
- package/dist/utils/payload-package-check.d.ts.map +0 -1
- package/dist/utils/payload-package-check.js.map +0 -1
- package/dist/utils/project.d.ts.map +0 -1
- package/dist/utils/project.js.map +0 -1
- package/dist/utils/s3-upload.d.ts.map +0 -1
- package/dist/utils/s3-upload.js.map +0 -1
- package/dist/utils/token-display.d.ts.map +0 -1
- package/dist/utils/token-display.js.map +0 -1
- package/dist/utils/typescript-validator.d.ts.map +0 -1
- package/dist/utils/typescript-validator.js.map +0 -1
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { flattenAllFields, traverseFields } from 'payload';
|
|
2
|
+
import { applyDefaults } from './applyDefaults.js';
|
|
3
|
+
import { castFieldValue } from './castFieldValue.js';
|
|
4
|
+
import { removeVirtualFields } from './removeVirtualFields.js';
|
|
5
|
+
import { stripFields } from './stripFields.js';
|
|
6
|
+
import { transformToLocalizeStatus } from './transformPublishedLocale.js';
|
|
7
|
+
const ATOMIC_OPERATION_KEYS = [
|
|
8
|
+
'$push',
|
|
9
|
+
'$remove',
|
|
10
|
+
'$inc'
|
|
11
|
+
];
|
|
12
|
+
function isAtomicOperation(value) {
|
|
13
|
+
if (value === null || value === undefined || typeof value !== 'object' || Array.isArray(value)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const keys = Object.keys(value);
|
|
17
|
+
return keys.length === 1 && ATOMIC_OPERATION_KEYS.includes(keys[0]);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Transform data before sending to Content API (WRITE operations)
|
|
21
|
+
*
|
|
22
|
+
* Conversions applied:
|
|
23
|
+
* - Default values: Apply static defaults for undefined fields (when applyDefaults=true)
|
|
24
|
+
* - Type casting: Convert values to match field types (e.g., number -> string for text fields)
|
|
25
|
+
* - RichText fields: Objects -> JSON strings
|
|
26
|
+
* - Virtual fields: Remove fields with `virtual: true` (pure virtual fields should never be saved)
|
|
27
|
+
* - Timestamps: Add updatedAt (always), and createdAt (when createdAt=true)
|
|
28
|
+
* - publishedLocale: Transform to localizeStatus format (when publishedLocale is provided)
|
|
29
|
+
*
|
|
30
|
+
* Note: Date fields are automatically converted to ISO strings by JSON.stringify()
|
|
31
|
+
*/ export function dataToContentAPI(payload, collectionSlug, data, options) {
|
|
32
|
+
if (!data || typeof data !== 'object') {
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
// Transform publishedLocale to localizeStatus format before other transformations
|
|
36
|
+
const dataWithLocalizedStatus = transformToLocalizeStatus(data, options?.publishedLocale);
|
|
37
|
+
// Deep clone to avoid mutating original data
|
|
38
|
+
const transformed = JSON.parse(JSON.stringify(dataWithLocalizedStatus));
|
|
39
|
+
// Get collection config
|
|
40
|
+
const isGlobal = collectionSlug.startsWith('_global-');
|
|
41
|
+
const actualSlug = isGlobal ? collectionSlug.substring(8) : collectionSlug;
|
|
42
|
+
const collectionConfig = isGlobal ? payload.config.globals?.find((g)=>g.slug === actualSlug) : payload.config.collections.find((c)=>c.slug === actualSlug);
|
|
43
|
+
if (!collectionConfig?.fields) {
|
|
44
|
+
return transformed;
|
|
45
|
+
}
|
|
46
|
+
// Apply static defaults recursively to handle nested structures (arrays, groups)
|
|
47
|
+
// This must happen before traverseFields to ensure defaults are in place
|
|
48
|
+
if (options?.applyDefaults) {
|
|
49
|
+
applyDefaults(transformed, collectionConfig.fields, payload.config.blocks);
|
|
50
|
+
}
|
|
51
|
+
// Use Payload's traverseFields to iterate over all fields for transformations
|
|
52
|
+
const callback = ({ field, ref })=>{
|
|
53
|
+
if (!('name' in field) || !field.name) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!ref || typeof ref !== 'object') {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const current = ref;
|
|
60
|
+
let value = current[field.name];
|
|
61
|
+
if (isAtomicOperation(value)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// null → [] for non-localized array-like fields. SQL adapters return null for empty join
|
|
65
|
+
// tables; Content API stores JSON null which breaks jsonb_array_elements queries.
|
|
66
|
+
if (value === null && !('localized' in field && field.localized)) {
|
|
67
|
+
const isHasManyArray = (field.type === 'relationship' || field.type === 'upload') && 'hasMany' in field && field.hasMany;
|
|
68
|
+
const isArrayLike = field.type === 'array' || field.type === 'blocks';
|
|
69
|
+
const isHasManySelect = field.type === 'select' && 'hasMany' in field && field.hasMany;
|
|
70
|
+
if (isHasManyArray || isArrayLike || isHasManySelect) {
|
|
71
|
+
current[field.name] = [];
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (value !== null && value !== undefined) {
|
|
76
|
+
value = castFieldValue(field, value);
|
|
77
|
+
current[field.name] = value;
|
|
78
|
+
// Normalize non-localized hasMany relationship/upload: single value → array.
|
|
79
|
+
// Payload may not wrap in array before calling db.update (e.g. children: 'uuid').
|
|
80
|
+
const isNonLocalizedHasMany = !('localized' in field && field.localized) && (field.type === 'relationship' || field.type === 'upload') && 'hasMany' in field && field.hasMany;
|
|
81
|
+
if (isNonLocalizedHasMany && !Array.isArray(value)) {
|
|
82
|
+
current[field.name] = [
|
|
83
|
+
value
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
// RichText: object -> JSON string
|
|
87
|
+
if (field.type === 'richText' && typeof value !== 'string') {
|
|
88
|
+
current[field.name] = JSON.stringify(value);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
traverseFields({
|
|
93
|
+
callback,
|
|
94
|
+
fields: collectionConfig.fields,
|
|
95
|
+
fillEmpty: false,
|
|
96
|
+
ref: transformed
|
|
97
|
+
});
|
|
98
|
+
stripFields({
|
|
99
|
+
config: payload.config,
|
|
100
|
+
data: transformed,
|
|
101
|
+
fields: flattenAllFields({
|
|
102
|
+
cache: true,
|
|
103
|
+
fields: collectionConfig.fields
|
|
104
|
+
}),
|
|
105
|
+
reservedKeys: [
|
|
106
|
+
'id',
|
|
107
|
+
'globalType'
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
removeVirtualFields(transformed, collectionConfig.fields);
|
|
111
|
+
// Convert numeric ID to string for Content API
|
|
112
|
+
const customIDType = payload.collections?.[collectionSlug]?.customIDType;
|
|
113
|
+
if (customIDType === 'number') {
|
|
114
|
+
transformed.id = String(transformed.id);
|
|
115
|
+
}
|
|
116
|
+
// Add timestamps (Content API no longer auto-sets these in DB)
|
|
117
|
+
// Preserve existing timestamps when already present (e.g. version data that carries
|
|
118
|
+
// the parent document's timestamps), otherwise generate new ones.
|
|
119
|
+
// Explicit null means "don't change" — strip it so the API keeps the existing value.
|
|
120
|
+
const now = new Date().toISOString();
|
|
121
|
+
if (transformed.updatedAt === null) {
|
|
122
|
+
delete transformed.updatedAt;
|
|
123
|
+
} else if (transformed.updatedAt === undefined) {
|
|
124
|
+
transformed.updatedAt = now;
|
|
125
|
+
}
|
|
126
|
+
if (options?.createdAt && !transformed.createdAt) {
|
|
127
|
+
transformed.createdAt = now;
|
|
128
|
+
}
|
|
129
|
+
return transformed;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Transform data received from Content API (READ operations)
|
|
133
|
+
*
|
|
134
|
+
* Conversions applied:
|
|
135
|
+
* - RichText fields: JSON strings -> Objects
|
|
136
|
+
* - Virtual fields: Remove fields with `virtual: true` (should not be in DB but Content API backend may add them)
|
|
137
|
+
*
|
|
138
|
+
* Note: Date fields come as ISO strings from Content API and stay as strings
|
|
139
|
+
* (matching MongoDB and other adapters' behavior)
|
|
140
|
+
*/ /**
|
|
141
|
+
* Extract version content from versionData that may be flat (no nested `version` key).
|
|
142
|
+
* Some callers spread version content at the top level alongside metadata
|
|
143
|
+
* (e.g. `{ ...version.version, createdAt }`), so we reconstruct the `version`
|
|
144
|
+
* object by filtering out known metadata keys.
|
|
145
|
+
*/ export function resolveVersionContent(version, versionMeta) {
|
|
146
|
+
if (version !== undefined) {
|
|
147
|
+
return version;
|
|
148
|
+
}
|
|
149
|
+
const metaKeys = [
|
|
150
|
+
'createdAt',
|
|
151
|
+
'updatedAt',
|
|
152
|
+
'latest',
|
|
153
|
+
'parent'
|
|
154
|
+
];
|
|
155
|
+
return Object.fromEntries(Object.entries(versionMeta).filter(([key])=>!metaKeys.includes(key)));
|
|
156
|
+
}
|
|
157
|
+
export function dataFromContentAPI(payload, collectionSlug, data, locale) {
|
|
158
|
+
if (!data || typeof data !== 'object') {
|
|
159
|
+
return data;
|
|
160
|
+
}
|
|
161
|
+
// Deep clone to avoid mutating original data
|
|
162
|
+
const transformed = JSON.parse(JSON.stringify(data));
|
|
163
|
+
// Get collection config
|
|
164
|
+
const isGlobal = collectionSlug.startsWith('_global-');
|
|
165
|
+
const actualSlug = isGlobal ? collectionSlug.substring(8) : collectionSlug;
|
|
166
|
+
const collectionConfig = isGlobal ? payload.config.globals?.find((g)=>g.slug === actualSlug) : payload.config.collections.find((c)=>c.slug === actualSlug);
|
|
167
|
+
if (!collectionConfig?.fields) {
|
|
168
|
+
return transformed;
|
|
169
|
+
}
|
|
170
|
+
const isAllLocales = locale === 'all' || locale === '*';
|
|
171
|
+
// Use Payload's traverseFields to iterate over all fields
|
|
172
|
+
const callback = ({ field, parentPath, ref })=>{
|
|
173
|
+
if (!('name' in field) || !field.name) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (!ref || typeof ref !== 'object') {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const current = ref;
|
|
180
|
+
const value = current[field.name];
|
|
181
|
+
const isLocalized = 'localized' in field && field.localized;
|
|
182
|
+
// Group fields must always be an object so Payload can traverse sub-fields
|
|
183
|
+
// (e.g. join fields inside a group). A null/undefined group crashes afterRead.
|
|
184
|
+
if (field.type === 'group') {
|
|
185
|
+
if (value == null || typeof value !== 'object') {
|
|
186
|
+
current[field.name] = {};
|
|
187
|
+
}
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
// Localized join fields: wrap in locale map so afterRead can hoist the value.
|
|
191
|
+
// Content API returns join data directly at the field path (e.g. { docs: [...] }),
|
|
192
|
+
// but Payload's afterRead expects localized fields as { [locale]: value }.
|
|
193
|
+
if (field.type === 'join' && isLocalized && value !== undefined && !isAllLocales && locale) {
|
|
194
|
+
current[field.name] = {
|
|
195
|
+
[locale]: value
|
|
196
|
+
};
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
// Content API may omit fields; Payload expects null for optional fields.
|
|
200
|
+
// In all-locales mode, localized fields use {} so afterRead can safely iterate locale keys.
|
|
201
|
+
if (value === undefined) {
|
|
202
|
+
const isRequired = 'required' in field && field.required;
|
|
203
|
+
const isJoin = field.type === 'join';
|
|
204
|
+
if (!isRequired && !isJoin) {
|
|
205
|
+
current[field.name] = isLocalized && isAllLocales ? {} : null;
|
|
206
|
+
}
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
// null localized field in all-locales mode → {} (empty locale map)
|
|
210
|
+
if (value === null && isLocalized && isAllLocales) {
|
|
211
|
+
current[field.name] = {};
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (value !== null) {
|
|
215
|
+
// hasMany relationships: normalize to array (non-localized only).
|
|
216
|
+
// We store raw JSON so a single value stays as-is; Payload expects arrays.
|
|
217
|
+
if (field.type === 'relationship' && field.hasMany && !Array.isArray(value) && !('localized' in field && field.localized)) {
|
|
218
|
+
current[field.name] = [
|
|
219
|
+
value
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
// Localized array/blocks: empty per-locale arrays → null in single-locale mode.
|
|
223
|
+
// Payload's afterRead fallback triggers on null (not []), matching SQL adapter behavior.
|
|
224
|
+
if (isLocalized && !isAllLocales && (field.type === 'array' || field.type === 'blocks') && typeof value === 'object' && !Array.isArray(value)) {
|
|
225
|
+
const localeMap = value;
|
|
226
|
+
for (const localeKey of Object.keys(localeMap)){
|
|
227
|
+
const localeValue = localeMap[localeKey];
|
|
228
|
+
if (Array.isArray(localeValue) && localeValue.length === 0) {
|
|
229
|
+
localeMap[localeKey] = null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Localized fields: JSON string → parsed object (locale map).
|
|
234
|
+
// Simple strings that fail to parse as objects are kept as-is (expected for single-locale).
|
|
235
|
+
if ('localized' in field && field.localized && typeof value === 'string') {
|
|
236
|
+
try {
|
|
237
|
+
const parsed = JSON.parse(value);
|
|
238
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
239
|
+
current[field.name] = parsed;
|
|
240
|
+
}
|
|
241
|
+
} catch {
|
|
242
|
+
// Not valid JSON - keep original value
|
|
243
|
+
}
|
|
244
|
+
} else if (field.type === 'richText' && typeof value === 'string') {
|
|
245
|
+
try {
|
|
246
|
+
current[field.name] = JSON.parse(value);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
const fieldPath = parentPath ? `${parentPath}.${field.name}` : field.name;
|
|
249
|
+
payload.logger.warn({
|
|
250
|
+
err: error instanceof Error ? error : new Error(String(error)),
|
|
251
|
+
msg: `Failed to parse richtext field '${fieldPath}' in collection '${collectionSlug}'`
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// Date fields: Already ISO strings from Content API, no conversion needed
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
traverseFields({
|
|
259
|
+
callback,
|
|
260
|
+
fields: collectionConfig.fields,
|
|
261
|
+
fillEmpty: false,
|
|
262
|
+
ref: transformed
|
|
263
|
+
});
|
|
264
|
+
// Convert string ID to number if collection uses numeric custom ID
|
|
265
|
+
const customIDType = payload.collections?.[collectionSlug]?.customIDType;
|
|
266
|
+
if (customIDType === 'number') {
|
|
267
|
+
transformed.id = Number(transformed.id);
|
|
268
|
+
}
|
|
269
|
+
stripFields({
|
|
270
|
+
config: payload.config,
|
|
271
|
+
data: transformed,
|
|
272
|
+
fields: flattenAllFields({
|
|
273
|
+
cache: true,
|
|
274
|
+
fields: collectionConfig.fields
|
|
275
|
+
}),
|
|
276
|
+
reservedKeys: [
|
|
277
|
+
'id',
|
|
278
|
+
'globalType'
|
|
279
|
+
]
|
|
280
|
+
});
|
|
281
|
+
// Remove virtual fields - must happen AFTER stripFields
|
|
282
|
+
removeVirtualFields(transformed, collectionConfig.fields);
|
|
283
|
+
// Handle auth-specific fields that aren't in the field schema
|
|
284
|
+
// When these fields are null in DB, Content API omits them from response (undefined)
|
|
285
|
+
// But Payload expects them to be null, not undefined
|
|
286
|
+
// Only add them if the collection has auth enabled
|
|
287
|
+
if ('auth' in collectionConfig && collectionConfig.auth) {
|
|
288
|
+
const authFields = [
|
|
289
|
+
'resetPasswordExpiration',
|
|
290
|
+
'lockUntil'
|
|
291
|
+
];
|
|
292
|
+
for (const fieldName of authFields){
|
|
293
|
+
if (!(fieldName in transformed)) {
|
|
294
|
+
transformed[fieldName] = null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return transformed;
|
|
299
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payload stores a point as GeoJSON; the v1 server uses a bare `[lng, lat]`
|
|
3
|
+
* tuple. Unwrap on write, re-wrap on read so afterRead can restore the tuple.
|
|
4
|
+
*/ function isPlainObject(value) {
|
|
5
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function isCoordinateTuple(value) {
|
|
8
|
+
return Array.isArray(value) && value.length === 2 && value.every((v)=>typeof v === 'number');
|
|
9
|
+
}
|
|
10
|
+
function pointLeafToWire(value) {
|
|
11
|
+
if (isPlainObject(value) && isCoordinateTuple(value.coordinates)) {
|
|
12
|
+
return value.coordinates;
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function pointLeafFromWire(value) {
|
|
17
|
+
if (isCoordinateTuple(value)) {
|
|
18
|
+
return {
|
|
19
|
+
type: 'Point',
|
|
20
|
+
coordinates: value
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function mapPoint(field, value, mapLeaf) {
|
|
26
|
+
if (field.type !== 'point' || value === null || value === undefined) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
if ('localized' in field && field.localized && isPlainObject(value)) {
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const [locale, localeValue] of Object.entries(value)){
|
|
32
|
+
result[locale] = mapLeaf(localeValue);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
return mapLeaf(value);
|
|
37
|
+
}
|
|
38
|
+
export function encodePointForWrite(field, value) {
|
|
39
|
+
return mapPoint(field, value, pointLeafToWire);
|
|
40
|
+
}
|
|
41
|
+
export function decodePointFromRead(field, value) {
|
|
42
|
+
return mapPoint(field, value, pointLeafFromWire);
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Removes virtual fields (fields with virtual: true) from data recursively.
|
|
4
|
+
* Virtual fields should never be persisted in the database.
|
|
5
|
+
*
|
|
6
|
+
* @todo It might be a good idea to combine `stripFields` with `stripFields`
|
|
7
|
+
* in a new utility that receives a callback with conditions. I didn't do
|
|
8
|
+
* it now because `stripFields` was copied from db-mongo and I'd like to
|
|
9
|
+
* find a way to unify everything.
|
|
10
|
+
*/
|
|
11
|
+
export declare function removeVirtualFields(data: Record<string, unknown>, fieldConfigs: CollectionConfig['fields']): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes virtual fields (fields with virtual: true) from data recursively.
|
|
3
|
+
* Virtual fields should never be persisted in the database.
|
|
4
|
+
*
|
|
5
|
+
* @todo It might be a good idea to combine `stripFields` with `stripFields`
|
|
6
|
+
* in a new utility that receives a callback with conditions. I didn't do
|
|
7
|
+
* it now because `stripFields` was copied from db-mongo and I'd like to
|
|
8
|
+
* find a way to unify everything.
|
|
9
|
+
*/ export function removeVirtualFields(data, fieldConfigs) {
|
|
10
|
+
for (const field of fieldConfigs){
|
|
11
|
+
// Handle UI fields (row, collapsible, tabs) - they don't have names
|
|
12
|
+
// but contain other fields that might be virtual
|
|
13
|
+
if (field.type === 'row' || field.type === 'collapsible') {
|
|
14
|
+
if ('fields' in field) {
|
|
15
|
+
removeVirtualFields(data, field.fields);
|
|
16
|
+
}
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (field.type === 'tabs' && 'tabs' in field) {
|
|
20
|
+
for (const tab of field.tabs){
|
|
21
|
+
if ('fields' in tab) {
|
|
22
|
+
removeVirtualFields(data, tab.fields);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
// Skip fields without names
|
|
28
|
+
if (!('name' in field) || !field.name) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// Remove field if it has virtual: true
|
|
32
|
+
if ('virtual' in field && field.virtual === true) {
|
|
33
|
+
delete data[field.name];
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// Recursively handle nested structures (groups, arrays with items, etc.)
|
|
37
|
+
if ('fields' in field && field.name in data) {
|
|
38
|
+
const value = data[field.name];
|
|
39
|
+
if (field.type === 'array' && Array.isArray(value)) {
|
|
40
|
+
// Process each array item
|
|
41
|
+
for (const item of value){
|
|
42
|
+
if (item && typeof item === 'object') {
|
|
43
|
+
removeVirtualFields(item, field.fields);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} else if (field.type === 'group' && value && typeof value === 'object') {
|
|
47
|
+
// Process group
|
|
48
|
+
removeVirtualFields(value, field.fields);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Field, Payload, TabAsField } from 'payload';
|
|
2
|
+
export declare function encodeRichTextForWrite(field: Field | TabAsField, value: unknown): unknown;
|
|
3
|
+
export declare function decodeRichTextFromRead(field: Field | TabAsField, value: unknown, payload: Payload, fieldPath: string, collectionSlug: string): unknown;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v1 server stores richText as a serialized JSON string, so stringify on
|
|
3
|
+
* write and parse on read. A localized richText is a per-locale map, serialized
|
|
4
|
+
* and parsed per entry (not as one blob).
|
|
5
|
+
*/ function isPlainObject(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function richTextLeafToWire(value) {
|
|
9
|
+
if (value === null || value === undefined || typeof value === 'string') {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
return JSON.stringify(value);
|
|
13
|
+
}
|
|
14
|
+
export function encodeRichTextForWrite(field, value) {
|
|
15
|
+
if (field.type !== 'richText' || value === null || value === undefined) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
if ('localized' in field && field.localized && isPlainObject(value)) {
|
|
19
|
+
const result = {};
|
|
20
|
+
for (const [locale, localeValue] of Object.entries(value)){
|
|
21
|
+
result[locale] = richTextLeafToWire(localeValue);
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
return richTextLeafToWire(value);
|
|
26
|
+
}
|
|
27
|
+
function richTextLeafFromWire(value, onError) {
|
|
28
|
+
if (typeof value !== 'string') {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(value);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
onError(error);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function decodeRichTextFromRead(field, value, payload, fieldPath, collectionSlug) {
|
|
39
|
+
if (field.type !== 'richText' || value === null || value === undefined) {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
const onError = (error)=>{
|
|
43
|
+
payload.logger.warn({
|
|
44
|
+
err: error instanceof Error ? error : new Error(String(error)),
|
|
45
|
+
msg: `Failed to parse richtext field '${fieldPath}' in collection '${collectionSlug}'`
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
if ('localized' in field && field.localized && isPlainObject(value)) {
|
|
49
|
+
const result = {};
|
|
50
|
+
for (const [locale, localeValue] of Object.entries(value)){
|
|
51
|
+
result[locale] = richTextLeafFromWire(localeValue, onError);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
return richTextLeafFromWire(value, onError);
|
|
56
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { FlattenedField, SanitizedConfig } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Strips fields from data that are not defined in the schema or are invalid.
|
|
4
|
+
*
|
|
5
|
+
* This function was copied from the MongoDB adapter's implementation:
|
|
6
|
+
* @see packages/db-mongodb/src/utilities/transform.ts (stripFields function)
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* This utility performs deep sanitization of document data by:
|
|
10
|
+
* 1. **Removing undefined fields**: Strips any field not present in the collection's schema
|
|
11
|
+
* (e.g., sensitive fields like `password`, `apiKey`, or any extra fields not in config)
|
|
12
|
+
* 2. **Removing invalid locales**: Deletes locale keys that don't exist in `config.localization.localeCodes`
|
|
13
|
+
* (e.g., if data contains `{ "es-MX": "..." }` but only `"en"` is configured)
|
|
14
|
+
* 3. **Removing invalid blocks**: Filters out blocks with unknown `blockType` values
|
|
15
|
+
* (prevents data corruption from blocks that don't exist in the schema)
|
|
16
|
+
* 4. **Recursive sanitization**: Processes nested structures (arrays, groups, blocks, localized fields)
|
|
17
|
+
* to ensure deep data integrity
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Unlike MongoDB's adapter which uses Mongoose schemas with `strict: true` (rejecting extra fields
|
|
21
|
+
* on write), Content API uses flexible JSONB storage that accepts any fields. Therefore, this
|
|
22
|
+
* function is called on **both read and write operations** to ensure data consistency.
|
|
23
|
+
*
|
|
24
|
+
* The MongoDB adapter also supports an `allowAdditionalKeys` option that allows reading/writing
|
|
25
|
+
* fields not in the schema. For now, Content API does not support this feature - we always
|
|
26
|
+
* sanitize data. If users request this functionality in the future, we can consider adding it.
|
|
27
|
+
*
|
|
28
|
+
* @todo
|
|
29
|
+
* 1. Consider moving this utility to `payload/shared` so both MongoDB and Content API adapters
|
|
30
|
+
* can use the same implementation, reducing code duplication and maintenance burden.
|
|
31
|
+
*
|
|
32
|
+
* 2. Performance optimization: This function iterates through all fields recursively.
|
|
33
|
+
* The `dataToContentAPI` and `dataFromContentAPI` functions in
|
|
34
|
+
* `packages/figma/src/db-content-api/utilities/data.ts` also iterate through fields
|
|
35
|
+
* to transform richText (object ↔ JSON string), custom IDs (number ↔ string), and dates.
|
|
36
|
+
* Consider combining both traversals into a single abstraction to avoid iterating twice.
|
|
37
|
+
*
|
|
38
|
+
* 3. Feature parity: MongoDB adapter has `allowAdditionalKeys` option. We currently always
|
|
39
|
+
* strip additional keys, but could add this as a configurable option if users need it.
|
|
40
|
+
*/
|
|
41
|
+
export declare const stripFields: ({ config, data, fields, parentIsLocalized, reservedKeys, }: {
|
|
42
|
+
config: SanitizedConfig;
|
|
43
|
+
data: any;
|
|
44
|
+
fields: FlattenedField[];
|
|
45
|
+
parentIsLocalized?: boolean;
|
|
46
|
+
reservedKeys?: string[];
|
|
47
|
+
}) => void;
|