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