@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
|
@@ -1,15 +1,122 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useConfig } from '@payloadcms/ui';
|
|
4
4
|
import { useSearchParams } from 'next/navigation.js';
|
|
5
5
|
import React, { useEffect, useState } from 'react';
|
|
6
|
+
import { resolveParentTargetOrigin, setupIframeAutoLogin } from './iframeAutoLogin.js';
|
|
6
7
|
import './index.scss';
|
|
7
8
|
const baseClass = 'oauth-login';
|
|
9
|
+
// Max time we wait for the parent (figma.com) to respond with a code after
|
|
10
|
+
// posting `mint-cms-oauth-code`. If we hit this without a reply, we assume
|
|
11
|
+
// the parent isn't going to respond and fall back to the manual login button.
|
|
12
|
+
const AUTO_LOGIN_PARENT_REPLY_TIMEOUT_MS = 10000;
|
|
13
|
+
// Figma logo SVG colored version
|
|
14
|
+
// const FigmaIcon: React.FC = () => (
|
|
15
|
+
// <svg fill="none" height="27" viewBox="0 0 400 600" width="18">
|
|
16
|
+
// <path
|
|
17
|
+
// d="M0 500C0 444.772 44.772 400 100 400H200V500C200 555.228 155.228 600 100 600C44.772 600 0 555.228 0 500Z"
|
|
18
|
+
// fill="#24CB71"
|
|
19
|
+
// />
|
|
20
|
+
// <path
|
|
21
|
+
// d="M200 0V200H300C355.228 200 400 155.228 400 100C400 44.772 355.228 0 300 0H200Z"
|
|
22
|
+
// fill="#FF7237"
|
|
23
|
+
// />
|
|
24
|
+
// <path
|
|
25
|
+
// d="M299.167 400C354.395 400 399.167 355.228 399.167 300C399.167 244.772 354.395 200 299.167 200C243.939 200 199.167 244.772 199.167 300C199.167 355.228 243.939 400 299.167 400Z"
|
|
26
|
+
// fill="#00B6FF"
|
|
27
|
+
// />
|
|
28
|
+
// <path
|
|
29
|
+
// d="M0 100C0 155.228 44.772 200 100 200H200V0H100C44.772 0 0 44.772 0 100Z"
|
|
30
|
+
// fill="#FF3737"
|
|
31
|
+
// />
|
|
32
|
+
// <path
|
|
33
|
+
// d="M0 300C0 355.228 44.772 400 100 400H200V200H100C44.772 200 0 244.772 0 300Z"
|
|
34
|
+
// fill="#874FFF"
|
|
35
|
+
// />
|
|
36
|
+
// </svg>
|
|
37
|
+
// )
|
|
38
|
+
// Figma logo SVG monochrome version
|
|
39
|
+
const FigmaIcon = ()=>/*#__PURE__*/ _jsx("svg", {
|
|
40
|
+
fill: "none",
|
|
41
|
+
height: "20px",
|
|
42
|
+
viewBox: "0 0 15 15",
|
|
43
|
+
width: "20px",
|
|
44
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
45
|
+
children: /*#__PURE__*/ _jsx("path", {
|
|
46
|
+
clipRule: "evenodd",
|
|
47
|
+
d: "M7.00005 2.04999H5.52505C4.71043 2.04999 4.05005 2.71037 4.05005 3.52499C4.05005 4.33961 4.71043 4.99999 5.52505 4.99999H7.00005V2.04999ZM7.00005 1.04999H8.00005H9.47505C10.842 1.04999 11.95 2.15808 11.95 3.52499C11.95 4.33163 11.5642 5.04815 10.9669 5.49999C11.5642 5.95184 11.95 6.66836 11.95 7.475C11.95 8.8419 10.842 9.95 9.47505 9.95C8.92236 9.95 8.41198 9.76884 8.00005 9.46266V9.95L8.00005 11.425C8.00005 12.7919 6.89195 13.9 5.52505 13.9C4.15814 13.9 3.05005 12.7919 3.05005 11.425C3.05005 10.6183 3.43593 9.90184 4.03317 9.44999C3.43593 8.99814 3.05005 8.28163 3.05005 7.475C3.05005 6.66836 3.43594 5.95184 4.03319 5.5C3.43594 5.04815 3.05005 4.33163 3.05005 3.52499C3.05005 2.15808 4.15814 1.04999 5.52505 1.04999H7.00005ZM8.00005 2.04999V4.99999H9.47505C10.2897 4.99999 10.95 4.33961 10.95 3.52499C10.95 2.71037 10.2897 2.04999 9.47505 2.04999H8.00005ZM5.52505 8.94998H7.00005L7.00005 7.4788L7.00005 7.475L7.00005 7.4712V6H5.52505C4.71043 6 4.05005 6.66038 4.05005 7.475C4.05005 8.28767 4.70727 8.94684 5.5192 8.94999L5.52505 8.94998ZM4.05005 11.425C4.05005 10.6123 4.70727 9.95315 5.5192 9.94999L5.52505 9.95H7.00005L7.00005 11.425C7.00005 12.2396 6.33967 12.9 5.52505 12.9C4.71043 12.9 4.05005 12.2396 4.05005 11.425ZM8.00005 7.47206C8.00164 6.65879 8.66141 6 9.47505 6C10.2897 6 10.95 6.66038 10.95 7.475C10.95 8.28962 10.2897 8.95 9.47505 8.95C8.66141 8.95 8.00164 8.29121 8.00005 7.47794V7.47206Z",
|
|
48
|
+
fill: "#FFFFFF",
|
|
49
|
+
fillRule: "evenodd"
|
|
50
|
+
})
|
|
51
|
+
});
|
|
8
52
|
export const DefaultLoginButton = ({ disabled, endpointSlug })=>{
|
|
9
53
|
const { config: { admin: { user: userSlug }, routes: { api }, serverURL } } = useConfig();
|
|
10
54
|
const [authorizeURL, setAuthorizeURL] = useState('');
|
|
55
|
+
const [isInIframe, setIsInIframe] = useState(null);
|
|
56
|
+
const [autoLoginFailed, setAutoLoginFailed] = useState(false);
|
|
11
57
|
const searchParams = useSearchParams();
|
|
12
58
|
const payloadRedirect = searchParams.get('redirect');
|
|
59
|
+
useEffect(()=>{
|
|
60
|
+
try {
|
|
61
|
+
setIsInIframe(window.self !== window.top);
|
|
62
|
+
} catch {
|
|
63
|
+
// Cross-origin access throws — that itself means we're in an iframe.
|
|
64
|
+
setIsInIframe(true);
|
|
65
|
+
}
|
|
66
|
+
}, []);
|
|
67
|
+
// Iframe auto-login: ask the parent (figma.com) for a fresh OAuth code, then
|
|
68
|
+
// navigate to `/sso/login?code=…&state=…` — the same handler the manual
|
|
69
|
+
// login button flow reaches. /sso/login exchanges the code, sets session
|
|
70
|
+
// cookies, and redirects to /admin. Runs on initial /admin/login load and
|
|
71
|
+
// after logout. See `./iframeAutoLogin.ts` for the flow + tests.
|
|
72
|
+
//
|
|
73
|
+
// If the flow fails — synchronously via `onFailed`, or silently via the
|
|
74
|
+
// timeout — we flip `autoLoginFailed` so the manual login button renders
|
|
75
|
+
// as a fallback instead of leaving the user on a blank screen.
|
|
76
|
+
useEffect(()=>{
|
|
77
|
+
if (isInIframe !== true || disabled) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const fallbackTimer = window.setTimeout(()=>{
|
|
81
|
+
// eslint-disable-next-line no-console -- surface silent parent failures
|
|
82
|
+
console.warn(`[payload iframe auto-login] parent did not reply with cms-oauth-code within ${AUTO_LOGIN_PARENT_REPLY_TIMEOUT_MS}ms — falling back to manual login`);
|
|
83
|
+
setAutoLoginFailed(true);
|
|
84
|
+
}, AUTO_LOGIN_PARENT_REPLY_TIMEOUT_MS);
|
|
85
|
+
// ancestorOrigins[0] is the immediate embedder's origin (browser-set,
|
|
86
|
+
// unspoofable) where supported; undefined on browsers that don't implement
|
|
87
|
+
// the non-standard Location.ancestorOrigins (older Firefox, pre-148).
|
|
88
|
+
const ancestorOrigins = window.location.ancestorOrigins;
|
|
89
|
+
// encodeURIComponent is required on Coder devbox: there a proxy hop rewrites
|
|
90
|
+
// an unencoded `serverURL=https://<host>` to http before it reaches the
|
|
91
|
+
// server, which then flows into state.serverURL / the OAuth redirect_uri and
|
|
92
|
+
// breaks login with an https→http navigation. Encoding the `://` avoids it.
|
|
93
|
+
const cleanup = setupIframeAutoLogin({
|
|
94
|
+
doFetch: window.fetch.bind(window),
|
|
95
|
+
metaUrl: `${serverURL}${api}/${userSlug}/${endpointSlug}/meta?serverURL=${encodeURIComponent(window.location.origin)}`,
|
|
96
|
+
navigate: (url)=>{
|
|
97
|
+
window.location.href = url;
|
|
98
|
+
},
|
|
99
|
+
onFailed: ()=>setAutoLoginFailed(true),
|
|
100
|
+
parentTargetOrigin: resolveParentTargetOrigin({
|
|
101
|
+
ancestorOrigin: ancestorOrigins?.[0],
|
|
102
|
+
ownOrigin: window.location.origin,
|
|
103
|
+
referrer: document.referrer
|
|
104
|
+
}),
|
|
105
|
+
postMessageToParent: (msg, target)=>window.parent.postMessage(msg, target),
|
|
106
|
+
win: window
|
|
107
|
+
});
|
|
108
|
+
return ()=>{
|
|
109
|
+
window.clearTimeout(fallbackTimer);
|
|
110
|
+
cleanup();
|
|
111
|
+
};
|
|
112
|
+
}, [
|
|
113
|
+
isInIframe,
|
|
114
|
+
disabled,
|
|
115
|
+
serverURL,
|
|
116
|
+
api,
|
|
117
|
+
userSlug,
|
|
118
|
+
endpointSlug
|
|
119
|
+
]);
|
|
13
120
|
useEffect(()=>{
|
|
14
121
|
if (payloadRedirect && !disabled) {
|
|
15
122
|
// set cookie to redirect to the original page
|
|
@@ -19,32 +126,63 @@ export const DefaultLoginButton = ({ disabled, endpointSlug })=>{
|
|
|
19
126
|
payloadRedirect,
|
|
20
127
|
disabled
|
|
21
128
|
]);
|
|
129
|
+
// Fetch the manual login URL whenever we'd render the button — either we
|
|
130
|
+
// aren't in an iframe, or we're in an iframe but auto-login has given up.
|
|
131
|
+
const shouldRenderButton = !disabled && (isInIframe === false || autoLoginFailed);
|
|
22
132
|
useEffect(()=>{
|
|
133
|
+
if (!shouldRenderButton) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
23
136
|
const getAuthorizeURL = async ()=>{
|
|
24
|
-
|
|
137
|
+
// Encoded for the same reason as the auto-login metaUrl above.
|
|
138
|
+
const serverURLFromWindow = encodeURIComponent(window.location.origin);
|
|
25
139
|
const data = await fetch(`${serverURL}${api}/${userSlug}/${endpointSlug}/meta?serverURL=${serverURLFromWindow}`).then((res)=>res.json());
|
|
26
|
-
|
|
27
|
-
setAuthorizeURL(data.authorizeURL);
|
|
28
|
-
}
|
|
140
|
+
setAuthorizeURL(data.authorizeURL);
|
|
29
141
|
};
|
|
30
142
|
void getAuthorizeURL();
|
|
31
143
|
}, [
|
|
32
144
|
api,
|
|
33
145
|
serverURL,
|
|
34
146
|
userSlug,
|
|
35
|
-
|
|
147
|
+
shouldRenderButton,
|
|
36
148
|
endpointSlug
|
|
37
149
|
]);
|
|
38
|
-
if (
|
|
150
|
+
if (!shouldRenderButton) {
|
|
151
|
+
// In the iframe auto-login window, show a "Signing in…" hint so the
|
|
152
|
+
// user sees something is happening instead of a blank slot until the
|
|
153
|
+
// flow either navigates them away or times out into the manual button.
|
|
154
|
+
if (isInIframe === true && !disabled) {
|
|
155
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
156
|
+
className: baseClass,
|
|
157
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
158
|
+
className: `${baseClass}__signing-in`,
|
|
159
|
+
role: "status",
|
|
160
|
+
children: [
|
|
161
|
+
/*#__PURE__*/ _jsx("span", {
|
|
162
|
+
children: "Signing in"
|
|
163
|
+
}),
|
|
164
|
+
/*#__PURE__*/ _jsx("div", {
|
|
165
|
+
"aria-hidden": "true",
|
|
166
|
+
className: `${baseClass}__spinner`
|
|
167
|
+
})
|
|
168
|
+
]
|
|
169
|
+
})
|
|
170
|
+
});
|
|
171
|
+
}
|
|
39
172
|
return null;
|
|
40
173
|
}
|
|
41
174
|
return /*#__PURE__*/ _jsx("div", {
|
|
42
175
|
className: baseClass,
|
|
43
|
-
children: /*#__PURE__*/
|
|
176
|
+
children: /*#__PURE__*/ _jsxs("a", {
|
|
44
177
|
className: `${baseClass}__btn`,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
178
|
+
href: authorizeURL,
|
|
179
|
+
children: [
|
|
180
|
+
/*#__PURE__*/ _jsx(FigmaIcon, {}),
|
|
181
|
+
/*#__PURE__*/ _jsx("span", {
|
|
182
|
+
className: `${baseClass}__text`,
|
|
183
|
+
children: "Log in with Figma"
|
|
184
|
+
})
|
|
185
|
+
]
|
|
48
186
|
})
|
|
49
187
|
});
|
|
50
188
|
};
|
|
@@ -1,10 +1,82 @@
|
|
|
1
1
|
.oauth-login {
|
|
2
2
|
display: flex;
|
|
3
3
|
justify-content: center;
|
|
4
|
+
padding: 1rem 0;
|
|
4
5
|
|
|
5
|
-
&__btn
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
&__btn {
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
gap: 0.75rem;
|
|
11
|
+
padding: 0.75rem 1.5rem;
|
|
12
|
+
min-height: 3rem;
|
|
13
|
+
background-color: #4d49fc;
|
|
14
|
+
color: #ffffff;
|
|
15
|
+
border: none;
|
|
16
|
+
border-radius: 0.5rem;
|
|
17
|
+
font-size: 1rem;
|
|
18
|
+
font-weight: 450;
|
|
19
|
+
letter-spacing: 0.05px;
|
|
20
|
+
text-decoration: none;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
transition: background-color 0.2s ease, transform 0.1s ease;
|
|
23
|
+
box-shadow: none;
|
|
24
|
+
|
|
25
|
+
&:hover {
|
|
26
|
+
background-color: #4440e8;
|
|
27
|
+
transform: translateY(-1px);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&:active {
|
|
31
|
+
background-color: #3c38d4;
|
|
32
|
+
transform: translateY(0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&:focus {
|
|
36
|
+
outline: none;
|
|
37
|
+
box-shadow: 0 0 0 2px rgba(77, 73, 252, 0.4);
|
|
8
38
|
}
|
|
9
39
|
}
|
|
40
|
+
|
|
41
|
+
&__icon {
|
|
42
|
+
flex-shrink: 0;
|
|
43
|
+
width: 20px;
|
|
44
|
+
height: 20px;
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
justify-content: center;
|
|
48
|
+
color: #ffffff;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&__text {
|
|
52
|
+
white-space: nowrap;
|
|
53
|
+
line-height: 1rem;
|
|
54
|
+
font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
55
|
+
Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&__signing-in {
|
|
59
|
+
display: flex;
|
|
60
|
+
flex-direction: column;
|
|
61
|
+
align-items: center;
|
|
62
|
+
gap: 0.75rem;
|
|
63
|
+
font-size: 1rem;
|
|
64
|
+
font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
|
|
65
|
+
Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&__spinner {
|
|
69
|
+
width: 24px;
|
|
70
|
+
height: 24px;
|
|
71
|
+
border: 2px solid var(--theme-elevation-200, #e5e5e5);
|
|
72
|
+
border-top-color: currentColor;
|
|
73
|
+
border-radius: 50%;
|
|
74
|
+
animation: oauth-login-spin 0.8s linear infinite;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@keyframes oauth-login-spin {
|
|
79
|
+
to {
|
|
80
|
+
transform: rotate(360deg);
|
|
81
|
+
}
|
|
10
82
|
}
|
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Logout, useConfig } from '@payloadcms/ui';
|
|
4
|
+
import { formatAdminURL } from 'payload/shared';
|
|
4
5
|
import React from 'react';
|
|
5
|
-
import { getAdminPath } from '../../utilities/getAdminPath.js';
|
|
6
6
|
import './index.scss';
|
|
7
7
|
const baseClass = 'oauth-logout';
|
|
8
8
|
export const LogoutButton = ({ disabled, endpointSlug })=>{
|
|
9
9
|
const { config, config: { admin: { user: userSlug }, routes: { api }, serverURL } } = useConfig();
|
|
10
|
+
// In an iframe (Figma Make Preview) the LoginButton auto-logs the user
|
|
11
|
+
// back in as soon as they hit /admin/login, which would silently undo the
|
|
12
|
+
// logout. Redirect to the site root instead so the user actually stays
|
|
13
|
+
// logged out. Outside an iframe, keep the original behavior of redirecting
|
|
14
|
+
// back to /admin.
|
|
10
15
|
const [redirect, setRedirect] = React.useState('');
|
|
11
16
|
React.useEffect(()=>{
|
|
12
17
|
const protocol = window.location.protocol;
|
|
13
18
|
const domain = window.location.hostname;
|
|
14
19
|
const port = window.location.port;
|
|
15
|
-
let
|
|
20
|
+
let origin = `${protocol}//${domain}`;
|
|
16
21
|
if (port) {
|
|
17
|
-
|
|
22
|
+
origin += `:${port}`;
|
|
18
23
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
let isInIframe;
|
|
25
|
+
try {
|
|
26
|
+
isInIframe = window.self !== window.top;
|
|
27
|
+
} catch {
|
|
28
|
+
// Cross-origin access throws — that itself means we're in an iframe.
|
|
29
|
+
isInIframe = true;
|
|
30
|
+
}
|
|
31
|
+
setRedirect(isInIframe ? origin : formatAdminURL({
|
|
32
|
+
adminRoute: config.routes.admin,
|
|
33
|
+
serverURL: origin
|
|
34
|
+
}));
|
|
22
35
|
}, [
|
|
23
36
|
config
|
|
24
37
|
]);
|
|
@@ -32,7 +45,7 @@ export const LogoutButton = ({ disabled, endpointSlug })=>{
|
|
|
32
45
|
className: baseClass,
|
|
33
46
|
children: /*#__PURE__*/ _jsx("a", {
|
|
34
47
|
"aria-label": "Logout",
|
|
35
|
-
href: `${serverURL}${api}/${userSlug}/${endpointSlug}/logout?redirect=${redirect}`,
|
|
48
|
+
href: `${serverURL}${api}/${userSlug}/${endpointSlug}/logout?redirect=${encodeURIComponent(redirect)}`,
|
|
36
49
|
children: /*#__PURE__*/ _jsxs("svg", {
|
|
37
50
|
className: "icon icon--logout",
|
|
38
51
|
fill: "none",
|
package/dist/oauth/defaults.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { CollectionConfig, EmailField, TextField } from 'payload';
|
|
2
2
|
import type { VerifyFunction } from './types.js';
|
|
3
|
+
export declare const DEFAULT_USER_INFO_COOKIE_NAME = "figma-user-info";
|
|
3
4
|
export declare const defaultScope: string[];
|
|
4
5
|
export declare const defaultUsernameField: TextField;
|
|
5
|
-
export declare const defaultVerify: ({ collection, strategyName, usernameField, }: {
|
|
6
|
+
export declare const defaultVerify: ({ collection, strategyName, userInfoCookieName, usernameField, }: {
|
|
6
7
|
collection: CollectionConfig;
|
|
7
8
|
strategyName: string;
|
|
9
|
+
userInfoCookieName?: string;
|
|
8
10
|
usernameField: EmailField | TextField;
|
|
9
11
|
}) => VerifyFunction;
|
|
10
12
|
//# sourceMappingURL=defaults.d.ts.map
|
package/dist/oauth/defaults.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import { parseCookies } from 'payload';
|
|
1
2
|
import { v4 as uuid } from 'uuid';
|
|
2
3
|
import { hasUserTokenPropsChanged } from './utilities/hasUserTokenPropsChanged.js';
|
|
4
|
+
import { isDuplicateKeyError } from './utilities/isDuplicateKeyError.js';
|
|
5
|
+
export const DEFAULT_USER_INFO_COOKIE_NAME = 'figma-user-info';
|
|
6
|
+
function getFigmaUserInfo(headers, cookieName) {
|
|
7
|
+
try {
|
|
8
|
+
const cookies = parseCookies(headers);
|
|
9
|
+
const encoded = cookies.get(cookieName);
|
|
10
|
+
if (!encoded) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return JSON.parse(Buffer.from(encoded, 'base64').toString('utf-8'));
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
3
18
|
export const defaultScope = [
|
|
4
19
|
'openid',
|
|
5
20
|
'profile',
|
|
@@ -14,7 +29,7 @@ export const defaultUsernameField = {
|
|
|
14
29
|
},
|
|
15
30
|
unique: true
|
|
16
31
|
};
|
|
17
|
-
export const defaultVerify = ({ collection, strategyName, usernameField })=>async ({ payload, token })=>{
|
|
32
|
+
export const defaultVerify = ({ collection, strategyName, userInfoCookieName = DEFAULT_USER_INFO_COOKIE_NAME, usernameField })=>async ({ headers, payload, token })=>{
|
|
18
33
|
let tokenUsername = 'preferred_username';
|
|
19
34
|
if (usernameField.name !== 'preferredUsername') {
|
|
20
35
|
tokenUsername = usernameField.name;
|
|
@@ -24,6 +39,13 @@ export const defaultVerify = ({ collection, strategyName, usernameField })=>asyn
|
|
|
24
39
|
user: null
|
|
25
40
|
};
|
|
26
41
|
}
|
|
42
|
+
const figmaUserInfo = getFigmaUserInfo(headers, userInfoCookieName);
|
|
43
|
+
let responseHeaders;
|
|
44
|
+
// Clear the cookie after reading
|
|
45
|
+
if (figmaUserInfo) {
|
|
46
|
+
responseHeaders = new Headers();
|
|
47
|
+
responseHeaders.append('Set-Cookie', `${userInfoCookieName}=; Max-Age=0; Path=/;`);
|
|
48
|
+
}
|
|
27
49
|
let user = null;
|
|
28
50
|
const depth = typeof collection.auth === 'object' ? collection.auth.depth : undefined;
|
|
29
51
|
try {
|
|
@@ -40,13 +62,19 @@ export const defaultVerify = ({ collection, strategyName, usernameField })=>asyn
|
|
|
40
62
|
});
|
|
41
63
|
if (results.docs.length > 0) {
|
|
42
64
|
user = results.docs[0];
|
|
43
|
-
//
|
|
44
|
-
|
|
65
|
+
// Check if update needed (token changed OR figma info missing/changed)
|
|
66
|
+
const userWithFigma = user;
|
|
67
|
+
const needsFigmaUpdate = figmaUserInfo && (userWithFigma.figmaHandle !== figmaUserInfo.handle || userWithFigma.figmaImageUrl !== figmaUserInfo.img_url);
|
|
68
|
+
if (hasUserTokenPropsChanged(user, token) || needsFigmaUpdate) {
|
|
45
69
|
user = await payload.update({
|
|
46
70
|
id: user.id,
|
|
47
71
|
collection: collection.slug,
|
|
48
72
|
data: {
|
|
49
|
-
...token
|
|
73
|
+
...token,
|
|
74
|
+
...figmaUserInfo && {
|
|
75
|
+
figmaHandle: figmaUserInfo.handle,
|
|
76
|
+
figmaImageUrl: figmaUserInfo.img_url
|
|
77
|
+
}
|
|
50
78
|
},
|
|
51
79
|
depth
|
|
52
80
|
});
|
|
@@ -55,16 +83,43 @@ export const defaultVerify = ({ collection, strategyName, usernameField })=>asyn
|
|
|
55
83
|
const newUser = {
|
|
56
84
|
email: token.preferredUsername || token.email,
|
|
57
85
|
[usernameField.name]: token[tokenUsername],
|
|
58
|
-
...token
|
|
86
|
+
...token,
|
|
87
|
+
...figmaUserInfo && {
|
|
88
|
+
figmaHandle: figmaUserInfo.handle,
|
|
89
|
+
figmaImageUrl: figmaUserInfo.img_url
|
|
90
|
+
}
|
|
59
91
|
};
|
|
60
92
|
if (typeof collection.auth === 'object' && !collection.auth.disableLocalStrategy) {
|
|
61
93
|
newUser.password = uuid();
|
|
62
94
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
95
|
+
try {
|
|
96
|
+
user = await payload.create({
|
|
97
|
+
collection: collection.slug,
|
|
98
|
+
data: newUser,
|
|
99
|
+
depth,
|
|
100
|
+
overrideAccess: true
|
|
101
|
+
});
|
|
102
|
+
} catch (createErr) {
|
|
103
|
+
// Race condition: if unique constraint violation, user was created by concurrent request
|
|
104
|
+
if (isDuplicateKeyError(createErr)) {
|
|
105
|
+
const retryResults = await payload.find({
|
|
106
|
+
collection: collection.slug,
|
|
107
|
+
depth,
|
|
108
|
+
limit: 1,
|
|
109
|
+
pagination: false,
|
|
110
|
+
where: {
|
|
111
|
+
[usernameField.name]: {
|
|
112
|
+
equals: token[tokenUsername]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
if (retryResults.docs.length > 0) {
|
|
117
|
+
user = retryResults.docs[0];
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
throw createErr;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
68
123
|
}
|
|
69
124
|
} catch (err) {
|
|
70
125
|
payload.logger.error({
|
|
@@ -72,6 +127,7 @@ export const defaultVerify = ({ collection, strategyName, usernameField })=>asyn
|
|
|
72
127
|
msg: 'Error verifying user from defaultVerify.'
|
|
73
128
|
});
|
|
74
129
|
return {
|
|
130
|
+
responseHeaders,
|
|
75
131
|
user: null
|
|
76
132
|
};
|
|
77
133
|
}
|
|
@@ -80,10 +136,12 @@ export const defaultVerify = ({ collection, strategyName, usernameField })=>asyn
|
|
|
80
136
|
user._strategy = strategyName;
|
|
81
137
|
user.exp = token.exp;
|
|
82
138
|
return {
|
|
139
|
+
responseHeaders,
|
|
83
140
|
user
|
|
84
141
|
};
|
|
85
142
|
}
|
|
86
143
|
return {
|
|
144
|
+
responseHeaders,
|
|
87
145
|
user: null
|
|
88
146
|
};
|
|
89
147
|
};
|