@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,482 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module generates PayloadCMS collection configurations based on the Better Auth schema.
|
|
3
|
+
*
|
|
4
|
+
* The generated collection configs include:
|
|
5
|
+
* - Users: For user management with proper auth configuration
|
|
6
|
+
* - Sessions: For maintaining user sessions
|
|
7
|
+
* - Accounts: For OAuth provider accounts
|
|
8
|
+
* - VerificationTokens: For email verification or social sign in
|
|
9
|
+
*
|
|
10
|
+
* Each collection is properly formatted with:
|
|
11
|
+
* - Appropriate field types (text, relationship, checkbox, etc.)
|
|
12
|
+
* - Admin configuration for better UI experience
|
|
13
|
+
* - Auth configuration for the Users collection
|
|
14
|
+
* - Proper field relationships between collections
|
|
15
|
+
*
|
|
16
|
+
* Users can copy these generated collection configs to their PayloadCMS project
|
|
17
|
+
* and add authentication strategies as needed.
|
|
18
|
+
*/ import { createContextLogger } from "@revealui/infrastructure";
|
|
19
|
+
import { getAuthTables } from "better-auth/db";
|
|
20
|
+
const logger = createContextLogger('auth:generate-schema');
|
|
21
|
+
const RESERVED_FIELD_NAMES = new Set([
|
|
22
|
+
'id',
|
|
23
|
+
'createdAt',
|
|
24
|
+
'updatedAt'
|
|
25
|
+
]);
|
|
26
|
+
let biomeFormatterPromise = null;
|
|
27
|
+
function isModuleNotFoundError(error) {
|
|
28
|
+
if (!error || typeof error !== 'object') {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if ('code' in error && typeof error.code === 'string') {
|
|
32
|
+
const code = error.code;
|
|
33
|
+
return code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND';
|
|
34
|
+
}
|
|
35
|
+
if ('message' in error && typeof error.message === 'string') {
|
|
36
|
+
const message = error.message;
|
|
37
|
+
return message.includes('Cannot find module') || message.includes('Cannot find package');
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
async function loadBiomeFormatter() {
|
|
42
|
+
if (biomeFormatterPromise) {
|
|
43
|
+
return biomeFormatterPromise;
|
|
44
|
+
}
|
|
45
|
+
const loader = new Function('specifier', 'return import(specifier);');
|
|
46
|
+
biomeFormatterPromise = loader('@biomejs/biome').then((module)=>{
|
|
47
|
+
if (typeof module?.formatContent === 'function') {
|
|
48
|
+
return module.formatContent.bind(module);
|
|
49
|
+
}
|
|
50
|
+
logger.warn('Biome module loaded without formatContent export, skipping formatting');
|
|
51
|
+
return null;
|
|
52
|
+
}).catch((error)=>{
|
|
53
|
+
if (isModuleNotFoundError(error)) {
|
|
54
|
+
logger.debug('Biome formatter not installed, skipping formatting');
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
logger.warn('Unable to load Biome formatter, skipping formatting', {
|
|
58
|
+
error
|
|
59
|
+
});
|
|
60
|
+
return null;
|
|
61
|
+
});
|
|
62
|
+
return biomeFormatterPromise;
|
|
63
|
+
}
|
|
64
|
+
async function formatWithBiome(code, filePath) {
|
|
65
|
+
try {
|
|
66
|
+
const formatContent = await loadBiomeFormatter();
|
|
67
|
+
if (!formatContent) {
|
|
68
|
+
return code;
|
|
69
|
+
}
|
|
70
|
+
const result = await formatContent({
|
|
71
|
+
configuration: {
|
|
72
|
+
formatter: {
|
|
73
|
+
enabled: true,
|
|
74
|
+
formatWithErrors: false,
|
|
75
|
+
indentStyle: 'space',
|
|
76
|
+
indentWidth: 2,
|
|
77
|
+
lineWidth: 100
|
|
78
|
+
},
|
|
79
|
+
javascript: {
|
|
80
|
+
formatter: {
|
|
81
|
+
arrowParentheses: 'asNeeded',
|
|
82
|
+
bracketSameLine: false,
|
|
83
|
+
bracketSpacing: true,
|
|
84
|
+
jsxQuoteStyle: 'single',
|
|
85
|
+
quoteStyle: 'single',
|
|
86
|
+
semicolons: 'always',
|
|
87
|
+
trailingCommas: 'es5'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
content: code,
|
|
92
|
+
filePath
|
|
93
|
+
});
|
|
94
|
+
const errors = result.diagnostics?.filter((diagnostic)=>diagnostic.severity === 'error') ?? [];
|
|
95
|
+
if (errors.length > 0) {
|
|
96
|
+
const message = errors.map((diagnostic)=>diagnostic.message).join('\n');
|
|
97
|
+
throw new Error(`Biome formatting failed:\n${message}`);
|
|
98
|
+
}
|
|
99
|
+
return result.content;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
logger.warn('Biome formatter encountered an unexpected error, skipping formatting', {
|
|
102
|
+
error
|
|
103
|
+
});
|
|
104
|
+
return code;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export const generateSchemaBuilderStage = async ({ BAOptions, code })=>{
|
|
108
|
+
const formattedCode = await formatWithBiome(code, 'schema.ts');
|
|
109
|
+
const { collections, post } = parseExistingSchema(formattedCode);
|
|
110
|
+
const payloadSchemaStr = generatePayloadCollectionConfigs({
|
|
111
|
+
collections,
|
|
112
|
+
exports: post,
|
|
113
|
+
options: BAOptions
|
|
114
|
+
});
|
|
115
|
+
return await formatWithBiome(`${payloadSchemaStr}`, 'schema.ts');
|
|
116
|
+
};
|
|
117
|
+
function parseExistingSchema(code) {
|
|
118
|
+
const definitions = extractCollectionDefinitions(code);
|
|
119
|
+
const collections = definitions.map(({ definition, name })=>buildCollectionConfig(name, definition));
|
|
120
|
+
const post = extractExportStatement(code);
|
|
121
|
+
return {
|
|
122
|
+
collections,
|
|
123
|
+
post
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function extractCollectionDefinitions(code) {
|
|
127
|
+
const definitions = [];
|
|
128
|
+
const startRegex = /const\s+([A-Z][a-zA-Z0-9]*)\s*:\s*CollectionConfig\s*=\s*{/g;
|
|
129
|
+
for(let match = startRegex.exec(code); match !== null; match = startRegex.exec(code)){
|
|
130
|
+
const matchedName = match[1];
|
|
131
|
+
if (!matchedName) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const collectionName = matchedName;
|
|
135
|
+
const blockEndIndex = findBlockEnd(code, startRegex.lastIndex);
|
|
136
|
+
const asConstIndex = code.indexOf('as const;', blockEndIndex);
|
|
137
|
+
const sliceEnd = asConstIndex === -1 ? blockEndIndex : asConstIndex + 'as const;'.length;
|
|
138
|
+
const definition = code.slice(match.index, sliceEnd);
|
|
139
|
+
definitions.push({
|
|
140
|
+
definition,
|
|
141
|
+
name: collectionName
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return definitions;
|
|
145
|
+
}
|
|
146
|
+
function findBlockEnd(code, startIndex) {
|
|
147
|
+
let depth = 1;
|
|
148
|
+
for(let index = startIndex; index < code.length; index += 1){
|
|
149
|
+
const character = code[index];
|
|
150
|
+
if (character === '{') {
|
|
151
|
+
depth += 1;
|
|
152
|
+
} else if (character === '}') {
|
|
153
|
+
depth -= 1;
|
|
154
|
+
if (depth === 0) {
|
|
155
|
+
return index + 1;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return code.length;
|
|
160
|
+
}
|
|
161
|
+
function buildCollectionConfig(collectionName, collectionDef) {
|
|
162
|
+
const slugMatch = /slug:\s*"([^"]+)"/.exec(collectionDef);
|
|
163
|
+
const titleMatch = /useAsTitle:\s*"([^"]+)"/.exec(collectionDef);
|
|
164
|
+
const timestampsMatch = /timestamps:\s*(true|false)/.exec(collectionDef);
|
|
165
|
+
const fields = extractFields(collectionDef);
|
|
166
|
+
return {
|
|
167
|
+
admin: {
|
|
168
|
+
useAsTitle: titleMatch?.[1] ?? 'id'
|
|
169
|
+
},
|
|
170
|
+
fields,
|
|
171
|
+
slug: slugMatch?.[1] ?? collectionName.toLowerCase(),
|
|
172
|
+
...timestampsMatch?.[1] === 'true' ? {
|
|
173
|
+
timestamps: true
|
|
174
|
+
} : {}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function extractFields(collectionDef) {
|
|
178
|
+
const fieldsStart = collectionDef.indexOf('fields');
|
|
179
|
+
if (fieldsStart === -1) return [];
|
|
180
|
+
const arrayStart = collectionDef.indexOf('[', fieldsStart);
|
|
181
|
+
if (arrayStart === -1) return [];
|
|
182
|
+
const blocks = collectObjectBlocks(collectionDef, arrayStart + 1);
|
|
183
|
+
return blocks.map((block)=>createFieldConfig(block)).filter((field)=>field !== null);
|
|
184
|
+
}
|
|
185
|
+
function createFieldConfig(fieldBlock) {
|
|
186
|
+
const nameMatch = /name:\s*"([^"]+)"/.exec(fieldBlock);
|
|
187
|
+
const typeMatch = /type:\s*"([^"]+)"/.exec(fieldBlock);
|
|
188
|
+
const requiredMatch = /required:\s*(true|false)/.exec(fieldBlock);
|
|
189
|
+
const uniqueMatch = /unique:\s*(true|false)/.exec(fieldBlock);
|
|
190
|
+
const relationToMatch = /relationTo:\s*"([^"]+)"/.exec(fieldBlock);
|
|
191
|
+
if (!nameMatch || !typeMatch) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const fieldName = nameMatch[1];
|
|
195
|
+
const fieldType = typeMatch[1];
|
|
196
|
+
if (!fieldName || !fieldType) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
// Using Record<string, unknown> because PayloadCMS field configuration structure varies by field type and cannot be strictly typed
|
|
200
|
+
const fieldConfig = {
|
|
201
|
+
name: fieldName,
|
|
202
|
+
type: fieldType
|
|
203
|
+
};
|
|
204
|
+
if (requiredMatch) {
|
|
205
|
+
fieldConfig.required = requiredMatch[1] === 'true';
|
|
206
|
+
}
|
|
207
|
+
if (uniqueMatch) {
|
|
208
|
+
fieldConfig.unique = uniqueMatch[1] === 'true';
|
|
209
|
+
}
|
|
210
|
+
if (relationToMatch?.[1]) {
|
|
211
|
+
fieldConfig.relationTo = relationToMatch[1];
|
|
212
|
+
}
|
|
213
|
+
return fieldConfig;
|
|
214
|
+
}
|
|
215
|
+
function collectObjectBlocks(source, startIndex) {
|
|
216
|
+
const blocks = [];
|
|
217
|
+
let braceDepth = 0;
|
|
218
|
+
let currentBlock = '';
|
|
219
|
+
for(let index = startIndex; index < source.length; index += 1){
|
|
220
|
+
const character = source.charAt(index);
|
|
221
|
+
switch(character){
|
|
222
|
+
case '{':
|
|
223
|
+
braceDepth += 1;
|
|
224
|
+
currentBlock += character;
|
|
225
|
+
break;
|
|
226
|
+
case '}':
|
|
227
|
+
if (braceDepth > 0) {
|
|
228
|
+
braceDepth -= 1;
|
|
229
|
+
currentBlock += character;
|
|
230
|
+
if (braceDepth === 0 && currentBlock.trim()) {
|
|
231
|
+
blocks.push(currentBlock);
|
|
232
|
+
currentBlock = '';
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
case ']':
|
|
237
|
+
if (braceDepth === 0) {
|
|
238
|
+
return blocks;
|
|
239
|
+
}
|
|
240
|
+
currentBlock += character;
|
|
241
|
+
break;
|
|
242
|
+
default:
|
|
243
|
+
if (braceDepth > 0) {
|
|
244
|
+
currentBlock += character;
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return blocks;
|
|
250
|
+
}
|
|
251
|
+
function extractExportStatement(code) {
|
|
252
|
+
const exportIndex = code.indexOf('export');
|
|
253
|
+
if (exportIndex === -1) return '';
|
|
254
|
+
const openBraceIndex = code.indexOf('{', exportIndex);
|
|
255
|
+
const closeBraceIndex = code.indexOf('}', openBraceIndex + 1);
|
|
256
|
+
if (openBraceIndex === -1 || closeBraceIndex === -1) {
|
|
257
|
+
return '';
|
|
258
|
+
}
|
|
259
|
+
return code.slice(exportIndex, closeBraceIndex + 1);
|
|
260
|
+
}
|
|
261
|
+
function generatePayloadCollectionConfigs({ collections, exports, options }) {
|
|
262
|
+
const tables = getAuthTables(options);
|
|
263
|
+
const existingCollectionsBySlug = buildExistingCollectionMap(collections);
|
|
264
|
+
const header = `/**
|
|
265
|
+
* EXAMPLE COLLECTIONS FOR BETTER AUTH
|
|
266
|
+
*
|
|
267
|
+
* Below is what your Payload collections should look like.
|
|
268
|
+
* Please copy these to your actual collection configs.
|
|
269
|
+
* Make sure to add an authStrategy for the users collection if there is one.
|
|
270
|
+
*
|
|
271
|
+
* Example auth strategy:
|
|
272
|
+
* auth: {
|
|
273
|
+
* disableLocalStrategy: true,
|
|
274
|
+
* strategies: [
|
|
275
|
+
* betterAuthStrategy(),
|
|
276
|
+
* // Add other strategies as needed
|
|
277
|
+
* ],
|
|
278
|
+
* },
|
|
279
|
+
*/
|
|
280
|
+
import type { CollectionConfig } from 'payload';
|
|
281
|
+
|
|
282
|
+
`;
|
|
283
|
+
const generatedCollections = Object.values(tables).map((table)=>renderCollectionFromTable(table, existingCollectionsBySlug)).join('');
|
|
284
|
+
const additionalCollections = collections.filter((collection)=>collection.slug && !Object.prototype.hasOwnProperty.call(tables, collection.slug)).map((collection)=>renderExistingCollection(collection.slug, collection)).join('');
|
|
285
|
+
const exportBlock = buildExportBlock(exports, tables);
|
|
286
|
+
return header + generatedCollections + additionalCollections + exportBlock;
|
|
287
|
+
}
|
|
288
|
+
function toPascalCase(input) {
|
|
289
|
+
return input.split(/[_\s-]+/u).filter(Boolean).map((segment)=>segment.charAt(0).toUpperCase() + segment.slice(1)).join('');
|
|
290
|
+
}
|
|
291
|
+
function getNameField(fields) {
|
|
292
|
+
const values = Object.values(fields ?? {});
|
|
293
|
+
for (const field of values){
|
|
294
|
+
const fieldName = field.fieldName;
|
|
295
|
+
if (typeof fieldName === 'string' && fieldName === 'id') {
|
|
296
|
+
return fieldName;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
for (const field of values){
|
|
300
|
+
const fieldName = field.fieldName;
|
|
301
|
+
if (typeof fieldName === 'string') {
|
|
302
|
+
return fieldName;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return 'id';
|
|
306
|
+
}
|
|
307
|
+
function buildExistingCollectionMap(collections) {
|
|
308
|
+
return collections.reduce((acc, collection)=>{
|
|
309
|
+
if (collection.slug) {
|
|
310
|
+
acc.set(collection.slug, collection);
|
|
311
|
+
}
|
|
312
|
+
return acc;
|
|
313
|
+
}, new Map());
|
|
314
|
+
}
|
|
315
|
+
function renderExistingCollection(name, collection) {
|
|
316
|
+
const pascalCase = toPascalCase(name);
|
|
317
|
+
return `const ${pascalCase}: CollectionConfig = ${JSON.stringify(collection, null, 2)} as const;\n\n`;
|
|
318
|
+
}
|
|
319
|
+
function renderCollectionFromTable(table, existingCollectionsBySlug) {
|
|
320
|
+
const modelName = table.modelName;
|
|
321
|
+
const existingCollection = existingCollectionsBySlug.get(modelName);
|
|
322
|
+
if (existingCollection) {
|
|
323
|
+
return renderExistingCollection(modelName, existingCollection);
|
|
324
|
+
}
|
|
325
|
+
const collectionName = toPascalCase(modelName);
|
|
326
|
+
const authBlock = modelName === 'users' ? renderUsersAuthBlock() : '';
|
|
327
|
+
const fields = renderFieldsForTable(table);
|
|
328
|
+
return `const ${collectionName}: CollectionConfig = {
|
|
329
|
+
slug: "${modelName}",
|
|
330
|
+
admin: {
|
|
331
|
+
useAsTitle: "${getNameField(table.fields)}",
|
|
332
|
+
},
|
|
333
|
+
${authBlock} fields: [
|
|
334
|
+
${fields} ],
|
|
335
|
+
timestamps: true,
|
|
336
|
+
} as const;
|
|
337
|
+
|
|
338
|
+
`;
|
|
339
|
+
}
|
|
340
|
+
function renderUsersAuthBlock() {
|
|
341
|
+
return ` auth: {
|
|
342
|
+
disableLocalStrategy: true,
|
|
343
|
+
strategies: [],
|
|
344
|
+
// Add your auth strategies here if needed
|
|
345
|
+
},
|
|
346
|
+
`;
|
|
347
|
+
}
|
|
348
|
+
function renderFieldsForTable(table) {
|
|
349
|
+
const entries = Object.entries(table.fields ?? {});
|
|
350
|
+
return entries.map(([rawKey, field])=>renderFieldDefinition(rawKey, field)).filter(Boolean).join('');
|
|
351
|
+
}
|
|
352
|
+
function mapFieldType(type, fieldName) {
|
|
353
|
+
if (fieldName.endsWith('_id')) {
|
|
354
|
+
return 'relationship';
|
|
355
|
+
}
|
|
356
|
+
if (type === 'upload') {
|
|
357
|
+
return 'upload';
|
|
358
|
+
}
|
|
359
|
+
return type;
|
|
360
|
+
}
|
|
361
|
+
function renderFieldDefinition(fieldKey, field) {
|
|
362
|
+
const fieldName = field.fieldName ?? fieldKey;
|
|
363
|
+
if (RESERVED_FIELD_NAMES.has(fieldName)) {
|
|
364
|
+
return '';
|
|
365
|
+
}
|
|
366
|
+
const fieldType = mapFieldType(field.type, fieldName);
|
|
367
|
+
const lines = [];
|
|
368
|
+
lines.push(' {');
|
|
369
|
+
lines.push(` name: "${formatFieldName(fieldName, fieldType, field)}",`);
|
|
370
|
+
lines.push(...buildFieldTypeLines(fieldType, fieldName, field));
|
|
371
|
+
appendBooleanField('required', field.required, lines);
|
|
372
|
+
appendBooleanField('unique', field.unique, lines);
|
|
373
|
+
appendSelectOptions(fieldType, field, lines);
|
|
374
|
+
appendDefaultValue(lines, field.defaultValue);
|
|
375
|
+
appendAdminConfig(field, lines);
|
|
376
|
+
lines.push(' },');
|
|
377
|
+
return `${lines.join('\n')}
|
|
378
|
+
`;
|
|
379
|
+
}
|
|
380
|
+
function formatFieldName(fieldName, fieldType, field) {
|
|
381
|
+
if (fieldType === 'relationship') {
|
|
382
|
+
return fieldName.replace('_id', '');
|
|
383
|
+
}
|
|
384
|
+
if (field.references?.model && fieldName.endsWith('_id')) {
|
|
385
|
+
return fieldName.replace('_id', '');
|
|
386
|
+
}
|
|
387
|
+
return fieldName;
|
|
388
|
+
}
|
|
389
|
+
function buildFieldTypeLines(fieldType, fieldName, field) {
|
|
390
|
+
if (fieldType === 'relationship') {
|
|
391
|
+
return [
|
|
392
|
+
' type: "relationship",',
|
|
393
|
+
` relationTo: "${field.references?.model ?? fieldName.replace('_id', '')}",`
|
|
394
|
+
];
|
|
395
|
+
}
|
|
396
|
+
if (fieldType === 'upload') {
|
|
397
|
+
return [
|
|
398
|
+
' type: "upload",',
|
|
399
|
+
' relationTo: "media",'
|
|
400
|
+
];
|
|
401
|
+
}
|
|
402
|
+
return [
|
|
403
|
+
` type: "${fieldType}",`
|
|
404
|
+
];
|
|
405
|
+
}
|
|
406
|
+
function appendBooleanField(key, value, lines) {
|
|
407
|
+
if (value) {
|
|
408
|
+
lines.push(` ${key}: true,`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function appendSelectOptions(fieldType, field, lines) {
|
|
412
|
+
if (fieldType !== 'select' || !Array.isArray(field.options)) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
lines.push(` options: ${JSON.stringify(field.options)},`);
|
|
416
|
+
}
|
|
417
|
+
function appendAdminConfig(field, lines) {
|
|
418
|
+
if (!field.admin?.readOnly) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
lines.push(' admin: {');
|
|
422
|
+
lines.push(' readOnly: true,');
|
|
423
|
+
lines.push(' },');
|
|
424
|
+
}
|
|
425
|
+
function appendDefaultValue(lines, defaultValue) {
|
|
426
|
+
if (defaultValue === undefined) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (typeof defaultValue === 'string') {
|
|
430
|
+
lines.push(` defaultValue: "${defaultValue}",`);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (typeof defaultValue === 'boolean') {
|
|
434
|
+
lines.push(` defaultValue: ${defaultValue ? 'true' : 'false'},`);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (typeof defaultValue === 'function') {
|
|
438
|
+
const stringified = defaultValue.toString();
|
|
439
|
+
if (stringified.includes('() => !1')) {
|
|
440
|
+
lines.push(' defaultValue: false,');
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (stringified.includes('() => !0')) {
|
|
444
|
+
lines.push(' defaultValue: true,');
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
lines.push(` defaultValue: ${String(defaultValue)},`);
|
|
449
|
+
}
|
|
450
|
+
function extractExportedCollections(exportBlock) {
|
|
451
|
+
const openBraceIndex = exportBlock.indexOf('{');
|
|
452
|
+
const closeBraceIndex = exportBlock.indexOf('}', openBraceIndex + 1);
|
|
453
|
+
if (openBraceIndex === -1 || closeBraceIndex === -1) {
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
return exportBlock.slice(openBraceIndex + 1, closeBraceIndex).split(',').map((name)=>name.trim()).filter((name)=>name.length > 0);
|
|
457
|
+
}
|
|
458
|
+
function buildExportBlock(exports, tables) {
|
|
459
|
+
const trimmed = exports.trim();
|
|
460
|
+
if (trimmed.length > 0) {
|
|
461
|
+
const existingCollections = extractExportedCollections(trimmed);
|
|
462
|
+
const generatedCollections = Object.keys(tables).map(toPascalCase);
|
|
463
|
+
const allCollections = [
|
|
464
|
+
...new Set([
|
|
465
|
+
...existingCollections,
|
|
466
|
+
...generatedCollections
|
|
467
|
+
])
|
|
468
|
+
];
|
|
469
|
+
return `export { ${allCollections.join(', ')} };
|
|
470
|
+
`;
|
|
471
|
+
}
|
|
472
|
+
const generated = Object.keys(tables);
|
|
473
|
+
if (generated.length > 0) {
|
|
474
|
+
const pascalNames = generated.map(toPascalCase);
|
|
475
|
+
return `export { ${pascalNames.join(', ')} };
|
|
476
|
+
`;
|
|
477
|
+
}
|
|
478
|
+
return `export {};
|
|
479
|
+
`;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
//# sourceMappingURL=generate-schema-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/better-auth/adapter/generate-schema/generate-schema-builder.ts"],"sourcesContent":["/**\n * This module generates PayloadCMS collection configurations based on the Better Auth schema.\n *\n * The generated collection configs include:\n * - Users: For user management with proper auth configuration\n * - Sessions: For maintaining user sessions\n * - Accounts: For OAuth provider accounts\n * - VerificationTokens: For email verification or social sign in\n *\n * Each collection is properly formatted with:\n * - Appropriate field types (text, relationship, checkbox, etc.)\n * - Admin configuration for better UI experience\n * - Auth configuration for the Users collection\n * - Proper field relationships between collections\n *\n * Users can copy these generated collection configs to their PayloadCMS project\n * and add authentication strategies as needed.\n */\nimport { createContextLogger } from '@revealui/infrastructure';\nimport { getAuthTables } from 'better-auth/db';\n\nimport type { BetterAuthOptions } from 'better-auth';\nimport type { CollectionConfig, Field } from 'payload';\n\nconst logger = createContextLogger('auth:generate-schema');\n\ntype AuthTables = ReturnType<typeof getAuthTables>;\ntype AuthTable = AuthTables[keyof AuthTables];\ntype AuthField = AuthTable['fields'][string] & {\n admin?: { readOnly?: boolean };\n defaultValue?: unknown;\n fieldName?: string;\n options?: unknown[];\n references?: { model?: string };\n type?: string;\n};\n\nconst RESERVED_FIELD_NAMES = new Set(['id', 'createdAt', 'updatedAt']);\n\ntype BiomeDiagnostics = {\n message: string;\n severity?: string;\n};\n\ntype BiomeFormatContentArgs = {\n // Using Record<string, unknown> because Biome configuration structure varies by Biome version and cannot be strictly typed\n configuration: /* Using Record<string, unknown> because Biome configuration structure varies by Biome version and cannot be strictly typed */ Record<\n string,\n unknown\n >;\n content: string;\n filePath: string;\n};\n\ntype BiomeFormatContentResult = {\n content: string;\n diagnostics?: BiomeDiagnostics[];\n};\n\ntype BiomeFormatContent = (args: BiomeFormatContentArgs) => Promise<BiomeFormatContentResult>;\n\nlet biomeFormatterPromise: Promise<BiomeFormatContent | null> | null = null;\n\nfunction isModuleNotFoundError(error: unknown): boolean {\n if (!error || typeof error !== 'object') {\n return false;\n }\n\n if ('code' in error && typeof (error as { code?: unknown }).code === 'string') {\n const code = (error as { code: string }).code;\n return code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND';\n }\n\n if ('message' in error && typeof (error as { message?: unknown }).message === 'string') {\n const message = (error as { message: string }).message;\n return message.includes('Cannot find module') || message.includes('Cannot find package');\n }\n\n return false;\n}\n\nasync function loadBiomeFormatter(): Promise<BiomeFormatContent | null> {\n if (biomeFormatterPromise) {\n return biomeFormatterPromise;\n }\n\n const loader = new Function('specifier', 'return import(specifier);') as (\n specifier: string\n ) => Promise<{ formatContent?: BiomeFormatContent }>;\n\n biomeFormatterPromise = loader('@biomejs/biome')\n .then(module => {\n if (typeof module?.formatContent === 'function') {\n return module.formatContent.bind(module);\n }\n\n logger.warn('Biome module loaded without formatContent export, skipping formatting');\n return null;\n })\n .catch(error => {\n if (isModuleNotFoundError(error)) {\n logger.debug('Biome formatter not installed, skipping formatting');\n return null;\n }\n\n logger.warn('Unable to load Biome formatter, skipping formatting', { error });\n return null;\n });\n\n return biomeFormatterPromise;\n}\n\nasync function formatWithBiome(code: string, filePath: string): Promise<string> {\n try {\n const formatContent = await loadBiomeFormatter();\n if (!formatContent) {\n return code;\n }\n\n const result = await formatContent({\n configuration: {\n formatter: {\n enabled: true,\n formatWithErrors: false,\n indentStyle: 'space',\n indentWidth: 2,\n lineWidth: 100,\n },\n javascript: {\n formatter: {\n arrowParentheses: 'asNeeded',\n bracketSameLine: false,\n bracketSpacing: true,\n jsxQuoteStyle: 'single',\n quoteStyle: 'single',\n semicolons: 'always',\n trailingCommas: 'es5',\n },\n },\n },\n content: code,\n filePath,\n });\n\n const errors = result.diagnostics?.filter(diagnostic => diagnostic.severity === 'error') ?? [];\n if (errors.length > 0) {\n const message = errors.map(diagnostic => diagnostic.message).join('\\n');\n throw new Error(`Biome formatting failed:\\n${message}`);\n }\n\n return result.content;\n } catch (error) {\n logger.warn('Biome formatter encountered an unexpected error, skipping formatting', {\n error,\n });\n return code;\n }\n}\n\nexport const generateSchemaBuilderStage = async ({\n BAOptions,\n code,\n}: {\n code: string;\n BAOptions: BetterAuthOptions;\n}) => {\n const formattedCode = await formatWithBiome(code, 'schema.ts');\n\n const { collections, post } = parseExistingSchema(formattedCode);\n\n const payloadSchemaStr = generatePayloadCollectionConfigs({\n collections,\n exports: post,\n options: BAOptions,\n });\n\n return await formatWithBiome(`${payloadSchemaStr}`, 'schema.ts');\n};\n\nfunction parseExistingSchema(code: string): {\n collections: CollectionConfig[];\n post: string;\n} {\n const definitions = extractCollectionDefinitions(code);\n const collections = definitions.map(({ definition, name }) =>\n buildCollectionConfig(name, definition)\n );\n const post = extractExportStatement(code);\n return { collections, post };\n}\n\nfunction extractCollectionDefinitions(code: string): Array<{ definition: string; name: string }> {\n const definitions: Array<{ definition: string; name: string }> = [];\n const startRegex = /const\\s+([A-Z][a-zA-Z0-9]*)\\s*:\\s*CollectionConfig\\s*=\\s*{/g;\n\n for (let match = startRegex.exec(code); match !== null; match = startRegex.exec(code)) {\n const matchedName = match[1];\n if (!matchedName) {\n continue;\n }\n\n const collectionName = matchedName;\n const blockEndIndex = findBlockEnd(code, startRegex.lastIndex);\n const asConstIndex = code.indexOf('as const;', blockEndIndex);\n const sliceEnd = asConstIndex === -1 ? blockEndIndex : asConstIndex + 'as const;'.length;\n const definition = code.slice(match.index, sliceEnd);\n definitions.push({ definition, name: collectionName });\n }\n\n return definitions;\n}\n\nfunction findBlockEnd(code: string, startIndex: number): number {\n let depth = 1;\n for (let index = startIndex; index < code.length; index += 1) {\n const character = code[index];\n if (character === '{') {\n depth += 1;\n } else if (character === '}') {\n depth -= 1;\n if (depth === 0) {\n return index + 1;\n }\n }\n }\n return code.length;\n}\n\nfunction buildCollectionConfig(collectionName: string, collectionDef: string): CollectionConfig {\n const slugMatch = /slug:\\s*\"([^\"]+)\"/.exec(collectionDef);\n const titleMatch = /useAsTitle:\\s*\"([^\"]+)\"/.exec(collectionDef);\n const timestampsMatch = /timestamps:\\s*(true|false)/.exec(collectionDef);\n const fields = extractFields(collectionDef);\n\n return {\n admin: {\n useAsTitle: titleMatch?.[1] ?? 'id',\n },\n fields,\n slug: slugMatch?.[1] ?? collectionName.toLowerCase(),\n ...(timestampsMatch?.[1] === 'true' ? { timestamps: true } : {}),\n };\n}\n\nfunction extractFields(collectionDef: string): Field[] {\n const fieldsStart = collectionDef.indexOf('fields');\n if (fieldsStart === -1) return [];\n\n const arrayStart = collectionDef.indexOf('[', fieldsStart);\n if (arrayStart === -1) return [];\n\n const blocks = collectObjectBlocks(collectionDef, arrayStart + 1);\n return blocks\n .map(block => createFieldConfig(block))\n .filter((field): field is Field => field !== null);\n}\n\nfunction createFieldConfig(fieldBlock: string): Field | null {\n const nameMatch = /name:\\s*\"([^\"]+)\"/.exec(fieldBlock);\n const typeMatch = /type:\\s*\"([^\"]+)\"/.exec(fieldBlock);\n const requiredMatch = /required:\\s*(true|false)/.exec(fieldBlock);\n const uniqueMatch = /unique:\\s*(true|false)/.exec(fieldBlock);\n const relationToMatch = /relationTo:\\s*\"([^\"]+)\"/.exec(fieldBlock);\n\n if (!nameMatch || !typeMatch) {\n return null;\n }\n\n const fieldName = nameMatch[1];\n const fieldType = typeMatch[1];\n\n if (!fieldName || !fieldType) {\n return null;\n }\n\n // Using Record<string, unknown> because PayloadCMS field configuration structure varies by field type and cannot be strictly typed\n const fieldConfig: /* Using Record<string, unknown> because PayloadCMS field configuration structure varies by field type and cannot be strictly typed */ Record<\n string,\n unknown\n > & {\n name: string;\n type: Field['type'];\n } = {\n name: fieldName,\n type: fieldType as Field['type'],\n };\n\n if (requiredMatch) {\n fieldConfig.required = requiredMatch[1] === 'true';\n }\n\n if (uniqueMatch) {\n fieldConfig.unique = uniqueMatch[1] === 'true';\n }\n\n if (relationToMatch?.[1]) {\n fieldConfig.relationTo = relationToMatch[1];\n }\n\n return fieldConfig as Field;\n}\n\nfunction collectObjectBlocks(source: string, startIndex: number): string[] {\n const blocks: string[] = [];\n let braceDepth = 0;\n let currentBlock = '';\n\n for (let index = startIndex; index < source.length; index += 1) {\n const character = source.charAt(index);\n\n switch (character) {\n case '{':\n braceDepth += 1;\n currentBlock += character;\n break;\n case '}':\n if (braceDepth > 0) {\n braceDepth -= 1;\n currentBlock += character;\n if (braceDepth === 0 && currentBlock.trim()) {\n blocks.push(currentBlock);\n currentBlock = '';\n }\n }\n break;\n case ']':\n if (braceDepth === 0) {\n return blocks;\n }\n currentBlock += character;\n break;\n default:\n if (braceDepth > 0) {\n currentBlock += character;\n }\n break;\n }\n }\n\n return blocks;\n}\n\nfunction extractExportStatement(code: string): string {\n const exportIndex = code.indexOf('export');\n if (exportIndex === -1) return '';\n\n const openBraceIndex = code.indexOf('{', exportIndex);\n const closeBraceIndex = code.indexOf('}', openBraceIndex + 1);\n\n if (openBraceIndex === -1 || closeBraceIndex === -1) {\n return '';\n }\n\n return code.slice(exportIndex, closeBraceIndex + 1);\n}\n\nfunction generatePayloadCollectionConfigs({\n collections,\n exports,\n options,\n}: {\n collections: CollectionConfig[];\n exports: string;\n options: BetterAuthOptions;\n}): string {\n const tables = getAuthTables(options);\n const existingCollectionsBySlug = buildExistingCollectionMap(collections);\n\n const header = `/**\n * EXAMPLE COLLECTIONS FOR BETTER AUTH\n *\n * Below is what your Payload collections should look like.\n * Please copy these to your actual collection configs.\n * Make sure to add an authStrategy for the users collection if there is one.\n *\n * Example auth strategy:\n * auth: {\n * disableLocalStrategy: true,\n * strategies: [\n * betterAuthStrategy(),\n * // Add other strategies as needed\n * ],\n * },\n */\nimport type { CollectionConfig } from 'payload';\n\n`;\n\n const generatedCollections = Object.values(tables)\n .map(table => renderCollectionFromTable(table, existingCollectionsBySlug))\n .join('');\n\n const additionalCollections = collections\n .filter(\n collection =>\n collection.slug && !Object.prototype.hasOwnProperty.call(tables, collection.slug)\n )\n .map(collection => renderExistingCollection(collection.slug as string, collection))\n .join('');\n\n const exportBlock = buildExportBlock(exports, tables);\n\n return header + generatedCollections + additionalCollections + exportBlock;\n}\n\nfunction toPascalCase(input: string): string {\n return input\n .split(/[_\\s-]+/u)\n .filter(Boolean)\n .map(segment => segment.charAt(0).toUpperCase() + segment.slice(1))\n .join('');\n}\n\nfunction getNameField(fields: AuthTable['fields']): string {\n const values = Object.values(fields ?? {});\n\n for (const field of values) {\n const fieldName = (field as { fieldName?: unknown }).fieldName;\n if (typeof fieldName === 'string' && fieldName === 'id') {\n return fieldName;\n }\n }\n\n for (const field of values) {\n const fieldName = (field as { fieldName?: unknown }).fieldName;\n if (typeof fieldName === 'string') {\n return fieldName;\n }\n }\n\n return 'id';\n}\n\nfunction buildExistingCollectionMap(\n collections: CollectionConfig[]\n): Map<string, CollectionConfig> {\n return collections.reduce((acc, collection) => {\n if (collection.slug) {\n acc.set(collection.slug, collection);\n }\n return acc;\n }, new Map<string, CollectionConfig>());\n}\n\nfunction renderExistingCollection(name: string, collection: CollectionConfig): string {\n const pascalCase = toPascalCase(name);\n return `const ${pascalCase}: CollectionConfig = ${JSON.stringify(collection, null, 2)} as const;\\n\\n`;\n}\n\nfunction renderCollectionFromTable(\n table: ReturnType<typeof getAuthTables>[string],\n existingCollectionsBySlug: Map<string, CollectionConfig>\n): string {\n const modelName = table.modelName;\n const existingCollection = existingCollectionsBySlug.get(modelName);\n if (existingCollection) {\n return renderExistingCollection(modelName, existingCollection);\n }\n\n const collectionName = toPascalCase(modelName);\n const authBlock = modelName === 'users' ? renderUsersAuthBlock() : '';\n const fields = renderFieldsForTable(table);\n\n return `const ${collectionName}: CollectionConfig = {\n slug: \"${modelName}\",\n admin: {\n useAsTitle: \"${getNameField(table.fields)}\",\n },\n${authBlock} fields: [\n${fields} ],\n timestamps: true,\n} as const;\n\n`;\n}\n\nfunction renderUsersAuthBlock(): string {\n return ` auth: {\n disableLocalStrategy: true,\n strategies: [],\n // Add your auth strategies here if needed\n },\n`;\n}\n\nfunction renderFieldsForTable(table: ReturnType<typeof getAuthTables>[string]): string {\n const entries = Object.entries(table.fields ?? {}) as Array<\n [string, (typeof table.fields)[keyof typeof table.fields]]\n >;\n\n return entries\n .map(([rawKey, field]) => renderFieldDefinition(rawKey, field as AuthField))\n .filter(Boolean)\n .join('');\n}\n\nfunction mapFieldType(type: string, fieldName: string): string {\n if (fieldName.endsWith('_id')) {\n return 'relationship';\n }\n if (type === 'upload') {\n return 'upload';\n }\n return type;\n}\n\nfunction renderFieldDefinition(fieldKey: string, field: AuthField): string {\n const fieldName = field.fieldName ?? fieldKey;\n if (RESERVED_FIELD_NAMES.has(fieldName)) {\n return '';\n }\n\n const fieldType = mapFieldType(field.type as string, fieldName);\n const lines: string[] = [];\n\n lines.push(' {');\n lines.push(` name: \"${formatFieldName(fieldName, fieldType, field)}\",`);\n lines.push(...buildFieldTypeLines(fieldType, fieldName, field));\n appendBooleanField('required', field.required, lines);\n appendBooleanField('unique', field.unique, lines);\n appendSelectOptions(fieldType, field, lines);\n appendDefaultValue(lines, field.defaultValue);\n appendAdminConfig(field, lines);\n lines.push(' },');\n\n return `${lines.join('\\n')}\n`;\n}\n\nfunction formatFieldName(fieldName: string, fieldType: string, field: AuthField): string {\n if (fieldType === 'relationship') {\n return fieldName.replace('_id', '');\n }\n if (field.references?.model && fieldName.endsWith('_id')) {\n return fieldName.replace('_id', '');\n }\n return fieldName;\n}\n\nfunction buildFieldTypeLines(fieldType: string, fieldName: string, field: AuthField): string[] {\n if (fieldType === 'relationship') {\n return [\n ' type: \"relationship\",',\n ` relationTo: \"${field.references?.model ?? fieldName.replace('_id', '')}\",`,\n ];\n }\n if (fieldType === 'upload') {\n return [' type: \"upload\",', ' relationTo: \"media\",'];\n }\n return [` type: \"${fieldType}\",`];\n}\n\nfunction appendBooleanField(key: string, value: boolean | undefined, lines: string[]): void {\n if (value) {\n lines.push(` ${key}: true,`);\n }\n}\n\nfunction appendSelectOptions(fieldType: string, field: AuthField, lines: string[]): void {\n if (fieldType !== 'select' || !Array.isArray(field.options)) {\n return;\n }\n lines.push(` options: ${JSON.stringify(field.options)},`);\n}\n\nfunction appendAdminConfig(field: AuthField, lines: string[]): void {\n if (!field.admin?.readOnly) {\n return;\n }\n lines.push(' admin: {');\n lines.push(' readOnly: true,');\n lines.push(' },');\n}\n\nfunction appendDefaultValue(lines: string[], defaultValue: unknown): void {\n if (defaultValue === undefined) {\n return;\n }\n\n if (typeof defaultValue === 'string') {\n lines.push(` defaultValue: \"${defaultValue}\",`);\n return;\n }\n\n if (typeof defaultValue === 'boolean') {\n lines.push(` defaultValue: ${defaultValue ? 'true' : 'false'},`);\n return;\n }\n\n if (typeof defaultValue === 'function') {\n const stringified = defaultValue.toString();\n if (stringified.includes('() => !1')) {\n lines.push(' defaultValue: false,');\n return;\n }\n if (stringified.includes('() => !0')) {\n lines.push(' defaultValue: true,');\n return;\n }\n }\n\n lines.push(` defaultValue: ${String(defaultValue)},`);\n}\n\nfunction extractExportedCollections(exportBlock: string): string[] {\n const openBraceIndex = exportBlock.indexOf('{');\n const closeBraceIndex = exportBlock.indexOf('}', openBraceIndex + 1);\n if (openBraceIndex === -1 || closeBraceIndex === -1) {\n return [];\n }\n\n return exportBlock\n .slice(openBraceIndex + 1, closeBraceIndex)\n .split(',')\n .map(name => name.trim())\n .filter(name => name.length > 0);\n}\n\nfunction buildExportBlock(exports: string, tables: ReturnType<typeof getAuthTables>): string {\n const trimmed = exports.trim();\n if (trimmed.length > 0) {\n const existingCollections = extractExportedCollections(trimmed);\n const generatedCollections = Object.keys(tables).map(toPascalCase);\n const allCollections = [...new Set([...existingCollections, ...generatedCollections])];\n return `export { ${allCollections.join(', ')} };\n`;\n }\n\n const generated = Object.keys(tables);\n if (generated.length > 0) {\n const pascalNames = generated.map(toPascalCase);\n return `export { ${pascalNames.join(', ')} };\n`;\n }\n\n return `export {};\n`;\n}\n"],"names":["createContextLogger","getAuthTables","logger","RESERVED_FIELD_NAMES","Set","biomeFormatterPromise","isModuleNotFoundError","error","code","message","includes","loadBiomeFormatter","loader","Function","then","module","formatContent","bind","warn","catch","debug","formatWithBiome","filePath","result","configuration","formatter","enabled","formatWithErrors","indentStyle","indentWidth","lineWidth","javascript","arrowParentheses","bracketSameLine","bracketSpacing","jsxQuoteStyle","quoteStyle","semicolons","trailingCommas","content","errors","diagnostics","filter","diagnostic","severity","length","map","join","Error","generateSchemaBuilderStage","BAOptions","formattedCode","collections","post","parseExistingSchema","payloadSchemaStr","generatePayloadCollectionConfigs","exports","options","definitions","extractCollectionDefinitions","definition","name","buildCollectionConfig","extractExportStatement","startRegex","match","exec","matchedName","collectionName","blockEndIndex","findBlockEnd","lastIndex","asConstIndex","indexOf","sliceEnd","slice","index","push","startIndex","depth","character","collectionDef","slugMatch","titleMatch","timestampsMatch","fields","extractFields","admin","useAsTitle","slug","toLowerCase","timestamps","fieldsStart","arrayStart","blocks","collectObjectBlocks","block","createFieldConfig","field","fieldBlock","nameMatch","typeMatch","requiredMatch","uniqueMatch","relationToMatch","fieldName","fieldType","fieldConfig","type","required","unique","relationTo","source","braceDepth","currentBlock","charAt","trim","exportIndex","openBraceIndex","closeBraceIndex","tables","existingCollectionsBySlug","buildExistingCollectionMap","header","generatedCollections","Object","values","table","renderCollectionFromTable","additionalCollections","collection","prototype","hasOwnProperty","call","renderExistingCollection","exportBlock","buildExportBlock","toPascalCase","input","split","Boolean","segment","toUpperCase","getNameField","reduce","acc","set","Map","pascalCase","JSON","stringify","modelName","existingCollection","get","authBlock","renderUsersAuthBlock","renderFieldsForTable","entries","rawKey","renderFieldDefinition","mapFieldType","endsWith","fieldKey","has","lines","formatFieldName","buildFieldTypeLines","appendBooleanField","appendSelectOptions","appendDefaultValue","defaultValue","appendAdminConfig","replace","references","model","key","value","Array","isArray","readOnly","undefined","stringified","toString","String","extractExportedCollections","trimmed","existingCollections","keys","allCollections","generated","pascalNames"],"mappings":"AAAA;;;;;;;;;;;;;;;;;CAiBC,GACD,SAASA,mBAAmB,QAAQ,2BAA2B;AAC/D,SAASC,aAAa,QAAQ,iBAAiB;AAK/C,MAAMC,SAASF,oBAAoB;AAanC,MAAMG,uBAAuB,IAAIC,IAAI;IAAC;IAAM;IAAa;CAAY;AAwBrE,IAAIC,wBAAmE;AAEvE,SAASC,sBAAsBC,KAAc;IAC3C,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAO;IACT;IAEA,IAAI,UAAUA,SAAS,OAAO,AAACA,MAA6BC,IAAI,KAAK,UAAU;QAC7E,MAAMA,OAAO,AAACD,MAA2BC,IAAI;QAC7C,OAAOA,SAAS,sBAAsBA,SAAS;IACjD;IAEA,IAAI,aAAaD,SAAS,OAAO,AAACA,MAAgCE,OAAO,KAAK,UAAU;QACtF,MAAMA,UAAU,AAACF,MAA8BE,OAAO;QACtD,OAAOA,QAAQC,QAAQ,CAAC,yBAAyBD,QAAQC,QAAQ,CAAC;IACpE;IAEA,OAAO;AACT;AAEA,eAAeC;IACb,IAAIN,uBAAuB;QACzB,OAAOA;IACT;IAEA,MAAMO,SAAS,IAAIC,SAAS,aAAa;IAIzCR,wBAAwBO,OAAO,kBAC5BE,IAAI,CAACC,CAAAA;QACJ,IAAI,OAAOA,QAAQC,kBAAkB,YAAY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ACC;IAEA,MAAM+I,YAAYhE,OAAO8D,IAAI,CAACnE;IAC9B,IAAIqE,UAAUjJ,MAAM,GAAG,GAAG;QACxB,MAAMkJ,cAAcD,UAAUhJ,GAAG,CAAC4F;QAClC,OAAO,CAAC,SAAS,EAAEqD,YAAYhJ,IAAI,CAAC,MAAM;AAC9C,CAAC;IACC;IAEA,OAAO,CAAC;AACV,CAAC;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPayloadSchema: (payloadDirPath: string) => Promise<string>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { createContextLogger } from "@revealui/infrastructure";
|
|
4
|
+
const logger = createContextLogger('auth:get-payload-schema');
|
|
5
|
+
export const getPayloadSchema = async (payloadDirPath)=>{
|
|
6
|
+
const projectRoot = process.cwd();
|
|
7
|
+
const resolvedPayloadDir = resolve(projectRoot, payloadDirPath);
|
|
8
|
+
if (!resolvedPayloadDir.startsWith(projectRoot)) {
|
|
9
|
+
throw new Error('Payload directory must reside within the project root.');
|
|
10
|
+
}
|
|
11
|
+
let files;
|
|
12
|
+
try {
|
|
13
|
+
files = await fs.readdir(resolvedPayloadDir);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (isNodeError(error) && error.code === 'ENOENT') {
|
|
16
|
+
throw new Error(`Payload directory not found at "${resolvedPayloadDir}". Please run this CLI from the project root directory where the payload directory is located, otherwise specify a payload directory path in your payloadAdapter options, under schema_generation.payload_dir_path.`);
|
|
17
|
+
}
|
|
18
|
+
logger.error('Failed to access payload directory', {
|
|
19
|
+
error,
|
|
20
|
+
payloadDirPath: resolvedPayloadDir
|
|
21
|
+
});
|
|
22
|
+
throw new Error(`Failed to access payload directory at "${resolvedPayloadDir}".`);
|
|
23
|
+
}
|
|
24
|
+
if (!files.includes('schema.ts')) return '';
|
|
25
|
+
try {
|
|
26
|
+
const schemaPath = join(resolvedPayloadDir, 'schema.ts');
|
|
27
|
+
const schemaCode = await fs.readFile(schemaPath, 'utf8');
|
|
28
|
+
return schemaCode;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
const schemaPath = join(resolvedPayloadDir, 'schema.ts');
|
|
31
|
+
logger.error('Failed to read schema.ts file', {
|
|
32
|
+
error,
|
|
33
|
+
schemaPath
|
|
34
|
+
});
|
|
35
|
+
throw new Error(`PayloadAdapter: Failed to read schema.ts file from "${resolvedPayloadDir}".`);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
function isNodeError(error) {
|
|
39
|
+
return typeof error === 'object' && error !== null && 'code' in error;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=get-payload-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/better-auth/adapter/generate-schema/get-payload-schema.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\n\nimport { createContextLogger } from '@revealui/infrastructure';\n\nconst logger = createContextLogger('auth:get-payload-schema');\n\nexport const getPayloadSchema = async (payloadDirPath: string): Promise<string> => {\n const projectRoot = process.cwd();\n const resolvedPayloadDir = resolve(projectRoot, payloadDirPath);\n\n if (!resolvedPayloadDir.startsWith(projectRoot)) {\n throw new Error('Payload directory must reside within the project root.');\n }\n\n let files: string[];\n try {\n files = await fs.readdir(resolvedPayloadDir);\n } catch (error: unknown) {\n if (isNodeError(error) && error.code === 'ENOENT') {\n throw new Error(\n `Payload directory not found at \"${resolvedPayloadDir}\". Please run this CLI from the project root directory where the payload directory is located, otherwise specify a payload directory path in your payloadAdapter options, under schema_generation.payload_dir_path.`\n );\n }\n logger.error('Failed to access payload directory', {\n error,\n payloadDirPath: resolvedPayloadDir,\n });\n throw new Error(`Failed to access payload directory at \"${resolvedPayloadDir}\".`);\n }\n\n if (!files.includes('schema.ts')) return '';\n try {\n const schemaPath = join(resolvedPayloadDir, 'schema.ts');\n\n const schemaCode = await fs.readFile(schemaPath, 'utf8');\n return schemaCode;\n } catch (error: unknown) {\n const schemaPath = join(resolvedPayloadDir, 'schema.ts');\n logger.error('Failed to read schema.ts file', { error, schemaPath });\n throw new Error(`PayloadAdapter: Failed to read schema.ts file from \"${resolvedPayloadDir}\".`);\n }\n};\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n return typeof error === 'object' && error !== null && 'code' in error;\n}\n"],"names":["fs","join","resolve","createContextLogger","logger","getPayloadSchema","payloadDirPath","projectRoot","process","cwd","resolvedPayloadDir","startsWith","Error","files","readdir","error","isNodeError","code","includes","schemaPath","schemaCode","readFile"],"mappings":"AAAA,OAAOA,QAAQ,mBAAmB;AAClC,SAASC,IAAI,EAAEC,OAAO,QAAQ,YAAY;AAE1C,SAASC,mBAAmB,QAAQ,2BAA2B;AAE/D,MAAMC,SAASD,oBAAoB;AAEnC,OAAO,MAAME,mBAAmB,OAAOC;IACrC,MAAMC,cAAcC,QAAQC,GAAG;IAC/B,MAAMC,qBAAqBR,QAAQK,aAAaD;IAEhD,IAAI,CAACI,mBAAmBC,UAAU,CAACJ,cAAc;QAC/C,MAAM,IAAIK,MAAM;IAClB;IAEA,IAAIC;IACJ,IAAI;QACFA,QAAQ,MAAMb,GAAGc,OAAO,CAACJ;IAC3B,EAAE,OAAOK,OAAgB;QACvB,IAAIC,YAAYD,UAAUA,MAAME,IAAI,KAAK,UAAU;YACjD,MAAM,IAAIL,MACR,CAAC,gCAAgC,EAAEF,mBAAmB,mNAAmN,CAAC;QAE9Q;QACAN,OAAOW,KAAK,CAAC,sCAAsC;YACjDA;YACAT,gBAAgBI;QAClB;QACA,MAAM,IAAIE,MAAM,CAAC,uCAAuC,EAAEF,mBAAmB,EAAE,CAAC;IAClF;IAEA,IAAI,CAACG,MAAMK,QAAQ,CAAC,cAAc,OAAO;IACzC,IAAI;QACF,MAAMC,aAAalB,KAAKS,oBAAoB;QAE5C,MAAMU,aAAa,MAAMpB,GAAGqB,QAAQ,CAACF,YAAY;QACjD,OAAOC;IACT,EAAE,OAAOL,OAAgB;QACvB,MAAMI,aAAalB,KAAKS,oBAAoB;QAC5CN,OAAOW,KAAK,CAAC,iCAAiC;YAAEA;YAAOI;QAAW;QAClE,MAAM,IAAIP,MAAM,CAAC,oDAAoD,EAAEF,mBAAmB,EAAE,CAAC;IAC/F;AACF,EAAE;AAEF,SAASM,YAAYD,KAAc;IACjC,OAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA;AAClE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { generateSchemaBuilderStage } from "./generate-schema-builder";
|
|
4
|
+
import { getPayloadSchema } from "./get-payload-schema";
|
|
5
|
+
export const generateSchema = async (BAoptions, options = {
|
|
6
|
+
outputDir: './generated'
|
|
7
|
+
})=>{
|
|
8
|
+
const { outputDir } = options;
|
|
9
|
+
const existing_schema_code = await getPayloadSchema(outputDir);
|
|
10
|
+
const new_schema_code = await generateSchemaBuilderStage({
|
|
11
|
+
code: existing_schema_code,
|
|
12
|
+
BAOptions: BAoptions
|
|
13
|
+
});
|
|
14
|
+
const schemaPath = path.resolve(outputDir, 'schema.ts');
|
|
15
|
+
await fs.writeFile(schemaPath, new_schema_code, 'utf8');
|
|
16
|
+
return new_schema_code;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/better-auth/adapter/generate-schema/index.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport type { BetterAuthOptions } from 'better-auth';\nimport { generateSchemaBuilderStage } from './generate-schema-builder';\nimport { getPayloadSchema } from './get-payload-schema';\n\nexport const generateSchema = async (\n BAoptions: BetterAuthOptions,\n options: { outputDir: string } = {\n outputDir: './generated',\n }\n): Promise<string> => {\n const { outputDir } = options;\n const existing_schema_code: string = await getPayloadSchema(outputDir);\n\n const new_schema_code = await generateSchemaBuilderStage({\n code: existing_schema_code,\n BAOptions: BAoptions,\n });\n\n const schemaPath = path.resolve(outputDir, 'schema.ts');\n await fs.writeFile(schemaPath, new_schema_code, 'utf8');\n\n return new_schema_code;\n};\n"],"names":["fs","path","generateSchemaBuilderStage","getPayloadSchema","generateSchema","BAoptions","options","outputDir","existing_schema_code","new_schema_code","code","BAOptions","schemaPath","resolve","writeFile"],"mappings":"AAAA,OAAOA,QAAQ,mBAAmB;AAClC,OAAOC,UAAU,YAAY;AAE7B,SAASC,0BAA0B,QAAQ,4BAA4B;AACvE,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,OAAO,MAAMC,iBAAiB,OAC5BC,WACAC,UAAiC;IAC/BC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IACtB,MAAME,uBAA+B,MAAML,iBAAiBI;IAE5D,MAAME,kBAAkB,MAAMP,2BAA2B;QACvDQ,MAAMF;QACNG,WAAWN;IACb;IAEA,MAAMO,aAAaX,KAAKY,OAAO,CAACN,WAAW;IAC3C,MAAMP,GAAGc,SAAS,CAACF,YAAYH,iBAAiB;IAEhD,OAAOA;AACT,EAAE"}
|