@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,429 @@
|
|
|
1
|
+
import type { UnionToIntersection, betterAuth } from 'better-auth';
|
|
2
|
+
import type { DBFieldAttribute } from 'better-auth/db';
|
|
3
|
+
import type { BetterAuthOptions as BetterAuthOptionsType, BetterAuthPlugin as BetterAuthPluginType, InferAPI, InferPluginTypes } from 'better-auth/types';
|
|
4
|
+
import type { BasePayload, CollectionConfig, Config, Endpoint, Field, Payload, PayloadRequest } from 'payload';
|
|
5
|
+
import type { ModelKey } from '../generated-types';
|
|
6
|
+
import { adminRoutes, baPluginSlugs, loginMethods, socialProviders } from './constants';
|
|
7
|
+
/**
|
|
8
|
+
* BetterAuth options with the following caveats:
|
|
9
|
+
* - The `database` option is removed as it is configured internally
|
|
10
|
+
* - The `user` `modelName` and `fields` is removed as it is configured internally
|
|
11
|
+
* - The `account` `modelName` and `fields` is removed as it is configured internally
|
|
12
|
+
* - The `session` `modelName` and `fields` is removed as it is configured internally
|
|
13
|
+
* - The `verification` `modelName` and `fields` is removed as it is configured internally
|
|
14
|
+
*
|
|
15
|
+
* @see https://www.better-auth.com/docs/reference/options
|
|
16
|
+
*/
|
|
17
|
+
export interface BetterAuthOptions extends Omit<BetterAuthOptionsType, 'database' | 'user' | 'account' | 'verification' | 'session' | 'advanced'> {
|
|
18
|
+
user?: Omit<NonNullable<BetterAuthOptionsType['user']>, 'modelName' | 'fields'> | undefined;
|
|
19
|
+
account?: Omit<NonNullable<BetterAuthOptionsType['account']>, 'modelName' | 'fields'> | undefined;
|
|
20
|
+
session?: Omit<NonNullable<BetterAuthOptionsType['session']>, 'modelName' | 'fields'> | undefined;
|
|
21
|
+
verification?: Omit<NonNullable<BetterAuthOptionsType['verification']>, 'modelName' | 'fields'> | undefined;
|
|
22
|
+
advanced?: Omit<NonNullable<BetterAuthOptionsType['advanced']>, 'generateId'> | undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface SanitizedBetterAuthOptions extends Omit<BetterAuthOptionsType, 'database'> {
|
|
25
|
+
}
|
|
26
|
+
export type SocialProvider = (typeof socialProviders)[number];
|
|
27
|
+
export type LoginMethod = (typeof loginMethods)[number];
|
|
28
|
+
type PluginCollectionOverrides = {
|
|
29
|
+
[K in keyof typeof baPluginSlugs]?: (options: {
|
|
30
|
+
collection: CollectionConfig;
|
|
31
|
+
}) => CollectionConfig;
|
|
32
|
+
};
|
|
33
|
+
export interface BetterAuthPluginOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Disable the plugin
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Disable the default payload auth
|
|
41
|
+
*
|
|
42
|
+
* This will ensure that better-auth handles both admin and frontend auth
|
|
43
|
+
*
|
|
44
|
+
* Admin will make use of custom admin routes for auth and give you more control
|
|
45
|
+
*
|
|
46
|
+
* Note: This will override the option passed in the users collection config
|
|
47
|
+
*
|
|
48
|
+
* Read about this more in the docs
|
|
49
|
+
* @see https://www.payloadauth.com/docs/better-auth#disable-default-payload-auth
|
|
50
|
+
*
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
disableDefaultPayloadAuth?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Custom admin components when disableDefaultPayloadAuth is true
|
|
56
|
+
*
|
|
57
|
+
* These components will be used to render the login, create first admin, and other auth-related views
|
|
58
|
+
*/
|
|
59
|
+
admin?: {
|
|
60
|
+
/**
|
|
61
|
+
* Override which social buttons are shown in the Payload Login / Sign Up view.
|
|
62
|
+
*
|
|
63
|
+
* Provide an array of LoginMethod keys.
|
|
64
|
+
*/
|
|
65
|
+
loginMethods?: LoginMethod[];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Debug options
|
|
69
|
+
*/
|
|
70
|
+
debug?: {
|
|
71
|
+
/**
|
|
72
|
+
* Enable debug logs
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
enableDebugLogs?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Log the tables that are needed for better-auth on init
|
|
78
|
+
* @default false
|
|
79
|
+
*/
|
|
80
|
+
logTables?: boolean;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Hide the better-authplugin collections from the payload admin UI
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
hidePluginCollections?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Defines the admin group for collections.
|
|
89
|
+
* @default "Auth"
|
|
90
|
+
*/
|
|
91
|
+
collectionAdminGroup?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Require a valid admin invitation for any *public* sign‑up.
|
|
94
|
+
*
|
|
95
|
+
* – Applies to both email/password and social‑provider flows.
|
|
96
|
+
* – Existing users can still sign in; admins can still create users via
|
|
97
|
+
* the Payload UI or server‑side calls.
|
|
98
|
+
* – Ignores provider‑level `disableImplicitSignUp` and `disableSignUp`:
|
|
99
|
+
* with a valid invite the sign‑up proceeds, without one it's blocked.
|
|
100
|
+
* – Also sets `disableImplicitSignUp` for all providers, requiring `requestSignUp` to be true for all `authClient.signIn.social` calls when creating a new account with a provider.
|
|
101
|
+
*
|
|
102
|
+
* Enable when you want OAuth for internal/admin use only and no public
|
|
103
|
+
* registrations at all.
|
|
104
|
+
*
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
requireAdminInviteForSignUp?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* BetterAuth options with the following caveats:
|
|
110
|
+
* - The `database` option is removed as it is configured internally
|
|
111
|
+
* - The `user` `modelName` and `fields` is removed as it is configured internally
|
|
112
|
+
* - The `account` `modelName` and `fields` is removed as it is configured internally
|
|
113
|
+
* - The `session` `modelName` and `fields` is removed as it is configured internally
|
|
114
|
+
* - The `verification` `modelName` and `fields` is removed as it is configured internally
|
|
115
|
+
*
|
|
116
|
+
* @see https://www.better-auth.com/docs/reference/options
|
|
117
|
+
*/
|
|
118
|
+
betterAuthOptions?: BetterAuthOptions;
|
|
119
|
+
/**
|
|
120
|
+
* Override plugin configurations
|
|
121
|
+
*
|
|
122
|
+
* Note: TypeScript cannot enforce that only enabled plugins are configured
|
|
123
|
+
* at compile time, but this will be validated at runtime.
|
|
124
|
+
*/
|
|
125
|
+
pluginCollectionOverrides?: PluginCollectionOverrides;
|
|
126
|
+
/**
|
|
127
|
+
* Configure the Users collections:
|
|
128
|
+
*/
|
|
129
|
+
users?: {
|
|
130
|
+
/**
|
|
131
|
+
* Will set the `modelName` for the `user` table in better-auth
|
|
132
|
+
*
|
|
133
|
+
* and the `slug` for the `users` collection in payload
|
|
134
|
+
*
|
|
135
|
+
* @default 'users'
|
|
136
|
+
*/
|
|
137
|
+
slug?: string | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* The default role for users
|
|
140
|
+
*
|
|
141
|
+
* This will be used as the default role for the role field in the users collection
|
|
142
|
+
*
|
|
143
|
+
* If you define this you must also have this role in the roles array
|
|
144
|
+
*
|
|
145
|
+
* This will also be used as the defaultRole option in the better-auth admin plugin if present
|
|
146
|
+
* @see https://www.better-auth.com/docs/plugins/admin#default-role
|
|
147
|
+
* @default "user"
|
|
148
|
+
*/
|
|
149
|
+
defaultRole?: string;
|
|
150
|
+
/**
|
|
151
|
+
* The default role for admins
|
|
152
|
+
*
|
|
153
|
+
* This will be used as the default role for when admins sign up in the create first admin view or when inviting new admins
|
|
154
|
+
*
|
|
155
|
+
*
|
|
156
|
+
* @default "admin"
|
|
157
|
+
*/
|
|
158
|
+
defaultAdminRole?: string;
|
|
159
|
+
/**
|
|
160
|
+
* All roles for the users collection
|
|
161
|
+
*
|
|
162
|
+
* These will be used to define all the options in the user collection role field
|
|
163
|
+
*
|
|
164
|
+
* Will be merged with the adminRoles array, no need to worry about redefining in adminRoles or duplicates
|
|
165
|
+
*
|
|
166
|
+
* This should match the roles in the better-auth admin plugin if you are using it
|
|
167
|
+
* @see https://www.better-auth.com/docs/plugins/admin#access-control
|
|
168
|
+
*
|
|
169
|
+
* @default ["user"]
|
|
170
|
+
*/
|
|
171
|
+
roles?: string[];
|
|
172
|
+
/**
|
|
173
|
+
* Define admin roles for the users collection
|
|
174
|
+
*
|
|
175
|
+
* These roles will be given admin access to all auth collections created by this plugin
|
|
176
|
+
*
|
|
177
|
+
* Note: Will be merged with the roles array, no need to worry about redefining in roles or duplicates
|
|
178
|
+
*
|
|
179
|
+
* Will be also used as the adminRoles option in the better-auth admin plugin if present
|
|
180
|
+
*
|
|
181
|
+
* @see https://www.better-auth.com/docs/plugins/admin#admin-roles
|
|
182
|
+
*
|
|
183
|
+
* @default ["admin"]
|
|
184
|
+
*/
|
|
185
|
+
adminRoles?: string[];
|
|
186
|
+
/**
|
|
187
|
+
* Hide the `users` collection from the payload admin UI
|
|
188
|
+
*
|
|
189
|
+
* This will be overwritten if you change the value in the collection overrides option
|
|
190
|
+
*/
|
|
191
|
+
hidden?: boolean | undefined;
|
|
192
|
+
/**
|
|
193
|
+
* Define which fields users can update themselves
|
|
194
|
+
*
|
|
195
|
+
* Password field is automatically included and doesn't need to be specified here
|
|
196
|
+
*
|
|
197
|
+
* @example ['name', 'dateOfBirth', 'phoneNumber']
|
|
198
|
+
* @default ['name']
|
|
199
|
+
*/
|
|
200
|
+
allowedFields?: string[] | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* Function to override the collection configuration
|
|
203
|
+
*
|
|
204
|
+
* This allows modifying the collection config after it has been built
|
|
205
|
+
* Example use cases include adding saveToJwt to specific fields or
|
|
206
|
+
* modifying field descriptions
|
|
207
|
+
*
|
|
208
|
+
* @param options Object containing the collection config and potentially additional parameters
|
|
209
|
+
* @returns Modified collection config
|
|
210
|
+
*/
|
|
211
|
+
collectionOverrides?: (options: {
|
|
212
|
+
collection: CollectionConfig;
|
|
213
|
+
}) => CollectionConfig;
|
|
214
|
+
/**
|
|
215
|
+
* This will block the first on sign up verification email from better-auth.
|
|
216
|
+
* If you are using Payload's userCollection.verify option, you will want to set this to true.
|
|
217
|
+
* Function that will be blocked: options.emailVerificationsendVerificationEmail
|
|
218
|
+
* @default false
|
|
219
|
+
*/
|
|
220
|
+
blockFirstBetterAuthVerificationEmail?: boolean;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Configure the Accounts collections:
|
|
224
|
+
*/
|
|
225
|
+
accounts?: {
|
|
226
|
+
/**
|
|
227
|
+
* Will set the `modelName` for the `account` table in better-auth
|
|
228
|
+
*
|
|
229
|
+
* and the `slug` for the `accounts` collection in payload
|
|
230
|
+
*
|
|
231
|
+
* @default 'accounts'
|
|
232
|
+
*/
|
|
233
|
+
slug?: string | undefined;
|
|
234
|
+
/**
|
|
235
|
+
* Hide the `accounts` collection from the payload admin UI
|
|
236
|
+
*/
|
|
237
|
+
hidden?: boolean | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* Function to override the collection configuration
|
|
240
|
+
*
|
|
241
|
+
* This allows modifying the collection config after it has been built
|
|
242
|
+
*
|
|
243
|
+
* @param options Object containing the collection config and potentially additional parameters
|
|
244
|
+
* @returns Modified collection config
|
|
245
|
+
*/
|
|
246
|
+
collectionOverrides?: (options: {
|
|
247
|
+
collection: CollectionConfig;
|
|
248
|
+
}) => CollectionConfig;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Configure the Sessions collections:
|
|
252
|
+
*/
|
|
253
|
+
sessions?: {
|
|
254
|
+
/**
|
|
255
|
+
* Will set the `modelName` for the `session` table in better-auth
|
|
256
|
+
*
|
|
257
|
+
* and the `slug` for the `sessions` collection in payload
|
|
258
|
+
*
|
|
259
|
+
* @default 'sessions'
|
|
260
|
+
*/
|
|
261
|
+
slug?: string | undefined;
|
|
262
|
+
/**
|
|
263
|
+
* Hide the `sessions` collection from the payload admin UI
|
|
264
|
+
*/
|
|
265
|
+
hidden?: boolean | undefined;
|
|
266
|
+
/**
|
|
267
|
+
* Function to override the collection configuration
|
|
268
|
+
*
|
|
269
|
+
* This allows modifying the collection config after it has been built
|
|
270
|
+
*
|
|
271
|
+
* @param options Object containing the collection config and potentially additional parameters
|
|
272
|
+
* @returns Modified collection config
|
|
273
|
+
*/
|
|
274
|
+
collectionOverrides?: (options: {
|
|
275
|
+
collection: CollectionConfig;
|
|
276
|
+
}) => CollectionConfig;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Configure the Verifications collections:
|
|
280
|
+
*/
|
|
281
|
+
verifications?: {
|
|
282
|
+
/**
|
|
283
|
+
* Will set the `modelName` for the `verification` table in better-auth
|
|
284
|
+
*
|
|
285
|
+
* and the `slug` for the `verifications` collection in payload
|
|
286
|
+
*
|
|
287
|
+
* @default 'verifications'
|
|
288
|
+
*/
|
|
289
|
+
slug?: string | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* Hide the `verifications` collection from the payload admin UI
|
|
292
|
+
*/
|
|
293
|
+
hidden?: boolean | undefined;
|
|
294
|
+
/**
|
|
295
|
+
* Function to override the collection configuration
|
|
296
|
+
*
|
|
297
|
+
* This allows modifying the collection config after it has been built
|
|
298
|
+
*
|
|
299
|
+
* @param options Object containing the collection config and potentially additional parameters
|
|
300
|
+
* @returns Modified collection config
|
|
301
|
+
*/
|
|
302
|
+
collectionOverrides?: (options: {
|
|
303
|
+
collection: CollectionConfig;
|
|
304
|
+
}) => CollectionConfig;
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Configure the Admin Invitations collections:
|
|
308
|
+
*/
|
|
309
|
+
adminInvitations?: {
|
|
310
|
+
/**
|
|
311
|
+
* Will set the `slug` for the `admin-invitations` collection in payload
|
|
312
|
+
*
|
|
313
|
+
* @default 'admin-invitations'
|
|
314
|
+
*/
|
|
315
|
+
slug?: string | undefined;
|
|
316
|
+
/**
|
|
317
|
+
* Hide the `admin-invitations` collection from the payload admin UI
|
|
318
|
+
*/
|
|
319
|
+
hidden?: boolean | undefined;
|
|
320
|
+
/**
|
|
321
|
+
* This will be used to generate the admin invite url
|
|
322
|
+
*
|
|
323
|
+
* @param options Object containing payload and the token
|
|
324
|
+
* @returns The admin invite url
|
|
325
|
+
*/
|
|
326
|
+
generateInviteUrl?: GenerateAdminInviteUrlFn;
|
|
327
|
+
/**
|
|
328
|
+
* This will be used to send the admin invite email
|
|
329
|
+
*
|
|
330
|
+
* @param options Object containing payload, email and the url
|
|
331
|
+
* @returns The admin invite url
|
|
332
|
+
*/
|
|
333
|
+
sendInviteEmail?: SendAdminInviteEmailFn;
|
|
334
|
+
/**
|
|
335
|
+
* Function to override the collection configuration
|
|
336
|
+
*
|
|
337
|
+
* This allows modifying the collection config after it has been built
|
|
338
|
+
*
|
|
339
|
+
* @param options Object containing the collection config and potentially additional parameters
|
|
340
|
+
* @returns Modified collection config
|
|
341
|
+
*/
|
|
342
|
+
collectionOverrides?: (options: {
|
|
343
|
+
collection: CollectionConfig;
|
|
344
|
+
}) => CollectionConfig;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
export type SendAdminInviteEmailFn = (options: {
|
|
348
|
+
payload: Payload;
|
|
349
|
+
email: string;
|
|
350
|
+
url: string;
|
|
351
|
+
}) => Promise<{
|
|
352
|
+
success: true;
|
|
353
|
+
message?: string;
|
|
354
|
+
} | {
|
|
355
|
+
success: false;
|
|
356
|
+
message: string;
|
|
357
|
+
}>;
|
|
358
|
+
export type GenerateAdminInviteUrlFn = (options: {
|
|
359
|
+
payload: Payload;
|
|
360
|
+
token: string;
|
|
361
|
+
}) => string;
|
|
362
|
+
export type ConfigAdminCustom = {
|
|
363
|
+
betterAuth: {
|
|
364
|
+
adminRoutes: {
|
|
365
|
+
[key in keyof typeof adminRoutes]: string;
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
export interface BetterAuthPlugin {
|
|
370
|
+
(config: Config): Config;
|
|
371
|
+
pluginOptions: BetterAuthPluginOptions;
|
|
372
|
+
}
|
|
373
|
+
export interface PayloadRequestWithBetterAuth<TPlugins extends BetterAuthPluginType[] = []> extends PayloadRequest {
|
|
374
|
+
payload: BasePayload & {
|
|
375
|
+
betterAuth: BetterAuthReturn<TPlugins>;
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
export type CollectionHookWithBetterAuth<T extends (args: any) => any> = T extends (args: infer A) => infer R ? (args: Omit<A, 'req'> & {
|
|
379
|
+
req: PayloadRequestWithBetterAuth;
|
|
380
|
+
}) => R : never;
|
|
381
|
+
export type EndpointWithBetterAuth = Omit<Endpoint, 'handler'> & {
|
|
382
|
+
handler: (req: PayloadRequestWithBetterAuth) => Promise<Response> | Response;
|
|
383
|
+
};
|
|
384
|
+
export type ExtractEndpoints<T> = T extends BetterAuthPlugin ? T extends {
|
|
385
|
+
endpoints?: infer E;
|
|
386
|
+
} ? E : Record<string, never> : Record<string, never>;
|
|
387
|
+
export type TPlugins<TPlugins extends BetterAuthPluginType[] = BetterAuthPluginType[]> = TPlugins;
|
|
388
|
+
export type PluginInferTypes<T extends TPlugins> = {
|
|
389
|
+
[K in keyof InferPluginTypes<{
|
|
390
|
+
plugins: T;
|
|
391
|
+
}>]: InferPluginTypes<{
|
|
392
|
+
plugins: T;
|
|
393
|
+
}>[K];
|
|
394
|
+
};
|
|
395
|
+
export type BetterAuthReturn<T extends TPlugins> = Omit<ReturnType<typeof betterAuth>, '$Infer'> & {
|
|
396
|
+
api: T extends (infer P)[] ? InferAPI<UnionToIntersection<ExtractEndpoints<P>>> : Record<string, never>;
|
|
397
|
+
$Infer: ReturnType<typeof betterAuth>['$Infer'] & PluginInferTypes<T>;
|
|
398
|
+
};
|
|
399
|
+
export type BetterAuthFunctionOptions<P extends TPlugins> = Omit<BetterAuthOptions, 'database' | 'plugins'> & {
|
|
400
|
+
enableDebugLogs?: boolean;
|
|
401
|
+
plugins: P;
|
|
402
|
+
};
|
|
403
|
+
export interface BuiltBetterAuthSchema {
|
|
404
|
+
modelName: string;
|
|
405
|
+
fields: Record<string, DBFieldAttribute>;
|
|
406
|
+
order: number;
|
|
407
|
+
}
|
|
408
|
+
export type BetterAuthSchemas = Record<ModelKey, BuiltBetterAuthSchema>;
|
|
409
|
+
export interface BuildCollectionProps {
|
|
410
|
+
resolvedSchemas: BetterAuthSchemas;
|
|
411
|
+
pluginOptions: BetterAuthPluginOptions;
|
|
412
|
+
incomingCollections: CollectionConfig[];
|
|
413
|
+
}
|
|
414
|
+
export type FieldOverrides<K extends string = string> = {
|
|
415
|
+
[Key in K]?: (field: DBFieldAttribute) => Partial<Field>;
|
|
416
|
+
} & {
|
|
417
|
+
[key: string]: (field: DBFieldAttribute) => Partial<Field>;
|
|
418
|
+
};
|
|
419
|
+
export type FieldWithIds = {
|
|
420
|
+
name?: string;
|
|
421
|
+
custom?: {
|
|
422
|
+
betterAuthFieldKey?: string;
|
|
423
|
+
};
|
|
424
|
+
};
|
|
425
|
+
export type FieldRule = {
|
|
426
|
+
condition?: (field: DBFieldAttribute) => boolean;
|
|
427
|
+
transform: (field: DBFieldAttribute) => Record<string, unknown>;
|
|
428
|
+
};
|
|
429
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/better-auth/plugin/types.ts"],"sourcesContent":["import type { UnionToIntersection, betterAuth } from 'better-auth';\nimport type { DBFieldAttribute } from 'better-auth/db';\nimport type {\n BetterAuthOptions as BetterAuthOptionsType,\n BetterAuthPlugin as BetterAuthPluginType,\n InferAPI,\n InferPluginTypes,\n} from 'better-auth/types';\nimport type {\n BasePayload,\n CollectionConfig,\n Config,\n Endpoint,\n Field,\n Payload,\n PayloadRequest,\n} from 'payload';\nimport type { ModelKey } from '../generated-types';\nimport { adminRoutes, baPluginSlugs, loginMethods, socialProviders } from './constants';\n\n/**\n * BetterAuth options with the following caveats:\n * - The `database` option is removed as it is configured internally\n * - The `user` `modelName` and `fields` is removed as it is configured internally\n * - The `account` `modelName` and `fields` is removed as it is configured internally\n * - The `session` `modelName` and `fields` is removed as it is configured internally\n * - The `verification` `modelName` and `fields` is removed as it is configured internally\n *\n * @see https://www.better-auth.com/docs/reference/options\n */\nexport interface BetterAuthOptions\n extends Omit<\n BetterAuthOptionsType,\n 'database' | 'user' | 'account' | 'verification' | 'session' | 'advanced'\n > {\n user?: Omit<NonNullable<BetterAuthOptionsType['user']>, 'modelName' | 'fields'> | undefined;\n account?: Omit<NonNullable<BetterAuthOptionsType['account']>, 'modelName' | 'fields'> | undefined;\n session?: Omit<NonNullable<BetterAuthOptionsType['session']>, 'modelName' | 'fields'> | undefined;\n verification?:\n | Omit<NonNullable<BetterAuthOptionsType['verification']>, 'modelName' | 'fields'>\n | undefined;\n advanced?: Omit<NonNullable<BetterAuthOptionsType['advanced']>, 'generateId'> | undefined;\n}\n\nexport interface SanitizedBetterAuthOptions extends Omit<BetterAuthOptionsType, 'database'> {}\n\nexport type SocialProvider = (typeof socialProviders)[number];\n\nexport type LoginMethod = (typeof loginMethods)[number];\n\ntype PluginCollectionOverrides = {\n [K in keyof typeof baPluginSlugs]?: (options: {\n collection: CollectionConfig;\n }) => CollectionConfig;\n};\n\nexport interface BetterAuthPluginOptions {\n /**\n * Disable the plugin\n * @default false\n */\n disabled?: boolean;\n /**\n * Disable the default payload auth\n *\n * This will ensure that better-auth handles both admin and frontend auth\n *\n * Admin will make use of custom admin routes for auth and give you more control\n *\n * Note: This will override the option passed in the users collection config\n *\n * Read about this more in the docs\n * @see https://www.payloadauth.com/docs/better-auth#disable-default-payload-auth\n *\n * @default false\n */\n disableDefaultPayloadAuth?: boolean;\n /**\n * Custom admin components when disableDefaultPayloadAuth is true\n *\n * These components will be used to render the login, create first admin, and other auth-related views\n */\n admin?: {\n /**\n * Override which social buttons are shown in the Payload Login / Sign Up view.\n *\n * Provide an array of LoginMethod keys.\n */\n loginMethods?: LoginMethod[];\n };\n /**\n * Debug options\n */\n debug?: {\n /**\n * Enable debug logs\n * @default false\n */\n enableDebugLogs?: boolean;\n /**\n * Log the tables that are needed for better-auth on init\n * @default false\n */\n logTables?: boolean;\n };\n /**\n * Hide the better-authplugin collections from the payload admin UI\n * @default false\n */\n hidePluginCollections?: boolean;\n /**\n * Defines the admin group for collections.\n * @default \"Auth\"\n */\n collectionAdminGroup?: string;\n /**\n * Require a valid admin invitation for any *public* sign‑up.\n *\n * – Applies to both email/password and social‑provider flows.\n * – Existing users can still sign in; admins can still create users via\n * the Payload UI or server‑side calls.\n * – Ignores provider‑level `disableImplicitSignUp` and `disableSignUp`:\n * with a valid invite the sign‑up proceeds, without one it's blocked.\n * – Also sets `disableImplicitSignUp` for all providers, requiring `requestSignUp` to be true for all `authClient.signIn.social` calls when creating a new account with a provider.\n *\n * Enable when you want OAuth for internal/admin use only and no public\n * registrations at all.\n *\n * @default false\n */\n requireAdminInviteForSignUp?: boolean;\n /**\n * BetterAuth options with the following caveats:\n * - The `database` option is removed as it is configured internally\n * - The `user` `modelName` and `fields` is removed as it is configured internally\n * - The `account` `modelName` and `fields` is removed as it is configured internally\n * - The `session` `modelName` and `fields` is removed as it is configured internally\n * - The `verification` `modelName` and `fields` is removed as it is configured internally\n *\n * @see https://www.better-auth.com/docs/reference/options\n */\n betterAuthOptions?: BetterAuthOptions;\n /**\n * Override plugin configurations\n *\n * Note: TypeScript cannot enforce that only enabled plugins are configured\n * at compile time, but this will be validated at runtime.\n */\n pluginCollectionOverrides?: PluginCollectionOverrides;\n /**\n * Configure the Users collections:\n */\n users?: {\n /**\n * Will set the `modelName` for the `user` table in better-auth\n *\n * and the `slug` for the `users` collection in payload\n *\n * @default 'users'\n */\n slug?: string | undefined;\n /**\n * The default role for users\n *\n * This will be used as the default role for the role field in the users collection\n *\n * If you define this you must also have this role in the roles array\n *\n * This will also be used as the defaultRole option in the better-auth admin plugin if present\n * @see https://www.better-auth.com/docs/plugins/admin#default-role\n * @default \"user\"\n */\n defaultRole?: string;\n /**\n * The default role for admins\n *\n * This will be used as the default role for when admins sign up in the create first admin view or when inviting new admins\n *\n *\n * @default \"admin\"\n */\n defaultAdminRole?: string;\n /**\n * All roles for the users collection\n *\n * These will be used to define all the options in the user collection role field\n *\n * Will be merged with the adminRoles array, no need to worry about redefining in adminRoles or duplicates\n *\n * This should match the roles in the better-auth admin plugin if you are using it\n * @see https://www.better-auth.com/docs/plugins/admin#access-control\n *\n * @default [\"user\"]\n */\n roles?: string[];\n /**\n * Define admin roles for the users collection\n *\n * These roles will be given admin access to all auth collections created by this plugin\n *\n * Note: Will be merged with the roles array, no need to worry about redefining in roles or duplicates\n *\n * Will be also used as the adminRoles option in the better-auth admin plugin if present\n *\n * @see https://www.better-auth.com/docs/plugins/admin#admin-roles\n *\n * @default [\"admin\"]\n */\n adminRoles?: string[];\n /**\n * Hide the `users` collection from the payload admin UI\n *\n * This will be overwritten if you change the value in the collection overrides option\n */\n hidden?: boolean | undefined;\n /**\n * Define which fields users can update themselves\n *\n * Password field is automatically included and doesn't need to be specified here\n *\n * @example ['name', 'dateOfBirth', 'phoneNumber']\n * @default ['name']\n */\n allowedFields?: string[] | undefined;\n /**\n * Function to override the collection configuration\n *\n * This allows modifying the collection config after it has been built\n * Example use cases include adding saveToJwt to specific fields or\n * modifying field descriptions\n *\n * @param options Object containing the collection config and potentially additional parameters\n * @returns Modified collection config\n */\n collectionOverrides?: (options: { collection: CollectionConfig }) => CollectionConfig;\n /**\n * This will block the first on sign up verification email from better-auth.\n * If you are using Payload's userCollection.verify option, you will want to set this to true.\n * Function that will be blocked: options.emailVerificationsendVerificationEmail\n * @default false\n */\n blockFirstBetterAuthVerificationEmail?: boolean;\n };\n /**\n * Configure the Accounts collections:\n */\n accounts?: {\n /**\n * Will set the `modelName` for the `account` table in better-auth\n *\n * and the `slug` for the `accounts` collection in payload\n *\n * @default 'accounts'\n */\n slug?: string | undefined;\n /**\n * Hide the `accounts` collection from the payload admin UI\n */\n hidden?: boolean | undefined;\n /**\n * Function to override the collection configuration\n *\n * This allows modifying the collection config after it has been built\n *\n * @param options Object containing the collection config and potentially additional parameters\n * @returns Modified collection config\n */\n collectionOverrides?: (options: { collection: CollectionConfig }) => CollectionConfig;\n };\n /**\n * Configure the Sessions collections:\n */\n sessions?: {\n /**\n * Will set the `modelName` for the `session` table in better-auth\n *\n * and the `slug` for the `sessions` collection in payload\n *\n * @default 'sessions'\n */\n slug?: string | undefined;\n /**\n * Hide the `sessions` collection from the payload admin UI\n */\n hidden?: boolean | undefined;\n /**\n * Function to override the collection configuration\n *\n * This allows modifying the collection config after it has been built\n *\n * @param options Object containing the collection config and potentially additional parameters\n * @returns Modified collection config\n */\n collectionOverrides?: (options: { collection: CollectionConfig }) => CollectionConfig;\n };\n /**\n * Configure the Verifications collections:\n */\n verifications?: {\n /**\n * Will set the `modelName` for the `verification` table in better-auth\n *\n * and the `slug` for the `verifications` collection in payload\n *\n * @default 'verifications'\n */\n slug?: string | undefined;\n /**\n * Hide the `verifications` collection from the payload admin UI\n */\n hidden?: boolean | undefined;\n /**\n * Function to override the collection configuration\n *\n * This allows modifying the collection config after it has been built\n *\n * @param options Object containing the collection config and potentially additional parameters\n * @returns Modified collection config\n */\n collectionOverrides?: (options: { collection: CollectionConfig }) => CollectionConfig;\n };\n /**\n * Configure the Admin Invitations collections:\n */\n adminInvitations?: {\n /**\n * Will set the `slug` for the `admin-invitations` collection in payload\n *\n * @default 'admin-invitations'\n */\n slug?: string | undefined;\n /**\n * Hide the `admin-invitations` collection from the payload admin UI\n */\n hidden?: boolean | undefined;\n /**\n * This will be used to generate the admin invite url\n *\n * @param options Object containing payload and the token\n * @returns The admin invite url\n */\n generateInviteUrl?: GenerateAdminInviteUrlFn;\n /**\n * This will be used to send the admin invite email\n *\n * @param options Object containing payload, email and the url\n * @returns The admin invite url\n */\n sendInviteEmail?: SendAdminInviteEmailFn;\n /**\n * Function to override the collection configuration\n *\n * This allows modifying the collection config after it has been built\n *\n * @param options Object containing the collection config and potentially additional parameters\n * @returns Modified collection config\n */\n collectionOverrides?: (options: { collection: CollectionConfig }) => CollectionConfig;\n };\n}\n\nexport type SendAdminInviteEmailFn = (options: {\n payload: Payload;\n email: string;\n url: string;\n}) => Promise<{ success: true; message?: string } | { success: false; message: string }>;\n\nexport type GenerateAdminInviteUrlFn = (options: { payload: Payload; token: string }) => string;\n\nexport type ConfigAdminCustom = {\n betterAuth: {\n adminRoutes: {\n [key in keyof typeof adminRoutes]: string;\n };\n };\n};\n\nexport interface BetterAuthPlugin {\n (config: Config): Config;\n pluginOptions: BetterAuthPluginOptions;\n}\n\nexport interface PayloadRequestWithBetterAuth<TPlugins extends BetterAuthPluginType[] = []>\n extends PayloadRequest {\n payload: BasePayload & {\n betterAuth: BetterAuthReturn<TPlugins>;\n };\n}\n\nexport type CollectionHookWithBetterAuth<T extends (args: any) => any> = T extends (\n args: infer A\n) => infer R\n ? (args: Omit<A, 'req'> & { req: PayloadRequestWithBetterAuth }) => R\n : never;\n\nexport type EndpointWithBetterAuth = Omit<Endpoint, 'handler'> & {\n handler: (req: PayloadRequestWithBetterAuth) => Promise<Response> | Response;\n};\n\nexport type ExtractEndpoints<T> = T extends BetterAuthPlugin\n ? T extends { endpoints?: infer E }\n ? E\n : Record<string, never>\n : Record<string, never>;\n\nexport type TPlugins<TPlugins extends BetterAuthPluginType[] = BetterAuthPluginType[]> = TPlugins;\n\nexport type PluginInferTypes<T extends TPlugins> = {\n [K in keyof InferPluginTypes<{ plugins: T }>]: InferPluginTypes<{\n plugins: T;\n }>[K];\n};\n\nexport type BetterAuthReturn<T extends TPlugins> = Omit<ReturnType<typeof betterAuth>, '$Infer'> & {\n api: T extends (infer P)[] ? InferAPI<UnionToIntersection<ExtractEndpoints<P>>> : Record<string, never>;\n $Infer: ReturnType<typeof betterAuth>['$Infer'] & PluginInferTypes<T>;\n};\n\nexport type BetterAuthFunctionOptions<P extends TPlugins> = Omit<\n BetterAuthOptions,\n 'database' | 'plugins'\n> & {\n enableDebugLogs?: boolean;\n plugins: P;\n};\n\nexport interface BuiltBetterAuthSchema {\n modelName: string;\n fields: Record<string, DBFieldAttribute>;\n order: number;\n}\n\nexport type BetterAuthSchemas = Record<ModelKey, BuiltBetterAuthSchema>;\n\nexport interface BuildCollectionProps {\n resolvedSchemas: BetterAuthSchemas;\n pluginOptions: BetterAuthPluginOptions;\n incomingCollections: CollectionConfig[];\n}\n\nexport type FieldOverrides<K extends string = string> = {\n [Key in K]?: (field: DBFieldAttribute) => Partial<Field>;\n} & {\n [key: string]: (field: DBFieldAttribute) => Partial<Field>;\n};\n\nexport type FieldWithIds = { name?: string; custom?: { betterAuthFieldKey?: string } };\n\nexport type FieldRule = {\n condition?: (field: DBFieldAttribute) => boolean;\n transform: (field: DBFieldAttribute) => Record<string, unknown>;\n};\n"],"names":[],"mappings":"AAgcA,WAGE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep-sets a value on an object using a dotted-path string.
|
|
3
|
+
*
|
|
4
|
+
* **Path syntax**
|
|
5
|
+
* ──────────────────────────────────────────────────────────
|
|
6
|
+
* token action
|
|
7
|
+
* ------------ ------------------------------------------
|
|
8
|
+
* `foo.bar` create/read plain nested objects
|
|
9
|
+
* `foo.bar[]` *append* `value` to array `foo.bar`
|
|
10
|
+
* `foo.[]bar` *prepend* `value` to array `foo.bar`
|
|
11
|
+
* `foo.bar[2]` replace item `2` of `foo.bar`, creating
|
|
12
|
+
* empty slots if the index is out of bounds
|
|
13
|
+
*
|
|
14
|
+
* Missing objects/arrays are created on the fly.
|
|
15
|
+
* The function mutates `target` in place and returns it so
|
|
16
|
+
* you can chain calls.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam T – target object type
|
|
19
|
+
* @typeParam V – value type
|
|
20
|
+
* @param target Object to mutate
|
|
21
|
+
* @param rawPath Dotted path string (see syntax table)
|
|
22
|
+
* @param value Value to set / append / prepend
|
|
23
|
+
* @returns The original `target` reference
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const o: Record<string, unknown> = {};
|
|
27
|
+
* set(o, 'alpha.beta[2].gamma', 42);
|
|
28
|
+
* // o →
|
|
29
|
+
* // {
|
|
30
|
+
* // alpha: {
|
|
31
|
+
* // beta: [
|
|
32
|
+
* // , // <-- empty slot #0
|
|
33
|
+
* // , // <-- empty slot #1
|
|
34
|
+
* // { gamma: 42 } // <-- slot #2
|
|
35
|
+
* // ]
|
|
36
|
+
* // }
|
|
37
|
+
* // }
|
|
38
|
+
*/
|
|
39
|
+
export declare function set<T extends Record<string, unknown>, V = unknown>(target: T, rawPath: string, value: V): T;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep-sets a value on an object using a dotted-path string.
|
|
3
|
+
*
|
|
4
|
+
* **Path syntax**
|
|
5
|
+
* ──────────────────────────────────────────────────────────
|
|
6
|
+
* token action
|
|
7
|
+
* ------------ ------------------------------------------
|
|
8
|
+
* `foo.bar` create/read plain nested objects
|
|
9
|
+
* `foo.bar[]` *append* `value` to array `foo.bar`
|
|
10
|
+
* `foo.[]bar` *prepend* `value` to array `foo.bar`
|
|
11
|
+
* `foo.bar[2]` replace item `2` of `foo.bar`, creating
|
|
12
|
+
* empty slots if the index is out of bounds
|
|
13
|
+
*
|
|
14
|
+
* Missing objects/arrays are created on the fly.
|
|
15
|
+
* The function mutates `target` in place and returns it so
|
|
16
|
+
* you can chain calls.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam T – target object type
|
|
19
|
+
* @typeParam V – value type
|
|
20
|
+
* @param target Object to mutate
|
|
21
|
+
* @param rawPath Dotted path string (see syntax table)
|
|
22
|
+
* @param value Value to set / append / prepend
|
|
23
|
+
* @returns The original `target` reference
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const o: Record<string, unknown> = {};
|
|
27
|
+
* set(o, 'alpha.beta[2].gamma', 42);
|
|
28
|
+
* // o →
|
|
29
|
+
* // {
|
|
30
|
+
* // alpha: {
|
|
31
|
+
* // beta: [
|
|
32
|
+
* // , // <-- empty slot #0
|
|
33
|
+
* // , // <-- empty slot #1
|
|
34
|
+
* // { gamma: 42 } // <-- slot #2
|
|
35
|
+
* // ]
|
|
36
|
+
* // }
|
|
37
|
+
* // }
|
|
38
|
+
*/ export function set(target, rawPath, value) {
|
|
39
|
+
if (!rawPath) return target;
|
|
40
|
+
const tokens = rawPath.split('.');
|
|
41
|
+
// Using any because node can be any nested object/array structure as we traverse the path
|
|
42
|
+
// biome-ignore lint/suspicious/noExplicitAny: node can be any nested object/array structure
|
|
43
|
+
let node = target;
|
|
44
|
+
for(let i = 0; i < tokens.length; i += 1){
|
|
45
|
+
const raw = tokens[i];
|
|
46
|
+
if (!raw) continue;
|
|
47
|
+
const prepend = raw.startsWith('[]');
|
|
48
|
+
const append = raw.endsWith('[]');
|
|
49
|
+
const idxMatch = raw.match(/\[(\d+)]$/);
|
|
50
|
+
const hasIndex = Boolean(idxMatch);
|
|
51
|
+
const index = hasIndex ? Number(idxMatch[1]) : -1;
|
|
52
|
+
const key = prepend ? raw.slice(2) : append ? raw.slice(0, -2) : hasIndex ? raw.slice(0, raw.length - idxMatch[0].length) : raw;
|
|
53
|
+
const last = i === tokens.length - 1;
|
|
54
|
+
/* ----- prepend / append ------------------------------------------------ */ if (prepend || append) {
|
|
55
|
+
if (!Array.isArray(node[key])) node[key] = [];
|
|
56
|
+
if (last) {
|
|
57
|
+
// Using any[] because array can contain any value types as we traverse nested structures
|
|
58
|
+
if (prepend) {
|
|
59
|
+
// biome-ignore lint/suspicious/noExplicitAny: array can contain any value types
|
|
60
|
+
node[key].unshift(value);
|
|
61
|
+
} else {
|
|
62
|
+
// biome-ignore lint/suspicious/noExplicitAny: array can contain any value types
|
|
63
|
+
node[key].push(value);
|
|
64
|
+
}
|
|
65
|
+
return target;
|
|
66
|
+
}
|
|
67
|
+
const next = {};
|
|
68
|
+
// Using any[] because array can contain any value types as we traverse nested structures
|
|
69
|
+
if (prepend) {
|
|
70
|
+
// biome-ignore lint/suspicious/noExplicitAny: array can contain any value types
|
|
71
|
+
node[key].unshift(next);
|
|
72
|
+
} else {
|
|
73
|
+
// biome-ignore lint/suspicious/noExplicitAny: array can contain any value types
|
|
74
|
+
node[key].push(next);
|
|
75
|
+
}
|
|
76
|
+
node = next;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
/* ----- explicit numeric index ----------------------------------------- */ if (hasIndex) {
|
|
80
|
+
if (!Array.isArray(node[key])) node[key] = [];
|
|
81
|
+
// Using any[] because array can contain any value types as we traverse nested structures
|
|
82
|
+
// biome-ignore lint/suspicious/noExplicitAny: array can contain any value types
|
|
83
|
+
const arr = node[key];
|
|
84
|
+
while(arr.length <= index)arr.push(undefined);
|
|
85
|
+
if (last) {
|
|
86
|
+
arr[index] = value;
|
|
87
|
+
return target;
|
|
88
|
+
}
|
|
89
|
+
if (arr[index] === undefined) arr[index] = {};
|
|
90
|
+
node = arr[index];
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
/* ----- plain object step ---------------------------------------------- */ if (last) {
|
|
94
|
+
node[key] = value;
|
|
95
|
+
return target;
|
|
96
|
+
}
|
|
97
|
+
if (node[key] === undefined) node[key] = {};
|
|
98
|
+
node = node[key];
|
|
99
|
+
}
|
|
100
|
+
return target;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/better-auth/plugin/utils/set.ts"],"sourcesContent":["/**\n * Deep-sets a value on an object using a dotted-path string.\n *\n * **Path syntax**\n * ──────────────────────────────────────────────────────────\n * token action\n * ------------ ------------------------------------------\n * `foo.bar` create/read plain nested objects\n * `foo.bar[]` *append* `value` to array `foo.bar`\n * `foo.[]bar` *prepend* `value` to array `foo.bar`\n * `foo.bar[2]` replace item `2` of `foo.bar`, creating\n * empty slots if the index is out of bounds\n *\n * Missing objects/arrays are created on the fly.\n * The function mutates `target` in place and returns it so\n * you can chain calls.\n *\n * @typeParam T – target object type\n * @typeParam V – value type\n * @param target Object to mutate\n * @param rawPath Dotted path string (see syntax table)\n * @param value Value to set / append / prepend\n * @returns The original `target` reference\n *\n * @example\n * const o: Record<string, unknown> = {};\n * set(o, 'alpha.beta[2].gamma', 42);\n * // o →\n * // {\n * // alpha: {\n * // beta: [\n * // , // <-- empty slot #0\n * // , // <-- empty slot #1\n * // { gamma: 42 } // <-- slot #2\n * // ]\n * // }\n * // }\n */\nexport function set<T extends Record<string, unknown>, V = unknown>(\n target: T,\n rawPath: string,\n value: V\n): T {\n if (!rawPath) return target;\n\n const tokens = rawPath.split('.');\n // Using any because node can be any nested object/array structure as we traverse the path\n // biome-ignore lint/suspicious/noExplicitAny: node can be any nested object/array structure\n let node: any = target;\n\n for (let i = 0; i < tokens.length; i += 1) {\n const raw = tokens[i];\n if (!raw) continue;\n const prepend = raw.startsWith('[]');\n const append = raw.endsWith('[]');\n const idxMatch = raw.match(/\\[(\\d+)]$/);\n const hasIndex = Boolean(idxMatch);\n const index = hasIndex ? Number(idxMatch![1]) : -1;\n const key = prepend\n ? raw.slice(2)\n : append\n ? raw.slice(0, -2)\n : hasIndex\n ? raw.slice(0, raw.length - idxMatch![0].length)\n : raw;\n const last = i === tokens.length - 1;\n\n /* ----- prepend / append ------------------------------------------------ */\n if (prepend || append) {\n if (!Array.isArray(node[key])) node[key] = [];\n if (last) {\n // Using any[] because array can contain any value types as we traverse nested structures\n if (prepend) {\n // biome-ignore lint/suspicious/noExplicitAny: array can contain any value types\n (node[key] as any[]).unshift(value);\n } else {\n // biome-ignore lint/suspicious/noExplicitAny: array can contain any value types\n (node[key] as any[]).push(value);\n }\n return target;\n }\n const next: Record<string, unknown> = {};\n // Using any[] because array can contain any value types as we traverse nested structures\n if (prepend) {\n // biome-ignore lint/suspicious/noExplicitAny: array can contain any value types\n (node[key] as any[]).unshift(next);\n } else {\n // biome-ignore lint/suspicious/noExplicitAny: array can contain any value types\n (node[key] as any[]).push(next);\n }\n node = next;\n continue;\n }\n\n /* ----- explicit numeric index ----------------------------------------- */\n if (hasIndex) {\n if (!Array.isArray(node[key])) node[key] = [];\n // Using any[] because array can contain any value types as we traverse nested structures\n // biome-ignore lint/suspicious/noExplicitAny: array can contain any value types\n const arr: any[] = node[key] as any[];\n while (arr.length <= index) arr.push(undefined);\n if (last) {\n arr[index] = value;\n return target;\n }\n if (arr[index] === undefined) arr[index] = {};\n node = arr[index];\n continue;\n }\n\n /* ----- plain object step ---------------------------------------------- */\n if (last) {\n node[key] = value;\n return target;\n }\n if (node[key] === undefined) node[key] = {};\n node = node[key];\n }\n\n return target;\n}\n"],"names":["set","target","rawPath","value","tokens","split","node","i","length","raw","prepend","startsWith","append","endsWith","idxMatch","match","hasIndex","Boolean","index","Number","key","slice","last","Array","isArray","unshift","push","next","arr","undefined"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCC,GACD,OAAO,SAASA,IACdC,MAAS,EACTC,OAAe,EACfC,KAAQ;IAER,IAAI,CAACD,SAAS,OAAOD;IAErB,MAAMG,SAASF,QAAQG,KAAK,CAAC;IAC7B,0FAA0F;IAC1F,4FAA4F;IAC5F,IAAIC,OAAYL;IAEhB,IAAK,IAAIM,IAAI,GAAGA,IAAIH,OAAOI,MAAM,EAAED,KAAK,EAAG;QACzC,MAAME,MAAML,MAAM,CAACG,EAAE;QACrB,IAAI,CAACE,KAAK;QACV,MAAMC,UAAUD,IAAIE,UAAU,CAAC;QAC/B,MAAMC,SAASH,IAAII,QAAQ,CAAC;QAC5B,MAAMC,WAAWL,IAAIM,KAAK,CAAC;QAC3B,MAAMC,WAAWC,QAAQH;QACzB,MAAMI,QAAQF,WAAWG,OAAOL,QAAS,CAAC,EAAE,IAAI,CAAC;QACjD,MAAMM,MAAMV,UACRD,IAAIY,KAAK,CAAC,KACVT,SACEH,IAAIY,KAAK,CAAC,GAAG,CAAC,KACdL,WACEP,IAAIY,KAAK,CAAC,GAAGZ,IAAID,MAAM,GAAGM,QAAS,CAAC,EAAE,CAACN,MAAM,IAC7CC;QACR,MAAMa,OAAOf,MAAMH,OAAOI,MAAM,GAAG;QAEnC,2EAA2E,GAC3E,IAAIE,WAAWE,QAAQ;YACrB,IAAI,CAACW,MAAMC,OAAO,CAAClB,IAAI,CAACc,IAAI,GAAGd,IAAI,CAACc,IAAI,GAAG,EAAE;YAC7C,IAAIE,MAAM;gBACR,yFAAyF;gBACzF,IAAIZ,SAAS;oBACX,gFAAgF;oBAC/EJ,IAAI,CAACc,IAAI,CAAWK,OAAO,CAACtB;gBAC/B,OAAO;oBACL,gFAAgF;oBAC/EG,IAAI,CAACc,IAAI,CAAWM,IAAI,CAACvB;gBAC5B;gBACA,OAAOF;YACT;YACA,MAAM0B,OAAgC,CAAC;YACvC,yFAAyF;YACzF,IAAIjB,SAAS;gBACX,gFAAgF;gBAC/EJ,IAAI,CAACc,IAAI,CAAWK,OAAO,CAACE;YAC/B,OAAO;gBACL,gFAAgF;gBAC/ErB,IAAI,CAACc,IAAI,CAAWM,IAAI,CAACC;YAC5B;YACArB,OAAOqB;YACP;QACF;QAEA,0EAA0E,GAC1E,IAAIX,UAAU;YACZ,IAAI,CAACO,MAAMC,OAAO,CAAClB,IAAI,CAACc,IAAI,GAAGd,IAAI,CAACc,IAAI,GAAG,EAAE;YAC7C,yFAAyF;YACzF,gFAAgF;YAChF,MAAMQ,MAAatB,IAAI,CAACc,IAAI;YAC5B,MAAOQ,IAAIpB,MAAM,IAAIU,MAAOU,IAAIF,IAAI,CAACG;YACrC,IAAIP,MAAM;gBACRM,GAAG,CAACV,MAAM,GAAGf;gBACb,OAAOF;YACT;YACA,IAAI2B,GAAG,CAACV,MAAM,KAAKW,WAAWD,GAAG,CAACV,MAAM,GAAG,CAAC;YAC5CZ,OAAOsB,GAAG,CAACV,MAAM;YACjB;QACF;QAEA,0EAA0E,GAC1E,IAAII,MAAM;YACRhB,IAAI,CAACc,IAAI,GAAGjB;YACZ,OAAOF;QACT;QACA,IAAIK,IAAI,CAACc,IAAI,KAAKS,WAAWvB,IAAI,CAACc,IAAI,GAAG,CAAC;QAC1Cd,OAAOA,IAAI,CAACc,IAAI;IAClB;IAEA,OAAOnB;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|