@revealui/auth 0.0.1-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/better-auth/adapter/__tests__/transform.test.js +213 -0
- package/dist/better-auth/adapter/__tests__/transform.test.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/biome.d.js +2 -0
- package/dist/better-auth/adapter/generate-schema/biome.d.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/generate-schema-builder.d.ts +5 -0
- package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js +482 -0
- package/dist/better-auth/adapter/generate-schema/generate-schema-builder.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/get-payload-schema.d.ts +1 -0
- package/dist/better-auth/adapter/generate-schema/get-payload-schema.js +42 -0
- package/dist/better-auth/adapter/generate-schema/get-payload-schema.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/index.d.ts +4 -0
- package/dist/better-auth/adapter/generate-schema/index.js +19 -0
- package/dist/better-auth/adapter/generate-schema/index.js.map +1 -0
- package/dist/better-auth/adapter/generate-schema/utils.d.ts +2 -0
- package/dist/better-auth/adapter/generate-schema/utils.js +20 -0
- package/dist/better-auth/adapter/generate-schema/utils.js.map +1 -0
- package/dist/better-auth/adapter/index.d.ts +15 -0
- package/dist/better-auth/adapter/index.js +731 -0
- package/dist/better-auth/adapter/index.js.map +1 -0
- package/dist/better-auth/adapter/tests/adapter.test.js +174 -0
- package/dist/better-auth/adapter/tests/adapter.test.js.map +1 -0
- package/dist/better-auth/adapter/tests/base-collections-tests.js +575 -0
- package/dist/better-auth/adapter/tests/base-collections-tests.js.map +1 -0
- package/dist/better-auth/adapter/tests/dev/index.js +117 -0
- package/dist/better-auth/adapter/tests/dev/index.js.map +1 -0
- package/dist/better-auth/adapter/tests/dev/migrate.js +26 -0
- package/dist/better-auth/adapter/tests/dev/migrate.js.map +1 -0
- package/dist/better-auth/adapter/tests/dev/migrations/20250423_232936_init.js +218 -0
- package/dist/better-auth/adapter/tests/dev/migrations/20250423_232936_init.js.map +1 -0
- package/dist/better-auth/adapter/tests/dev/schema.js +160 -0
- package/dist/better-auth/adapter/tests/dev/schema.js.map +1 -0
- package/dist/better-auth/adapter/tests/plugins-tests.js +2 -0
- package/dist/better-auth/adapter/tests/plugins-tests.js.map +1 -0
- package/dist/better-auth/adapter/transform/index.d.ts +27 -0
- package/dist/better-auth/adapter/transform/index.js +664 -0
- package/dist/better-auth/adapter/transform/index.js.map +1 -0
- package/dist/better-auth/adapter/types.d.ts +10 -0
- package/dist/better-auth/adapter/types.js +3 -0
- package/dist/better-auth/adapter/types.js.map +1 -0
- package/dist/better-auth/generated-types.d.ts +285 -0
- package/dist/better-auth/index.d.ts +3 -0
- package/dist/better-auth/index.js +5 -0
- package/dist/better-auth/index.js.map +1 -0
- package/dist/better-auth/plugin/__tests__/plugin.test.js +162 -0
- package/dist/better-auth/plugin/__tests__/plugin.test.js.map +1 -0
- package/dist/better-auth/plugin/constants.d.ts +220 -0
- package/dist/better-auth/plugin/constants.js +249 -0
- package/dist/better-auth/plugin/constants.js.map +1 -0
- package/dist/better-auth/plugin/helpers/check-plugin-exists.d.ts +12 -0
- package/dist/better-auth/plugin/helpers/check-plugin-exists.js +14 -0
- package/dist/better-auth/plugin/helpers/check-plugin-exists.js.map +1 -0
- package/dist/better-auth/plugin/helpers/generate-verify-email-url.d.ts +29 -0
- package/dist/better-auth/plugin/helpers/generate-verify-email-url.js +46 -0
- package/dist/better-auth/plugin/helpers/generate-verify-email-url.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-admin-access.d.ts +7 -0
- package/dist/better-auth/plugin/helpers/get-admin-access.js +22 -0
- package/dist/better-auth/plugin/helpers/get-admin-access.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-all-roles.d.ts +5 -0
- package/dist/better-auth/plugin/helpers/get-all-roles.js +20 -0
- package/dist/better-auth/plugin/helpers/get-all-roles.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-better-auth-schema.d.ts +18 -0
- package/dist/better-auth/plugin/helpers/get-better-auth-schema.js +70 -0
- package/dist/better-auth/plugin/helpers/get-better-auth-schema.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-collection-slug.d.ts +5 -0
- package/dist/better-auth/plugin/helpers/get-collection-slug.js +20 -0
- package/dist/better-auth/plugin/helpers/get-collection-slug.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-collection.d.ts +15 -0
- package/dist/better-auth/plugin/helpers/get-collection.js +29 -0
- package/dist/better-auth/plugin/helpers/get-collection.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-ip.d.ts +2 -0
- package/dist/better-auth/plugin/helpers/get-ip.js +31 -0
- package/dist/better-auth/plugin/helpers/get-ip.js.map +1 -0
- package/dist/better-auth/plugin/helpers/get-signed-cookie.d.ts +2 -0
- package/dist/better-auth/plugin/helpers/get-signed-cookie.js +65 -0
- package/dist/better-auth/plugin/helpers/get-signed-cookie.js.map +1 -0
- package/dist/better-auth/plugin/helpers/index.d.ts +1 -0
- package/dist/better-auth/plugin/helpers/index.js +3 -0
- package/dist/better-auth/plugin/helpers/index.js.map +1 -0
- package/dist/better-auth/plugin/helpers/prepare-session-data.d.ts +59 -0
- package/dist/better-auth/plugin/helpers/prepare-session-data.js +49 -0
- package/dist/better-auth/plugin/helpers/prepare-session-data.js.map +1 -0
- package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.d.ts +20 -0
- package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.js +67 -0
- package/dist/better-auth/plugin/helpers/sync-resolved-schema-with-collection-map.js.map +1 -0
- package/dist/better-auth/plugin/index.d.ts +11 -0
- package/dist/better-auth/plugin/index.js +125 -0
- package/dist/better-auth/plugin/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.d.ts +12 -0
- package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.js +87 -0
- package/dist/better-auth/plugin/lib/apply-disabled-default-auth-config.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.js +60 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/hooks/sync-password-to-user.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/index.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/index.js +154 -0
- package/dist/better-auth/plugin/lib/build-collections/accounts/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.d.ts +5 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.js +11 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-after-read.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.js +8 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/hooks/get-url-before-change.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.d.ts +6 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.js +119 -0
- package/dist/better-auth/plugin/lib/build-collections/admin-invitations/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/api-keys.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/api-keys.js +177 -0
- package/dist/better-auth/plugin/lib/build-collections/api-keys.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/device-code.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/device-code.js +50 -0
- package/dist/better-auth/plugin/lib/build-collections/device-code.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/index.d.ts +10 -0
- package/dist/better-auth/plugin/lib/build-collections/index.js +73 -0
- package/dist/better-auth/plugin/lib/build-collections/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/invitations.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/invitations.js +94 -0
- package/dist/better-auth/plugin/lib/build-collections/invitations.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/jwks.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/jwks.js +59 -0
- package/dist/better-auth/plugin/lib/build-collections/jwks.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/members.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/members.js +73 -0
- package/dist/better-auth/plugin/lib/build-collections/members.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.js +107 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-access-tokens.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-applications.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-applications.js +118 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-applications.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-consents.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-consents.js +89 -0
- package/dist/better-auth/plugin/lib/build-collections/oauth-consents.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/organizations.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/organizations.js +70 -0
- package/dist/better-auth/plugin/lib/build-collections/organizations.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/passkeys.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/passkeys.js +115 -0
- package/dist/better-auth/plugin/lib/build-collections/passkeys.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/sessions.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/sessions.js +170 -0
- package/dist/better-auth/plugin/lib/build-collections/sessions.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/sso-providers.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/sso-providers.js +81 -0
- package/dist/better-auth/plugin/lib/build-collections/sso-providers.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/subscriptions.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/subscriptions.js +111 -0
- package/dist/better-auth/plugin/lib/build-collections/subscriptions.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/team-members.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/team-members.js +57 -0
- package/dist/better-auth/plugin/lib/build-collections/team-members.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/teams.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/teams.js +76 -0
- package/dist/better-auth/plugin/lib/build-collections/teams.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/two-factors.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/two-factors.js +67 -0
- package/dist/better-auth/plugin/lib/build-collections/two-factors.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.d.ts +7 -0
- package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.js +53 -0
- package/dist/better-auth/plugin/lib/build-collections/users/better-auth-strategy.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.d.ts +11 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.js +75 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/generate-invite-url.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.d.ts +4 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.js +6 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.js +115 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/refresh-token.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.js +64 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/send-invite-url.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.js +80 -0
- package/dist/better-auth/plugin/lib/build-collections/users/endpoints/set-admin-role.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.d.ts +6 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.js +79 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-login.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.js +82 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/after-logout.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.js +54 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-delete.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.d.ts +6 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.js +15 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/before-login.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.d.ts +6 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.js +8 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.js +17 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/on-verified-change.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.d.ts +2 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.js +91 -0
- package/dist/better-auth/plugin/lib/build-collections/users/hooks/sync-account.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/users/index.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/users/index.js +341 -0
- package/dist/better-auth/plugin/lib/build-collections/users/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.d.ts +15 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.js +24 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/collection-schema.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.d.ts +10 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.js +67 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-duplicate-fields.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.d.ts +9 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.js +94 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/filter-properties.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.d.ts +7 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.js +35 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/get-timestamp-fields.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.d.ts +12 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.js +25 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/model-field-transformations.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.d.ts +14 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.js +67 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/payload-access.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.d.ts +20 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.js +98 -0
- package/dist/better-auth/plugin/lib/build-collections/utils/transform-schema-fields-to-payload.js.map +1 -0
- package/dist/better-auth/plugin/lib/build-collections/verifications.d.ts +3 -0
- package/dist/better-auth/plugin/lib/build-collections/verifications.js +87 -0
- package/dist/better-auth/plugin/lib/build-collections/verifications.js.map +1 -0
- package/dist/better-auth/plugin/lib/get-payload-auth.d.ts +5 -0
- package/dist/better-auth/plugin/lib/get-payload-auth.js +9 -0
- package/dist/better-auth/plugin/lib/get-payload-auth.js.map +1 -0
- package/dist/better-auth/plugin/lib/init-better-auth.d.ts +7 -0
- package/dist/better-auth/plugin/lib/init-better-auth.js +46 -0
- package/dist/better-auth/plugin/lib/init-better-auth.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.js +9 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/admin-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.js +10 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/api-key-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.js +8 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/device-authorization-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.d.ts +10 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.js +156 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/index.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.js +18 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/oidc-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.js +34 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/organizations-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.js +11 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/passkey-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.js +10 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/sso-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.d.ts +2 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.js +11 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/two-factor-plugin.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.d.ts +7 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.js +23 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/ensure-password-set-before-create.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.d.ts +25 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.js +62 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/password.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.d.ts +9 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.js +47 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/require-admin-invite-for-sign-up-middleware.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.d.ts +15 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.js +42 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/save-to-jwt-middleware.js.map +1 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.d.ts +9 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.js +63 -0
- package/dist/better-auth/plugin/lib/sanitize-better-auth-options/utils/use-admin-invite-after-email-sign-up-middleware.js.map +1 -0
- package/dist/better-auth/plugin/lib/set-login-methods.d.ts +4 -0
- package/dist/better-auth/plugin/lib/set-login-methods.js +14 -0
- package/dist/better-auth/plugin/lib/set-login-methods.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/admin-buttons/index.d.ts +9 -0
- package/dist/better-auth/plugin/payload/components/admin-buttons/index.js +143 -0
- package/dist/better-auth/plugin/payload/components/admin-buttons/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/admin-invite-button/index.d.ts +10 -0
- package/dist/better-auth/plugin/payload/components/admin-invite-button/index.js +219 -0
- package/dist/better-auth/plugin/payload/components/admin-invite-button/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/logout-button.d.ts +4 -0
- package/dist/better-auth/plugin/payload/components/logout-button.js +24 -0
- package/dist/better-auth/plugin/payload/components/logout-button.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/add-button.d.ts +8 -0
- package/dist/better-auth/plugin/payload/components/passkeys/add-button.js +117 -0
- package/dist/better-auth/plugin/payload/components/passkeys/add-button.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/client.d.ts +3 -0
- package/dist/better-auth/plugin/payload/components/passkeys/client.js +66 -0
- package/dist/better-auth/plugin/payload/components/passkeys/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/index.d.ts +4 -0
- package/dist/better-auth/plugin/payload/components/passkeys/index.js +52 -0
- package/dist/better-auth/plugin/payload/components/passkeys/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/list.d.ts +8 -0
- package/dist/better-auth/plugin/payload/components/passkeys/list.js +57 -0
- package/dist/better-auth/plugin/payload/components/passkeys/list.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/passkeys/types.d.ts +22 -0
- package/dist/better-auth/plugin/payload/components/passkeys/types.js +3 -0
- package/dist/better-auth/plugin/payload/components/passkeys/types.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/rsc-redirect.d.ts +6 -0
- package/dist/better-auth/plugin/payload/components/rsc-redirect.js +7 -0
- package/dist/better-auth/plugin/payload/components/rsc-redirect.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.d.ts +15 -0
- package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.js +157 -0
- package/dist/better-auth/plugin/payload/components/social-provider-buttons/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/token-field.d.ts +4 -0
- package/dist/better-auth/plugin/payload/components/token-field.js +31 -0
- package/dist/better-auth/plugin/payload/components/token-field.js.map +1 -0
- package/dist/better-auth/plugin/payload/components/two-factor-auth/index.d.ts +8 -0
- package/dist/better-auth/plugin/payload/components/two-factor-auth/index.js +300 -0
- package/dist/better-auth/plugin/payload/components/two-factor-auth/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/exports/client.d.ts +6 -0
- package/dist/better-auth/plugin/payload/exports/client.js +8 -0
- package/dist/better-auth/plugin/payload/exports/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/exports/rsc.d.ts +8 -0
- package/dist/better-auth/plugin/payload/exports/rsc.js +10 -0
- package/dist/better-auth/plugin/payload/exports/rsc.js.map +1 -0
- package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.d.ts +2 -0
- package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.js +9 -0
- package/dist/better-auth/plugin/payload/utils/generate-admin-invite-url.js.map +1 -0
- package/dist/better-auth/plugin/payload/utils/get-safe-redirect.d.ts +1 -0
- package/dist/better-auth/plugin/payload/utils/get-safe-redirect.js +22 -0
- package/dist/better-auth/plugin/payload/utils/get-safe-redirect.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/admin-login/client.d.ts +19 -0
- package/dist/better-auth/plugin/payload/views/admin-login/client.js +226 -0
- package/dist/better-auth/plugin/payload/views/admin-login/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/admin-login/index.d.ts +10 -0
- package/dist/better-auth/plugin/payload/views/admin-login/index.js +150 -0
- package/dist/better-auth/plugin/payload/views/admin-login/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/client.d.ts +16 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/client.js +299 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/index.d.ts +9 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/index.js +104 -0
- package/dist/better-auth/plugin/payload/views/admin-signup/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/client.d.ts +7 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/client.js +119 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/index.d.ts +8 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/index.js +78 -0
- package/dist/better-auth/plugin/payload/views/forgot-password/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/reset-password/client.d.ts +10 -0
- package/dist/better-auth/plugin/payload/views/reset-password/client.js +144 -0
- package/dist/better-auth/plugin/payload/views/reset-password/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/reset-password/index.d.ts +8 -0
- package/dist/better-auth/plugin/payload/views/reset-password/index.js +96 -0
- package/dist/better-auth/plugin/payload/views/reset-password/index.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/client.d.ts +6 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/client.js +96 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/client.js.map +1 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/index.d.ts +9 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/index.js +56 -0
- package/dist/better-auth/plugin/payload/views/two-factor-verify/index.js.map +1 -0
- package/dist/better-auth/plugin/types.d.ts +429 -0
- package/dist/better-auth/plugin/types.js +3 -0
- package/dist/better-auth/plugin/types.js.map +1 -0
- package/dist/better-auth/plugin/utils/set.d.ts +39 -0
- package/dist/better-auth/plugin/utils/set.js +103 -0
- package/dist/better-auth/plugin/utils/set.js.map +1 -0
- package/dist/better-auth/scripts/generate-types.d.ts +1 -0
- package/dist/better-auth/scripts/generate-types.js +234 -0
- package/dist/better-auth/scripts/generate-types.js.map +1 -0
- package/dist/better-auth/types.d.ts +2 -0
- package/dist/better-auth/types.js +4 -0
- package/dist/better-auth/types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/components/icons.d.ts +7 -0
- package/dist/shared/components/icons.js +442 -0
- package/dist/shared/components/icons.js.map +1 -0
- package/dist/shared/components/logo.d.ts +3 -0
- package/dist/shared/components/logo.js +24 -0
- package/dist/shared/components/logo.js.map +1 -0
- package/dist/shared/form/components/submit.d.ts +7 -0
- package/dist/shared/form/components/submit.js +16 -0
- package/dist/shared/form/components/submit.js.map +1 -0
- package/dist/shared/form/fields/text-field.d.ts +8 -0
- package/dist/shared/form/fields/text-field.js +37 -0
- package/dist/shared/form/fields/text-field.js.map +1 -0
- package/dist/shared/form/index.d.ts +4 -0
- package/dist/shared/form/index.js +8 -0
- package/dist/shared/form/index.js.map +1 -0
- package/dist/shared/form/ui/header/index.d.ts +8 -0
- package/dist/shared/form/ui/header/index.js +24 -0
- package/dist/shared/form/ui/header/index.js.map +1 -0
- package/dist/shared/form/ui/index.d.ts +31 -0
- package/dist/shared/form/ui/index.js +57 -0
- package/dist/shared/form/ui/index.js.map +1 -0
- package/dist/shared/form/validation.d.ts +51 -0
- package/dist/shared/form/validation.js +127 -0
- package/dist/shared/form/validation.js.map +1 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/payload/fields/field-copy-button/index.d.ts +3 -0
- package/dist/shared/payload/fields/field-copy-button/index.js +38 -0
- package/dist/shared/payload/fields/field-copy-button/index.js.map +1 -0
- package/dist/shared/payload/fields/generate-uuid-button/index.d.ts +3 -0
- package/dist/shared/payload/fields/generate-uuid-button/index.js +26 -0
- package/dist/shared/payload/fields/generate-uuid-button/index.js.map +1 -0
- package/dist/shared/payload/fields/index.d.ts +2 -0
- package/dist/shared/payload/fields/index.js +4 -0
- package/dist/shared/payload/fields/index.js.map +1 -0
- package/dist/shared/utils/regex.d.ts +2 -0
- package/dist/shared/utils/regex.js +4 -0
- package/dist/shared/utils/regex.js.map +1 -0
- package/dist/shared/utils/try-catch.d.ts +11 -0
- package/dist/shared/utils/try-catch.js +17 -0
- package/dist/shared/utils/try-catch.js.map +1 -0
- package/dist/shared/utils/value-or-default.d.ts +9 -0
- package/dist/shared/utils/value-or-default.js +12 -0
- package/dist/shared/utils/value-or-default.js.map +1 -0
- package/package.json +122 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { baModelFieldKeysToFieldNames, baModelKey, defaults } from "../../constants";
|
|
2
|
+
import { getAdminAccess } from "../../helpers/get-admin-access";
|
|
3
|
+
import { assertAllSchemaFields, getSchemaCollectionSlug, getSchemaFieldName } from "./utils/collection-schema";
|
|
4
|
+
import { filterDuplicateFields } from "./utils/filter-duplicate-fields";
|
|
5
|
+
import { isAdminOrCurrentUserWithRoles } from "./utils/payload-access";
|
|
6
|
+
import { getCollectionFields } from "./utils/transform-schema-fields-to-payload";
|
|
7
|
+
export function buildPasskeysCollection({ incomingCollections, pluginOptions, resolvedSchemas }) {
|
|
8
|
+
const passkeySlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.passkey);
|
|
9
|
+
const passkeySchema = resolvedSchemas[baModelKey.passkey];
|
|
10
|
+
const userIdFieldName = passkeySchema?.fields?.userId?.fieldName ?? baModelFieldKeysToFieldNames.passkey.userId;
|
|
11
|
+
const adminRoles = pluginOptions.users?.adminRoles ?? [
|
|
12
|
+
defaults.adminRole
|
|
13
|
+
];
|
|
14
|
+
const existingPasskeyCollection = incomingCollections.find((collection)=>collection.slug === passkeySlug);
|
|
15
|
+
const fieldOverrides = {
|
|
16
|
+
name: ()=>({
|
|
17
|
+
admin: {
|
|
18
|
+
readOnly: true,
|
|
19
|
+
description: 'The name of the passkey'
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
publicKey: ()=>({
|
|
23
|
+
index: true,
|
|
24
|
+
admin: {
|
|
25
|
+
readOnly: true,
|
|
26
|
+
description: 'The public key of the passkey'
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
userId: ()=>({
|
|
30
|
+
index: true,
|
|
31
|
+
admin: {
|
|
32
|
+
readOnly: true,
|
|
33
|
+
description: 'The user that the passkey belongs to'
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
credentialID: ()=>({
|
|
37
|
+
admin: {
|
|
38
|
+
readOnly: true,
|
|
39
|
+
description: 'The unique identifier of the registered credential'
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
counter: ()=>({
|
|
43
|
+
required: true,
|
|
44
|
+
admin: {
|
|
45
|
+
readOnly: true,
|
|
46
|
+
description: 'The counter of the passkey'
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
49
|
+
deviceType: ()=>({
|
|
50
|
+
required: true,
|
|
51
|
+
admin: {
|
|
52
|
+
readOnly: true,
|
|
53
|
+
description: 'The type of device used to register the passkey'
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
backedUp: ()=>({
|
|
57
|
+
required: true,
|
|
58
|
+
admin: {
|
|
59
|
+
readOnly: true,
|
|
60
|
+
description: 'Whether the passkey is backed up'
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
transports: ()=>({
|
|
64
|
+
required: true,
|
|
65
|
+
admin: {
|
|
66
|
+
readOnly: true,
|
|
67
|
+
description: 'The transports used to register the passkey'
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
const collectionFields = getCollectionFields({
|
|
72
|
+
schema: passkeySchema,
|
|
73
|
+
additionalProperties: fieldOverrides
|
|
74
|
+
});
|
|
75
|
+
let passkeyCollection = {
|
|
76
|
+
...existingPasskeyCollection,
|
|
77
|
+
slug: passkeySlug,
|
|
78
|
+
admin: {
|
|
79
|
+
hidden: pluginOptions.hidePluginCollections ?? false,
|
|
80
|
+
useAsTitle: getSchemaFieldName(resolvedSchemas, baModelKey.passkey, 'name'),
|
|
81
|
+
description: 'Passkeys are used to authenticate users',
|
|
82
|
+
group: pluginOptions?.collectionAdminGroup ?? 'Auth',
|
|
83
|
+
...existingPasskeyCollection?.admin
|
|
84
|
+
},
|
|
85
|
+
access: {
|
|
86
|
+
...getAdminAccess(pluginOptions),
|
|
87
|
+
read: isAdminOrCurrentUserWithRoles({
|
|
88
|
+
idField: userIdFieldName,
|
|
89
|
+
adminRoles
|
|
90
|
+
}),
|
|
91
|
+
delete: isAdminOrCurrentUserWithRoles({
|
|
92
|
+
idField: userIdFieldName,
|
|
93
|
+
adminRoles
|
|
94
|
+
}),
|
|
95
|
+
...existingPasskeyCollection?.access ?? {}
|
|
96
|
+
},
|
|
97
|
+
custom: {
|
|
98
|
+
...existingPasskeyCollection?.custom ?? {},
|
|
99
|
+
betterAuthModelKey: baModelKey.passkey
|
|
100
|
+
},
|
|
101
|
+
fields: [
|
|
102
|
+
...existingPasskeyCollection?.fields ?? [],
|
|
103
|
+
...filterDuplicateFields(existingPasskeyCollection?.fields, collectionFields)
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
if (typeof pluginOptions.pluginCollectionOverrides?.passkeys === 'function') {
|
|
107
|
+
passkeyCollection = pluginOptions.pluginCollectionOverrides.passkeys({
|
|
108
|
+
collection: passkeyCollection
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
assertAllSchemaFields(passkeyCollection, passkeySchema);
|
|
112
|
+
return passkeyCollection;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=passkeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/build-collections/passkeys.ts"],"sourcesContent":["import type { Passkey } from '@/better-auth/generated-types';\nimport type { BuildCollectionProps, FieldOverrides } from '@/better-auth/plugin/types';\nimport type { CollectionConfig } from 'payload';\nimport { baModelFieldKeysToFieldNames, baModelKey, defaults } from '../../constants';\nimport { getAdminAccess } from '../../helpers/get-admin-access';\nimport {\n assertAllSchemaFields,\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from './utils/collection-schema';\nimport { filterDuplicateFields } from './utils/filter-duplicate-fields';\nimport { isAdminOrCurrentUserWithRoles } from './utils/payload-access';\nimport { getCollectionFields } from './utils/transform-schema-fields-to-payload';\n\nexport function buildPasskeysCollection({\n incomingCollections,\n pluginOptions,\n resolvedSchemas,\n}: BuildCollectionProps): CollectionConfig {\n const passkeySlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.passkey);\n const passkeySchema = resolvedSchemas[baModelKey.passkey];\n const userIdFieldName =\n passkeySchema?.fields?.userId?.fieldName ?? baModelFieldKeysToFieldNames.passkey.userId;\n const adminRoles = pluginOptions.users?.adminRoles ?? [defaults.adminRole];\n\n const existingPasskeyCollection = incomingCollections.find(\n collection => collection.slug === passkeySlug\n ) as CollectionConfig | undefined;\n\n const fieldOverrides: FieldOverrides<keyof Passkey> = {\n name: () => ({\n admin: { readOnly: true, description: 'The name of the passkey' },\n }),\n publicKey: () => ({\n index: true,\n admin: { readOnly: true, description: 'The public key of the passkey' },\n }),\n userId: () => ({\n index: true,\n admin: { readOnly: true, description: 'The user that the passkey belongs to' },\n }),\n credentialID: () => ({\n admin: { readOnly: true, description: 'The unique identifier of the registered credential' },\n }),\n counter: () => ({\n required: true,\n admin: { readOnly: true, description: 'The counter of the passkey' },\n }),\n deviceType: () => ({\n required: true,\n admin: { readOnly: true, description: 'The type of device used to register the passkey' },\n }),\n backedUp: () => ({\n required: true,\n admin: { readOnly: true, description: 'Whether the passkey is backed up' },\n }),\n transports: () => ({\n required: true,\n admin: { readOnly: true, description: 'The transports used to register the passkey' },\n }),\n };\n\n const collectionFields = getCollectionFields({\n schema: passkeySchema,\n additionalProperties: fieldOverrides,\n });\n\n let passkeyCollection: CollectionConfig = {\n ...existingPasskeyCollection,\n slug: passkeySlug,\n admin: {\n hidden: pluginOptions.hidePluginCollections ?? false,\n useAsTitle: getSchemaFieldName(resolvedSchemas, baModelKey.passkey, 'name'),\n description: 'Passkeys are used to authenticate users',\n group: pluginOptions?.collectionAdminGroup ?? 'Auth',\n ...existingPasskeyCollection?.admin,\n },\n access: {\n ...getAdminAccess(pluginOptions),\n read: isAdminOrCurrentUserWithRoles({\n idField: userIdFieldName,\n adminRoles,\n }),\n delete: isAdminOrCurrentUserWithRoles({\n idField: userIdFieldName,\n adminRoles,\n }),\n ...(existingPasskeyCollection?.access ?? {}),\n },\n custom: {\n ...(existingPasskeyCollection?.custom ?? {}),\n betterAuthModelKey: baModelKey.passkey,\n },\n fields: [\n ...(existingPasskeyCollection?.fields ?? []),\n ...filterDuplicateFields(existingPasskeyCollection?.fields, collectionFields),\n ],\n };\n\n if (typeof pluginOptions.pluginCollectionOverrides?.passkeys === 'function') {\n passkeyCollection = pluginOptions.pluginCollectionOverrides.passkeys({\n collection: passkeyCollection,\n });\n }\n\n assertAllSchemaFields(passkeyCollection, passkeySchema);\n\n return passkeyCollection;\n}\n"],"names":["baModelFieldKeysToFieldNames","baModelKey","defaults","getAdminAccess","assertAllSchemaFields","getSchemaCollectionSlug","getSchemaFieldName","filterDuplicateFields","isAdminOrCurrentUserWithRoles","getCollectionFields","buildPasskeysCollection","incomingCollections","pluginOptions","resolvedSchemas","passkeySlug","passkey","passkeySchema","userIdFieldName","fields","userId","fieldName","adminRoles","users","adminRole","existingPasskeyCollection","find","collection","slug","fieldOverrides","name","admin","readOnly","description","publicKey","index","credentialID","counter","required","deviceType","backedUp","transports","collectionFields","schema","additionalProperties","passkeyCollection","hidden","hidePluginCollections","useAsTitle","group","collectionAdminGroup","access","read","idField","delete","custom","betterAuthModelKey","pluginCollectionOverrides","passkeys"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,kBAAkB;AACrF,SAASC,cAAc,QAAQ,iCAAiC;AAChE,SACEC,qBAAqB,EACrBC,uBAAuB,EACvBC,kBAAkB,QACb,4BAA4B;AACnC,SAASC,qBAAqB,QAAQ,kCAAkC;AACxE,SAASC,6BAA6B,QAAQ,yBAAyB;AACvE,SAASC,mBAAmB,QAAQ,6CAA6C;AAEjF,OAAO,SAASC,wBAAwB,EACtCC,mBAAmB,EACnBC,aAAa,EACbC,eAAe,EACM;IACrB,MAAMC,cAAcT,wBAAwBQ,iBAAiBZ,WAAWc,OAAO;IAC/E,MAAMC,gBAAgBH,eAAe,CAACZ,WAAWc,OAAO,CAAC;IACzD,MAAME,kBACJD,eAAeE,QAAQC,QAAQC,aAAapB,6BAA6Be,OAAO,CAACI,MAAM;IACzF,MAAME,aAAaT,cAAcU,KAAK,EAAED,cAAc;QAACnB,SAASqB,SAAS;KAAC;IAE1E,MAAMC,4BAA4Bb,oBAAoBc,IAAI,CACxDC,CAAAA,aAAcA,WAAWC,IAAI,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gBACTI;YACF;YACAgC,QAAQ7C,8BAA8B;gBACpC4C,SAASnC;gBACTI;YACF;YACA,GAAIG,2BAA2B0B,UAAU,CAAC,CAAC;QAC7C;QACAI,QAAQ;YACN,GAAI9B,2BAA2B8B,UAAU,CAAC,CAAC;YAC3CC,oBAAoBtD,WAAWc,OAAO;QACxC;QACAG,QAAQ;eACFM,2BAA2BN,UAAU,EAAE;eACxCX,sBAAsBiB,2BAA2BN,QAAQuB;SAC7D;IACH;IAEA,IAAI,OAAO7B,cAAc4C,yBAAyB,EAAEC,aAAa,YAAY;QAC3Eb,oBAAoBhC,cAAc4C,yBAAyB,CAACC,QAAQ,CAAC;YACnE/B,YAAYkB;QACd;IACF;IAEAxC,sBAAsBwC,mBAAmB5B;IAEzC,OAAO4B;AACT"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { baModelKey, baseSlugs } from "../../constants";
|
|
2
|
+
import { getAdminAccess } from "../../helpers/get-admin-access";
|
|
3
|
+
import { getDefaultCollectionSlug } from "../../helpers/get-collection-slug";
|
|
4
|
+
import { assertAllSchemaFields, getSchemaCollectionSlug } from "./utils/collection-schema";
|
|
5
|
+
import { filterDuplicateFields } from "./utils/filter-duplicate-fields";
|
|
6
|
+
import { getCollectionFields } from "./utils/transform-schema-fields-to-payload";
|
|
7
|
+
export function buildSessionsCollection({ incomingCollections, pluginOptions, resolvedSchemas }) {
|
|
8
|
+
const sessionSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.session);
|
|
9
|
+
const sessionSchema = resolvedSchemas[baModelKey.session];
|
|
10
|
+
const existingSessionCollection = incomingCollections.find((collection)=>collection.slug === sessionSlug);
|
|
11
|
+
const fieldOverrides = {
|
|
12
|
+
userId: ()=>({
|
|
13
|
+
index: true,
|
|
14
|
+
saveToJWT: true,
|
|
15
|
+
admin: {
|
|
16
|
+
readOnly: true,
|
|
17
|
+
description: 'The user that the session belongs to'
|
|
18
|
+
},
|
|
19
|
+
relationTo: getDefaultCollectionSlug({
|
|
20
|
+
modelKey: baModelKey.user,
|
|
21
|
+
pluginOptions
|
|
22
|
+
})
|
|
23
|
+
}),
|
|
24
|
+
token: ()=>({
|
|
25
|
+
index: true,
|
|
26
|
+
saveToJWT: true,
|
|
27
|
+
admin: {
|
|
28
|
+
readOnly: true,
|
|
29
|
+
description: 'The unique session token'
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
expiresAt: ()=>({
|
|
33
|
+
saveToJWT: true,
|
|
34
|
+
admin: {
|
|
35
|
+
readOnly: true,
|
|
36
|
+
description: 'The date and time when the session will expire'
|
|
37
|
+
}
|
|
38
|
+
}),
|
|
39
|
+
ipAddress: ()=>({
|
|
40
|
+
saveToJWT: true,
|
|
41
|
+
admin: {
|
|
42
|
+
readOnly: true,
|
|
43
|
+
description: 'The IP address of the device'
|
|
44
|
+
}
|
|
45
|
+
}),
|
|
46
|
+
userAgent: ()=>({
|
|
47
|
+
saveToJWT: true,
|
|
48
|
+
admin: {
|
|
49
|
+
readOnly: true,
|
|
50
|
+
description: 'The user agent information of the device'
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
impersonatedBy: ()=>({
|
|
54
|
+
type: 'relationship',
|
|
55
|
+
relationTo: pluginOptions.users?.slug ?? baseSlugs.users,
|
|
56
|
+
required: false,
|
|
57
|
+
saveToJWT: true,
|
|
58
|
+
admin: {
|
|
59
|
+
readOnly: true,
|
|
60
|
+
description: 'The admin who is impersonating this session'
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
activeOrganizationId: ()=>({
|
|
64
|
+
type: 'relationship',
|
|
65
|
+
saveToJWT: true,
|
|
66
|
+
relationTo: getDefaultCollectionSlug({
|
|
67
|
+
modelKey: baModelKey.organization,
|
|
68
|
+
pluginOptions
|
|
69
|
+
}),
|
|
70
|
+
admin: {
|
|
71
|
+
readOnly: true,
|
|
72
|
+
description: 'The currently active organization for the session'
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
activeTeamId: ()=>({
|
|
76
|
+
type: 'relationship',
|
|
77
|
+
saveToJWT: true,
|
|
78
|
+
relationTo: getDefaultCollectionSlug({
|
|
79
|
+
modelKey: baModelKey.team,
|
|
80
|
+
pluginOptions
|
|
81
|
+
}),
|
|
82
|
+
admin: {
|
|
83
|
+
readOnly: true,
|
|
84
|
+
description: 'The currently active team for the session'
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
};
|
|
88
|
+
const sessionFieldRules = [
|
|
89
|
+
{
|
|
90
|
+
condition: (field)=>field.fieldName === 'updatedAt' || field.fieldName === 'createdAt',
|
|
91
|
+
transform: (field)=>({
|
|
92
|
+
...field,
|
|
93
|
+
saveToJWT: false,
|
|
94
|
+
admin: {
|
|
95
|
+
disableBulkEdit: true,
|
|
96
|
+
hidden: true
|
|
97
|
+
},
|
|
98
|
+
index: true,
|
|
99
|
+
// Using any because PayloadCMS label function receives translation function with dynamic type
|
|
100
|
+
label: ({ t })=>t('general:updatedAt')
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
// Get collection fields from Better Auth schema
|
|
105
|
+
let collectionFields = getCollectionFields({
|
|
106
|
+
schema: sessionSchema,
|
|
107
|
+
fieldRules: sessionFieldRules,
|
|
108
|
+
additionalProperties: fieldOverrides
|
|
109
|
+
});
|
|
110
|
+
// Pre-filter userAgent field if it already exists in the collection
|
|
111
|
+
// This is a safety check before the main filterDuplicateFields call
|
|
112
|
+
if (existingSessionCollection?.fields) {
|
|
113
|
+
const hasUserAgentField = existingSessionCollection.fields.some((field)=>{
|
|
114
|
+
if ('name' in field && field.name === 'userAgent') {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
if (field.custom && typeof field.custom === 'object' && 'betterAuthFieldKey' in field.custom && field.custom.betterAuthFieldKey === 'userAgent') {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
});
|
|
122
|
+
if (hasUserAgentField && collectionFields) {
|
|
123
|
+
collectionFields = collectionFields.filter((field)=>{
|
|
124
|
+
if ('name' in field && field.name === 'userAgent') {
|
|
125
|
+
// Check if this is the Better Auth userAgent field
|
|
126
|
+
if (field.custom && typeof field.custom === 'object' && 'betterAuthFieldKey' in field.custom && field.custom.betterAuthFieldKey === 'userAgent') {
|
|
127
|
+
return false; // Filter out Better Auth's userAgent field
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let sessionCollection = {
|
|
135
|
+
...existingSessionCollection,
|
|
136
|
+
slug: sessionSlug,
|
|
137
|
+
admin: {
|
|
138
|
+
...pluginOptions.sessions?.hidden !== undefined && {
|
|
139
|
+
hidden: pluginOptions.sessions.hidden
|
|
140
|
+
},
|
|
141
|
+
description: 'Sessions are active sessions for users. They are used to authenticate users with a session token',
|
|
142
|
+
group: pluginOptions?.collectionAdminGroup ?? 'Auth',
|
|
143
|
+
...existingSessionCollection?.admin
|
|
144
|
+
},
|
|
145
|
+
access: {
|
|
146
|
+
...getAdminAccess(pluginOptions),
|
|
147
|
+
...existingSessionCollection?.access ?? {}
|
|
148
|
+
},
|
|
149
|
+
custom: {
|
|
150
|
+
...existingSessionCollection?.custom ?? {},
|
|
151
|
+
betterAuthModelKey: baModelKey.session
|
|
152
|
+
},
|
|
153
|
+
fields: [
|
|
154
|
+
...existingSessionCollection?.fields ?? [],
|
|
155
|
+
// Filter out fields that already exist to prevent duplicates
|
|
156
|
+
// Check both by name and betterAuthFieldKey to catch all duplicates
|
|
157
|
+
// This is critical to prevent "DuplicateFieldName" errors from PayloadCMS
|
|
158
|
+
...collectionFields ? filterDuplicateFields(existingSessionCollection?.fields, collectionFields) : []
|
|
159
|
+
]
|
|
160
|
+
};
|
|
161
|
+
if (typeof pluginOptions.sessions?.collectionOverrides === 'function') {
|
|
162
|
+
sessionCollection = pluginOptions.sessions.collectionOverrides({
|
|
163
|
+
collection: sessionCollection
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
assertAllSchemaFields(sessionCollection, sessionSchema);
|
|
167
|
+
return sessionCollection;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=sessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/build-collections/sessions.ts"],"sourcesContent":["import { baModelKey, baseSlugs } from '../../constants';\nimport { getAdminAccess } from '../../helpers/get-admin-access';\nimport { getDefaultCollectionSlug } from '../../helpers/get-collection-slug';\nimport { assertAllSchemaFields, getSchemaCollectionSlug } from './utils/collection-schema';\nimport { filterDuplicateFields } from './utils/filter-duplicate-fields';\nimport { getCollectionFields } from './utils/transform-schema-fields-to-payload';\n\nimport type { Session } from '@/better-auth/generated-types';\nimport type { BuildCollectionProps, FieldOverrides, FieldRule } from '@/better-auth/plugin/types';\nimport type { CollectionConfig, CollectionSlug } from 'payload';\n\nexport function buildSessionsCollection({\n incomingCollections,\n pluginOptions,\n resolvedSchemas,\n}: BuildCollectionProps): CollectionConfig {\n const sessionSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.session);\n const sessionSchema = resolvedSchemas[baModelKey.session];\n\n const existingSessionCollection = incomingCollections.find(\n collection => collection.slug === sessionSlug\n ) as CollectionConfig | undefined;\n\n const fieldOverrides: FieldOverrides<keyof Session> = {\n userId: () => ({\n index: true,\n saveToJWT: true,\n admin: { readOnly: true, description: 'The user that the session belongs to' },\n relationTo: getDefaultCollectionSlug({\n modelKey: baModelKey.user,\n pluginOptions,\n }) as CollectionSlug,\n }),\n token: () => ({\n index: true,\n saveToJWT: true,\n admin: { readOnly: true, description: 'The unique session token' },\n }),\n expiresAt: () => ({\n saveToJWT: true,\n admin: { readOnly: true, description: 'The date and time when the session will expire' },\n }),\n ipAddress: () => ({\n saveToJWT: true,\n admin: { readOnly: true, description: 'The IP address of the device' },\n }),\n userAgent: () => ({\n saveToJWT: true,\n admin: { readOnly: true, description: 'The user agent information of the device' },\n }),\n impersonatedBy: () => ({\n type: 'relationship',\n relationTo: (pluginOptions.users?.slug ?? baseSlugs.users) as CollectionSlug,\n required: false,\n saveToJWT: true,\n admin: {\n readOnly: true,\n description: 'The admin who is impersonating this session',\n },\n }),\n activeOrganizationId: () => ({\n type: 'relationship',\n saveToJWT: true,\n relationTo: getDefaultCollectionSlug({\n modelKey: baModelKey.organization,\n pluginOptions,\n }) as CollectionSlug,\n admin: {\n readOnly: true,\n description: 'The currently active organization for the session',\n },\n }),\n activeTeamId: () => ({\n type: 'relationship',\n saveToJWT: true,\n relationTo: getDefaultCollectionSlug({\n modelKey: baModelKey.team,\n pluginOptions,\n }) as CollectionSlug,\n admin: {\n readOnly: true,\n description: 'The currently active team for the session',\n },\n }),\n };\n\n const sessionFieldRules: FieldRule[] = [\n {\n condition: field => field.fieldName === 'updatedAt' || field.fieldName === 'createdAt',\n transform: field => ({\n ...field,\n saveToJWT: false,\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n index: true,\n // Using any because PayloadCMS label function receives translation function with dynamic type\n label: ({ t }: any) => t('general:updatedAt'),\n }),\n },\n ];\n\n // Get collection fields from Better Auth schema\n let collectionFields = getCollectionFields({\n schema: sessionSchema,\n fieldRules: sessionFieldRules,\n additionalProperties: fieldOverrides,\n });\n\n // Pre-filter userAgent field if it already exists in the collection\n // This is a safety check before the main filterDuplicateFields call\n if (existingSessionCollection?.fields) {\n const hasUserAgentField = existingSessionCollection.fields.some((field: any) => {\n if ('name' in field && field.name === 'userAgent') {\n return true;\n }\n if (\n field.custom &&\n typeof field.custom === 'object' &&\n 'betterAuthFieldKey' in field.custom &&\n (field.custom as { betterAuthFieldKey: string }).betterAuthFieldKey === 'userAgent'\n ) {\n return true;\n }\n return false;\n });\n\n if (hasUserAgentField && collectionFields) {\n collectionFields = collectionFields.filter((field: any) => {\n if ('name' in field && field.name === 'userAgent') {\n // Check if this is the Better Auth userAgent field\n if (\n field.custom &&\n typeof field.custom === 'object' &&\n 'betterAuthFieldKey' in field.custom &&\n (field.custom as { betterAuthFieldKey: string }).betterAuthFieldKey === 'userAgent'\n ) {\n return false; // Filter out Better Auth's userAgent field\n }\n }\n return true;\n });\n }\n }\n\n let sessionCollection: CollectionConfig = {\n ...existingSessionCollection,\n slug: sessionSlug,\n admin: {\n ...(pluginOptions.sessions?.hidden !== undefined && {\n hidden: pluginOptions.sessions.hidden,\n }),\n description:\n 'Sessions are active sessions for users. They are used to authenticate users with a session token',\n group: pluginOptions?.collectionAdminGroup ?? 'Auth',\n ...existingSessionCollection?.admin,\n },\n access: {\n ...getAdminAccess(pluginOptions),\n ...(existingSessionCollection?.access ?? {}),\n },\n custom: {\n ...(existingSessionCollection?.custom ?? {}),\n betterAuthModelKey: baModelKey.session,\n },\n fields: [\n ...(existingSessionCollection?.fields ?? []),\n // Filter out fields that already exist to prevent duplicates\n // Check both by name and betterAuthFieldKey to catch all duplicates\n // This is critical to prevent \"DuplicateFieldName\" errors from PayloadCMS\n ...(collectionFields\n ? filterDuplicateFields(existingSessionCollection?.fields, collectionFields)\n : []),\n ],\n };\n\n if (typeof pluginOptions.sessions?.collectionOverrides === 'function') {\n sessionCollection = pluginOptions.sessions.collectionOverrides({\n collection: sessionCollection,\n });\n }\n\n assertAllSchemaFields(sessionCollection, sessionSchema);\n\n return sessionCollection;\n}\n"],"names":["baModelKey","baseSlugs","getAdminAccess","getDefaultCollectionSlug","assertAllSchemaFields","getSchemaCollectionSlug","filterDuplicateFields","getCollectionFields","buildSessionsCollection","incomingCollections","pluginOptions","resolvedSchemas","sessionSlug","session","sessionSchema","existingSessionCollection","find","collection","slug","fieldOverrides","userId","index","saveToJWT","admin","readOnly","description","relationTo","modelKey","user","token","expiresAt","ipAddress","userAgent","impersonatedBy","type","users","required","activeOrganizationId","organization","activeTeamId","team","sessionFieldRules","condition","field","fieldName","transform","disableBulkEdit","hidden","label","t","collectionFields","schema","fieldRules","additionalProperties","fields","hasUserAgentField","some","name","custom","betterAuthFieldKey","filter","sessionCollection","sessions","undefined","group","collectionAdminGroup","access","betterAuthModelKey","collectionOverrides"],"mappings":"AAAA,SAASA,UAAU,EAAEC,SAAS,QAAQ,kBAAkB;AACxD,SAASC,cAAc,QAAQ,iCAAiC;AAChE,SAASC,wBAAwB,QAAQ,oCAAoC;AAC7E,SAASC,qBAAqB,EAAEC,uBAAuB,QAAQ,4BAA4B;AAC3F,SAASC,qBAAqB,QAAQ,kCAAkC;AACxE,SAASC,mBAAmB,QAAQ,6CAA6C;AAMjF,OAAO,SAASC,wBAAwB,EACtCC,mBAAmB,EACnBC,aAAa,EACbC,eAAe,EACM;IACrB,MAAMC,cAAcP,wBAAwBM,iBAAiBX,WAAWa,OAAO;IAC/E,MAAMC,gBAAgBH,eAAe,CAACX,WAAWa,OAAO,CAAC;IAEzD,MAAME,4BAA4BN,oBAAoBO,IAAI,CACxDC,CAAAA,aAAcA,WAAWC,IAAI,KAAKN;IAGpC,MAAMO,iBAAgD;QACpDC,QAAQ,IAAO,CAAA;gBACbC,OAAO;gBACPC,WAAW;gBACXC,OAAO;oBAAEC,UAAU;oBAAMC,aAAa;gBAAuC;gBAC7EC,YAAYvB,yBAAyB;oBACnCwB,UAAU3B,WAAW4B,IAAI;oBACzBlB;gBACF;YACF,CAAA;QACAmB,OAAO,IAAO,CAAA;gBACZR,OAAO;gBACPC,WAAW;gBACXC,OAAO;oBAAEC,UAAU;oBAAMC,aAAa;gBAA2B;YACnE,CAAA;QACAK,WAAW,IAAO,CAAA;gBAChBR,WAAW;gBACXC,OAAO;oBAAEC,UAAU;oBAAMC,aAAa;gBAAiD;YACzF,CAAA;QACAM,WAAW,IAAO,CAAA;gBAChBT,WAAW;gBACXC,OAAO;oBAAEC,UAAU;oBAAMC,aAAa;gBAA+B;YACvE,CAAA;QACAO,WAAW,IAAO,CAAA;gBAChBV,WAAW;gBACXC,OAAO;oBAAEC,UAAU;oBAAMC,aAAa;gBAA2C;YACnF,CAAA;QACAQ,gBAAgB,IAAO,CAA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AEzC,OAAO+C;AACT"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { baModelKey } from "../../constants";
|
|
2
|
+
import { getAdminAccess } from "../../helpers/get-admin-access";
|
|
3
|
+
import { assertAllSchemaFields, getSchemaCollectionSlug, getSchemaFieldName } from "./utils/collection-schema";
|
|
4
|
+
import { filterDuplicateFields } from "./utils/filter-duplicate-fields";
|
|
5
|
+
import { getCollectionFields } from "./utils/transform-schema-fields-to-payload";
|
|
6
|
+
export function buildSsoProvidersCollection({ incomingCollections, pluginOptions, resolvedSchemas }) {
|
|
7
|
+
const ssoProviderSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.ssoProvider);
|
|
8
|
+
const ssoProviderSchema = resolvedSchemas[baModelKey.ssoProvider];
|
|
9
|
+
const existingSsoProviderCollection = incomingCollections.find((collection)=>collection.slug === ssoProviderSlug);
|
|
10
|
+
const fieldOverrides = {
|
|
11
|
+
issuer: ()=>({
|
|
12
|
+
index: true,
|
|
13
|
+
admin: {
|
|
14
|
+
description: 'The issuer of the SSO provider'
|
|
15
|
+
}
|
|
16
|
+
}),
|
|
17
|
+
domain: ()=>({
|
|
18
|
+
admin: {
|
|
19
|
+
description: 'The domain of the SSO provider'
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
oidcConfig: ()=>({
|
|
23
|
+
admin: {
|
|
24
|
+
description: 'The OIDC config of the SSO provider'
|
|
25
|
+
}
|
|
26
|
+
}),
|
|
27
|
+
userId: ()=>({
|
|
28
|
+
admin: {
|
|
29
|
+
description: 'The user associated with the SSO provider'
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
providerId: ()=>({
|
|
33
|
+
admin: {
|
|
34
|
+
readOnly: true,
|
|
35
|
+
description: 'The provider id. Used to identify a provider and to generate a redirect url'
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
organizationId: ()=>({
|
|
39
|
+
admin: {
|
|
40
|
+
readOnly: true,
|
|
41
|
+
description: 'The organization Id. If provider is linked to an organization'
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
const collectionFields = getCollectionFields({
|
|
46
|
+
schema: ssoProviderSchema,
|
|
47
|
+
additionalProperties: fieldOverrides
|
|
48
|
+
});
|
|
49
|
+
let ssoProviderCollection = {
|
|
50
|
+
...existingSsoProviderCollection,
|
|
51
|
+
slug: ssoProviderSlug,
|
|
52
|
+
admin: {
|
|
53
|
+
hidden: pluginOptions.hidePluginCollections ?? false,
|
|
54
|
+
useAsTitle: getSchemaFieldName(resolvedSchemas, baModelKey.ssoProvider, 'issuer'),
|
|
55
|
+
description: 'SSO providers are used to authenticate users with an external provider',
|
|
56
|
+
group: pluginOptions?.collectionAdminGroup ?? 'Auth',
|
|
57
|
+
...existingSsoProviderCollection?.admin
|
|
58
|
+
},
|
|
59
|
+
access: {
|
|
60
|
+
...getAdminAccess(pluginOptions),
|
|
61
|
+
...existingSsoProviderCollection?.access ?? {}
|
|
62
|
+
},
|
|
63
|
+
custom: {
|
|
64
|
+
...existingSsoProviderCollection?.custom ?? {},
|
|
65
|
+
betterAuthModelKey: baModelKey.ssoProvider
|
|
66
|
+
},
|
|
67
|
+
fields: [
|
|
68
|
+
...existingSsoProviderCollection?.fields ?? [],
|
|
69
|
+
...filterDuplicateFields(existingSsoProviderCollection?.fields, collectionFields)
|
|
70
|
+
]
|
|
71
|
+
};
|
|
72
|
+
if (typeof pluginOptions.pluginCollectionOverrides?.ssoProviders === 'function') {
|
|
73
|
+
ssoProviderCollection = pluginOptions.pluginCollectionOverrides.ssoProviders({
|
|
74
|
+
collection: ssoProviderCollection
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
assertAllSchemaFields(ssoProviderCollection, ssoProviderSchema);
|
|
78
|
+
return ssoProviderCollection;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=sso-providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/build-collections/sso-providers.ts"],"sourcesContent":["import { baModelKey } from '../../constants';\nimport { getAdminAccess } from '../../helpers/get-admin-access';\nimport {\n assertAllSchemaFields,\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from './utils/collection-schema';\nimport { filterDuplicateFields } from './utils/filter-duplicate-fields';\nimport { getCollectionFields } from './utils/transform-schema-fields-to-payload';\n\nimport type { SsoProvider } from '@/better-auth/generated-types';\nimport type { BuildCollectionProps, FieldOverrides } from '@/better-auth/plugin/types';\nimport type { CollectionConfig } from 'payload';\n\nexport function buildSsoProvidersCollection({\n incomingCollections,\n pluginOptions,\n resolvedSchemas,\n}: BuildCollectionProps): CollectionConfig {\n const ssoProviderSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.ssoProvider);\n const ssoProviderSchema = resolvedSchemas[baModelKey.ssoProvider];\n\n const existingSsoProviderCollection = incomingCollections.find(\n collection => collection.slug === ssoProviderSlug\n ) as CollectionConfig | undefined;\n\n const fieldOverrides: FieldOverrides<keyof SsoProvider> = {\n issuer: () => ({\n index: true,\n admin: { description: 'The issuer of the SSO provider' },\n }),\n domain: () => ({\n admin: { description: 'The domain of the SSO provider' },\n }),\n oidcConfig: () => ({\n admin: { description: 'The OIDC config of the SSO provider' },\n }),\n userId: () => ({\n admin: { description: 'The user associated with the SSO provider' },\n }),\n providerId: () => ({\n admin: {\n readOnly: true,\n description: 'The provider id. Used to identify a provider and to generate a redirect url',\n },\n }),\n organizationId: () => ({\n admin: {\n readOnly: true,\n description: 'The organization Id. If provider is linked to an organization',\n },\n }),\n };\n\n const collectionFields = getCollectionFields({\n schema: ssoProviderSchema,\n additionalProperties: fieldOverrides,\n });\n\n let ssoProviderCollection: CollectionConfig = {\n ...existingSsoProviderCollection,\n slug: ssoProviderSlug,\n admin: {\n hidden: pluginOptions.hidePluginCollections ?? false,\n useAsTitle: getSchemaFieldName(resolvedSchemas, baModelKey.ssoProvider, 'issuer'),\n description: 'SSO providers are used to authenticate users with an external provider',\n group: pluginOptions?.collectionAdminGroup ?? 'Auth',\n ...existingSsoProviderCollection?.admin,\n },\n access: {\n ...getAdminAccess(pluginOptions),\n ...(existingSsoProviderCollection?.access ?? {}),\n },\n custom: {\n ...(existingSsoProviderCollection?.custom ?? {}),\n betterAuthModelKey: baModelKey.ssoProvider,\n },\n fields: [\n ...(existingSsoProviderCollection?.fields ?? []),\n ...filterDuplicateFields(existingSsoProviderCollection?.fields, collectionFields),\n ],\n };\n\n if (typeof pluginOptions.pluginCollectionOverrides?.ssoProviders === 'function') {\n ssoProviderCollection = pluginOptions.pluginCollectionOverrides.ssoProviders({\n collection: ssoProviderCollection,\n });\n }\n\n assertAllSchemaFields(ssoProviderCollection, ssoProviderSchema);\n\n return ssoProviderCollection;\n}\n"],"names":["baModelKey","getAdminAccess","assertAllSchemaFields","getSchemaCollectionSlug","getSchemaFieldName","filterDuplicateFields","getCollectionFields","buildSsoProvidersCollection","incomingCollections","pluginOptions","resolvedSchemas","ssoProviderSlug","ssoProvider","ssoProviderSchema","existingSsoProviderCollection","find","collection","slug","fieldOverrides","issuer","index","admin","description","domain","oidcConfig","userId","providerId","readOnly","organizationId","collectionFields","schema","additionalProperties","ssoProviderCollection","hidden","hidePluginCollections","useAsTitle","group","collectionAdminGroup","access","custom","betterAuthModelKey","fields","pluginCollectionOverrides","ssoProviders"],"mappings":"AAAA,SAASA,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,cAAc,QAAQ,iCAAiC;AAChE,SACEC,qBAAqB,EACrBC,uBAAuB,EACvBC,kBAAkB,QACb,4BAA4B;AACnC,SAASC,qBAAqB,QAAQ,kCAAkC;AACxE,SAASC,mBAAmB,QAAQ,6CAA6C;AAMjF,OAAO,SAASC,4BAA4B,EAC1CC,mBAAmB,EACnBC,aAAa,EACbC,eAAe,EACM;IACrB,MAAMC,kBAAkBR,wBAAwBO,iBAAiBV,WAAWY,WAAW;IACvF,MAAMC,oBAAoBH,eAAe,CAACV,WAAWY,WAAW,CAA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BAAiB,YAAY;QAC/EX,wBAAwBvB,cAAciC,yBAAyB,CAACC,YAAY,CAAC;YAC3E3B,YAAYgB;QACd;IACF;IAEA9B,sBAAsB8B,uBAAuBnB;IAE7C,OAAOmB;AACT"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BuildCollectionProps } from '@/better-auth/plugin/types';
|
|
2
|
+
import type { CollectionConfig } from 'payload';
|
|
3
|
+
export declare function buildSubscriptionsCollection({ incomingCollections, pluginOptions, resolvedSchemas, }: BuildCollectionProps): CollectionConfig;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { baModelKey } from "../../constants";
|
|
2
|
+
import { getAdminAccess } from "../../helpers/get-admin-access";
|
|
3
|
+
import { assertAllSchemaFields, getSchemaCollectionSlug, getSchemaFieldName } from "./utils/collection-schema";
|
|
4
|
+
import { filterDuplicateFields } from "./utils/filter-duplicate-fields";
|
|
5
|
+
import { getCollectionFields } from "./utils/transform-schema-fields-to-payload";
|
|
6
|
+
export function buildSubscriptionsCollection({ incomingCollections, pluginOptions, resolvedSchemas }) {
|
|
7
|
+
const subscriptionsSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.subscription);
|
|
8
|
+
const subscriptionsSchema = resolvedSchemas[baModelKey.subscription];
|
|
9
|
+
const existingSubscriptionCollection = incomingCollections.find((collection)=>collection.slug === subscriptionsSlug);
|
|
10
|
+
const fieldOverrides = {
|
|
11
|
+
plan: ()=>({
|
|
12
|
+
index: true,
|
|
13
|
+
admin: {
|
|
14
|
+
readOnly: true,
|
|
15
|
+
description: 'The name of the subscription plan'
|
|
16
|
+
}
|
|
17
|
+
}),
|
|
18
|
+
referenceId: ()=>({
|
|
19
|
+
index: true,
|
|
20
|
+
admin: {
|
|
21
|
+
readOnly: true,
|
|
22
|
+
description: 'The ID this subscription is associated with (user ID by default)'
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
stripeCustomerId: ()=>({
|
|
26
|
+
index: true,
|
|
27
|
+
admin: {
|
|
28
|
+
readOnly: true,
|
|
29
|
+
description: 'The Stripe customer ID'
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
stripeSubscriptionId: ()=>({
|
|
33
|
+
index: true,
|
|
34
|
+
admin: {
|
|
35
|
+
readOnly: true,
|
|
36
|
+
description: 'The Stripe subscription ID'
|
|
37
|
+
}
|
|
38
|
+
}),
|
|
39
|
+
status: ()=>({
|
|
40
|
+
index: true,
|
|
41
|
+
admin: {
|
|
42
|
+
description: 'The status of the subscription (active, canceled, etc.)'
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
periodStart: ()=>({
|
|
46
|
+
admin: {
|
|
47
|
+
description: 'Start date of the current billing period'
|
|
48
|
+
}
|
|
49
|
+
}),
|
|
50
|
+
periodEnd: ()=>({
|
|
51
|
+
admin: {
|
|
52
|
+
description: 'End date of the current billing period'
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
cancelAtPeriodEnd: ()=>({
|
|
56
|
+
admin: {
|
|
57
|
+
description: 'Whether the subscription will be canceled at the end of the period'
|
|
58
|
+
}
|
|
59
|
+
}),
|
|
60
|
+
seats: ()=>({
|
|
61
|
+
admin: {
|
|
62
|
+
description: 'Number of seats for team plans'
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
65
|
+
trialStart: ()=>({
|
|
66
|
+
admin: {
|
|
67
|
+
description: 'Start date of the trial period'
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
trialEnd: ()=>({
|
|
71
|
+
admin: {
|
|
72
|
+
description: 'End date of the trial period'
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
const collectionFields = getCollectionFields({
|
|
77
|
+
schema: subscriptionsSchema,
|
|
78
|
+
additionalProperties: fieldOverrides
|
|
79
|
+
});
|
|
80
|
+
let subscriptionsCollection = {
|
|
81
|
+
...existingSubscriptionCollection,
|
|
82
|
+
slug: subscriptionsSlug,
|
|
83
|
+
admin: {
|
|
84
|
+
useAsTitle: getSchemaFieldName(resolvedSchemas, baModelKey.subscription, 'plan'),
|
|
85
|
+
description: 'Subscriptions are used to manage the subscriptions of the users',
|
|
86
|
+
group: pluginOptions?.collectionAdminGroup ?? 'Auth',
|
|
87
|
+
...existingSubscriptionCollection?.admin
|
|
88
|
+
},
|
|
89
|
+
access: {
|
|
90
|
+
...getAdminAccess(pluginOptions),
|
|
91
|
+
...existingSubscriptionCollection?.access ?? {}
|
|
92
|
+
},
|
|
93
|
+
custom: {
|
|
94
|
+
...existingSubscriptionCollection?.custom ?? {},
|
|
95
|
+
betterAuthModelKey: baModelKey.subscription
|
|
96
|
+
},
|
|
97
|
+
fields: [
|
|
98
|
+
...existingSubscriptionCollection?.fields ?? [],
|
|
99
|
+
...filterDuplicateFields(existingSubscriptionCollection?.fields, collectionFields)
|
|
100
|
+
]
|
|
101
|
+
};
|
|
102
|
+
if (typeof pluginOptions.pluginCollectionOverrides?.subscriptions === 'function') {
|
|
103
|
+
subscriptionsCollection = pluginOptions.pluginCollectionOverrides.subscriptions({
|
|
104
|
+
collection: subscriptionsCollection
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
assertAllSchemaFields(subscriptionsCollection, subscriptionsSchema);
|
|
108
|
+
return subscriptionsCollection;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=subscriptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/better-auth/plugin/lib/build-collections/subscriptions.ts"],"sourcesContent":["import { baModelKey } from '../../constants';\nimport { getAdminAccess } from '../../helpers/get-admin-access';\nimport {\n assertAllSchemaFields,\n getSchemaCollectionSlug,\n getSchemaFieldName,\n} from './utils/collection-schema';\nimport { filterDuplicateFields } from './utils/filter-duplicate-fields';\nimport { getCollectionFields } from './utils/transform-schema-fields-to-payload';\n\nimport type { Subscription } from '@/better-auth/generated-types';\nimport type { BuildCollectionProps, FieldOverrides } from '@/better-auth/plugin/types';\nimport type { CollectionConfig } from 'payload';\n\nexport function buildSubscriptionsCollection({\n incomingCollections,\n pluginOptions,\n resolvedSchemas,\n}: BuildCollectionProps): CollectionConfig {\n const subscriptionsSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.subscription);\n const subscriptionsSchema = resolvedSchemas[baModelKey.subscription];\n\n const existingSubscriptionCollection = incomingCollections.find(\n collection => collection.slug === subscriptionsSlug\n ) as CollectionConfig | undefined;\n\n const fieldOverrides: FieldOverrides<keyof Subscription> = {\n plan: () => ({\n index: true,\n admin: { readOnly: true, description: 'The name of the subscription plan' },\n }),\n referenceId: () => ({\n index: true,\n admin: {\n readOnly: true,\n description: 'The ID this subscription is associated with (user ID by default)',\n },\n }),\n stripeCustomerId: () => ({\n index: true,\n admin: { readOnly: true, description: 'The Stripe customer ID' },\n }),\n stripeSubscriptionId: () => ({\n index: true,\n admin: { readOnly: true, description: 'The Stripe subscription ID' },\n }),\n status: () => ({\n index: true,\n admin: { description: 'The status of the subscription (active, canceled, etc.)' },\n }),\n periodStart: () => ({\n admin: { description: 'Start date of the current billing period' },\n }),\n periodEnd: () => ({\n admin: { description: 'End date of the current billing period' },\n }),\n cancelAtPeriodEnd: () => ({\n admin: { description: 'Whether the subscription will be canceled at the end of the period' },\n }),\n seats: () => ({\n admin: { description: 'Number of seats for team plans' },\n }),\n trialStart: () => ({\n admin: { description: 'Start date of the trial period' },\n }),\n trialEnd: () => ({\n admin: { description: 'End date of the trial period' },\n }),\n };\n\n const collectionFields = getCollectionFields({\n schema: subscriptionsSchema,\n additionalProperties: fieldOverrides,\n });\n\n let subscriptionsCollection: CollectionConfig = {\n ...existingSubscriptionCollection,\n slug: subscriptionsSlug,\n admin: {\n useAsTitle: getSchemaFieldName(resolvedSchemas, baModelKey.subscription, 'plan'),\n description: 'Subscriptions are used to manage the subscriptions of the users',\n group: pluginOptions?.collectionAdminGroup ?? 'Auth',\n ...existingSubscriptionCollection?.admin,\n },\n access: {\n ...getAdminAccess(pluginOptions),\n ...(existingSubscriptionCollection?.access ?? {}),\n },\n custom: {\n ...(existingSubscriptionCollection?.custom ?? {}),\n betterAuthModelKey: baModelKey.subscription,\n },\n fields: [\n ...(existingSubscriptionCollection?.fields ?? []),\n ...filterDuplicateFields(existingSubscriptionCollection?.fields, collectionFields),\n ],\n };\n\n if (typeof pluginOptions.pluginCollectionOverrides?.subscriptions === 'function') {\n subscriptionsCollection = pluginOptions.pluginCollectionOverrides.subscriptions({\n collection: subscriptionsCollection,\n });\n }\n\n assertAllSchemaFields(subscriptionsCollection, subscriptionsSchema);\n\n return subscriptionsCollection;\n}\n"],"names":["baModelKey","getAdminAccess","assertAllSchemaFields","getSchemaCollectionSlug","getSchemaFieldName","filterDuplicateFields","getCollectionFields","buildSubscriptionsCollection","incomingCollections","pluginOptions","resolvedSchemas","subscriptionsSlug","subscription","subscriptionsSchema","existingSubscriptionCollection","find","collection","slug","fieldOverrides","plan","index","admin","readOnly","description","referenceId","stripeCustomerId","stripeSubscriptionId","status","periodStart","periodEnd","cancelAtPeriodEnd","seats","trialStart","trialEnd","collectionFields","schema","additionalProperties","subscriptionsCollection","useAsTitle","group","collectionAdminGroup","access","custom","betterAuthModelKey","fields","pluginCollectionOverrides","subscriptions"],"mappings":"AAAA,SAASA,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,cAAc,QAAQ,iCAAiC;AAChE,SACEC,qBAAqB,EACrBC,uBAAuB,EACvBC,kBAAkB,QACb,4BAA4B;AACnC,SAASC,qBAAqB,QAAQ,kCAAkC;AACxE,SAASC,mBAAmB,QAAQ,6CAA6C;AAMjF,OAAO,SAASC,6BAA6B,EAC3CC,mBAAmB,EACnBC,aAAa,EACbC,eAAe,EACM;IACrB,MAAMC,oBAAoBR,wBAAwBO,iBAAiBV,WAAWY,YAAY;IAC1F,MAAMC,sBAAsBH,eAAe,CAACV,WAAWY,YAAY,CAAC;IAEpE,MAAME,iCAAiCN,oBAAoBO,IAAI,CAC7DC,CAAAA,aAAcA,WAAWC,IAA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G1B,gCAAgCO,KAAK;QAC1C;QACAoB,QAAQ;YACN,GAAGxC,eAAeQ,cAAc;YAChC,GAAIK,gCAAgC2B,UAAU,CAAC,CAAC;QAClD;QACAC,QAAQ;YACN,GAAI5B,gCAAgC4B,UAAU,CAAC,CAAC;YAChDC,oBAAoB3C,WAAWY,YAAY;QAC7C;QACAgC,QAAQ;eACF9B,gCAAgC8B,UAAU,EAAE;eAC7CvC,sBAAsBS,gCAAgC8B,QAAQV;SAClE;IACH;IAEA,IAAI,OAAOzB,cAAcoC,yBAAyB,EAAEC,kBAAkB,YAAY;QAChFT,0BAA0B5B,cAAcoC,yBAAyB,CAACC,aAAa,CAAC;YAC9E9B,YAAYqB;QACd;IACF;IAEAnC,sBAAsBmC,yBAAyBxB;IAE/C,OAAOwB;AACT"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { baModelKey } from "../../constants";
|
|
2
|
+
import { getAdminAccess } from "../../helpers/get-admin-access";
|
|
3
|
+
import { assertAllSchemaFields, getSchemaCollectionSlug, getSchemaFieldName } from "./utils/collection-schema";
|
|
4
|
+
import { filterDuplicateFields } from "./utils/filter-duplicate-fields";
|
|
5
|
+
import { getCollectionFields } from "./utils/transform-schema-fields-to-payload";
|
|
6
|
+
export function buildTeamMembersCollection({ incomingCollections, pluginOptions, resolvedSchemas }) {
|
|
7
|
+
const teamMemberSlug = getSchemaCollectionSlug(resolvedSchemas, baModelKey.teamMember);
|
|
8
|
+
const teamMemberSchema = resolvedSchemas[baModelKey.teamMember];
|
|
9
|
+
const existingTeamMemberCollection = incomingCollections.find((collection)=>collection.slug === teamMemberSlug);
|
|
10
|
+
const fieldOverrides = {
|
|
11
|
+
teamId: ()=>({
|
|
12
|
+
index: true,
|
|
13
|
+
admin: {
|
|
14
|
+
readOnly: true,
|
|
15
|
+
description: 'The team that the membership belongs to.'
|
|
16
|
+
}
|
|
17
|
+
}),
|
|
18
|
+
userId: ()=>({
|
|
19
|
+
index: true,
|
|
20
|
+
admin: {
|
|
21
|
+
readOnly: true,
|
|
22
|
+
description: 'The user that is a member of the team.'
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
const collectionFields = getCollectionFields({
|
|
27
|
+
schema: teamMemberSchema,
|
|
28
|
+
additionalProperties: fieldOverrides
|
|
29
|
+
});
|
|
30
|
+
const teamMemberCollection = {
|
|
31
|
+
...existingTeamMemberCollection,
|
|
32
|
+
slug: teamMemberSlug,
|
|
33
|
+
admin: {
|
|
34
|
+
hidden: pluginOptions.hidePluginCollections ?? false,
|
|
35
|
+
useAsTitle: getSchemaFieldName(resolvedSchemas, baModelKey.teamMember, 'teamId'),
|
|
36
|
+
description: 'Team members of an organization team.',
|
|
37
|
+
group: pluginOptions?.collectionAdminGroup ?? 'Auth',
|
|
38
|
+
...existingTeamMemberCollection?.admin
|
|
39
|
+
},
|
|
40
|
+
access: {
|
|
41
|
+
...getAdminAccess(pluginOptions),
|
|
42
|
+
...existingTeamMemberCollection?.access ?? {}
|
|
43
|
+
},
|
|
44
|
+
custom: {
|
|
45
|
+
...existingTeamMemberCollection?.custom ?? {},
|
|
46
|
+
betterAuthModelKey: baModelKey.teamMember
|
|
47
|
+
},
|
|
48
|
+
fields: [
|
|
49
|
+
...existingTeamMemberCollection?.fields ?? [],
|
|
50
|
+
...filterDuplicateFields(existingTeamMemberCollection?.fields, collectionFields)
|
|
51
|
+
]
|
|
52
|
+
};
|
|
53
|
+
assertAllSchemaFields(teamMemberCollection, teamMemberSchema);
|
|
54
|
+
return teamMemberCollection;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=team-members.js.map
|