refactor: plugin export paths

This commit is contained in:
Bereket Engida
2024-11-02 21:33:42 +03:00
parent e0977076f1
commit 87f49b7eab
26 changed files with 109 additions and 38 deletions

View File

@@ -14,7 +14,7 @@
"editor.defaultFormatter": "biomejs.biome" "editor.defaultFormatter": "biomejs.biome"
}, },
"[json]": { "[json]": {
"editor.defaultFormatter": "biomejs.biome" "editor.defaultFormatter": "vscode.json-language-features"
}, },
"typescript.tsdk": "node_modules/typescript/lib", "typescript.tsdk": "node_modules/typescript/lib",
"[astro]": { "[astro]": {

View File

@@ -1,12 +1,8 @@
import { betterAuth } from "better-auth"; import { betterAuth } from "better-auth";
import { import { bearer, admin, multiSession } from "better-auth/plugins";
bearer, import { organization } from "better-auth/plugins/organization";
organization, import { passkey } from "better-auth/plugins/passkey";
passkey, import { twoFactor } from "better-auth/plugins/two-factor";
twoFactor,
admin,
multiSession,
} from "better-auth/plugins";
import { reactInvitationEmail } from "./email/invitation"; import { reactInvitationEmail } from "./email/invitation";
import { LibsqlDialect } from "@libsql/kysely-libsql"; import { LibsqlDialect } from "@libsql/kysely-libsql";
import { reactResetPasswordEmail } from "./email/rest-password"; import { reactResetPasswordEmail } from "./email/rest-password";

View File

@@ -28,14 +28,13 @@ This plugin offers two main methods to do a second factor verification:
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { twoFactor } from "better-auth/plugins" // [!code highlight] import { twoFactor } from "better-auth/plugins/two-factor" // [!code highlight]
export const auth = betterAuth({ export const auth = betterAuth({
// ... other config options // ... other config options
appName: "My App", // provide your app name. It'll be used as an issuer. // [!code highlight]
plugins: [ plugins: [
twoFactor({ // [!code highlight] twoFactor() // [!code highlight]
issuer: "my-app" // [!code highlight]
}) // [!code highlight]
] ]
}) })
``` ```

View File

@@ -16,7 +16,7 @@ The Admin plugin provides a set of administrative functions for user management
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { admin } from "better-auth/plugins" // [!code highlight] import { admin } from "better-auth/plugins/admin" // [!code highlight]
export const auth = betterAuth({ export const auth = betterAuth({
// ... other config options // ... other config options

View File

@@ -15,7 +15,7 @@ The Anonymous plugin allows users to have an authenticated experience without re
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { anonymous } from "better-auth/plugins" // [!code highlight] import { anonymous } from "better-auth/plugins/anonymous" // [!code highlight]
export const auth = betterAuth({ export const auth = betterAuth({
// ... other config options // ... other config options

View File

@@ -11,7 +11,7 @@ Add the Bearer plugin to your authentication setup:
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth"; import { betterAuth } from "better-auth";
import { bearer } from "better-auth/plugins"; import { bearer } from "better-auth/plugins/bearer";
export const auth = betterAuth({ export const auth = betterAuth({
plugins: [bearer()] plugins: [bearer()]

View File

@@ -19,7 +19,7 @@ You can't register a user using the email OTP plugin. You can only sign in or ve
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { emailOTP } from "better-auth/plugins" // [!code highlight] import { emailOTP } from "better-auth/plugins/email-otp" // [!code highlight]
export const auth = betterAuth({ export const auth = betterAuth({
// ... other config options // ... other config options

View File

@@ -15,7 +15,7 @@ The Generic OAuth plugin provides a flexible way to integrate authentication wit
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { genericOAuth } from "better-auth/plugins" // [!code highlight] import { genericOAuth } from "better-auth/plugins/generic-oauth" // [!code highlight]
export const auth = betterAuth({ export const auth = betterAuth({
// ... other config options // ... other config options

View File

@@ -17,7 +17,7 @@ The JWT plugin provides endpoints to retrieve a JWT token and a JWKS endpoint to
### Add the plugin to your **auth** config ### Add the plugin to your **auth** config
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { jwt, bearer } from "better-auth/plugins" import { jwt, bearer } from "better-auth/plugins/jwt"
export const auth = betterAuth({ export const auth = betterAuth({
plugins: [ // [!code highlight] plugins: [ // [!code highlight]

View File

@@ -14,7 +14,7 @@ Magic link or email link is a way to authenticate users without a password. When
```ts title="server.ts" ```ts title="server.ts"
import { betterAuth } from "better-auth"; import { betterAuth } from "better-auth";
import { magicLink } from "better-auth/plugins"; import { magicLink } from "better-auth/plugins/magic-link";
export const auth = betterAuth({ export const auth = betterAuth({
plugins: [ plugins: [

View File

@@ -12,7 +12,7 @@ The multi-session plugin allows users to maintain multiple active sessions acros
### Add the plugin to your **auth** config ### Add the plugin to your **auth** config
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { multiSession } from "better-auth/plugins" import { multiSession } from "better-auth/plugins/multi-session"
export const auth = betterAuth({ export const auth = betterAuth({
plugins: [ // [!code highlight] plugins: [ // [!code highlight]

View File

@@ -12,7 +12,7 @@ Organizations simplifies user access and permissions management. Assign roles an
### Add the plugin to your **auth** config ### Add the plugin to your **auth** config
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { organization } from "better-auth/plugins" import { organization } from "better-auth/plugins/organization"
export const auth = betterAuth({ export const auth = betterAuth({
plugins: [ // [!code highlight] plugins: [ // [!code highlight]

View File

@@ -24,7 +24,7 @@ The passkey plugin implementation is powered by [simple-web-authn](https://simpl
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { passkey } from "better-auth/plugins" import { passkey } from "better-auth/plugins/passkey"
export const auth = betterAuth({ export const auth = betterAuth({

View File

@@ -13,7 +13,7 @@ The phone number plugin extends the authentication system by allowing users to s
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { phoneNumber } from "better-auth/plugins" import { phoneNumber } from "better-auth/plugins/phone-number"
const auth = betterAuth({ const auth = betterAuth({
plugins: [ plugins: [

View File

@@ -13,7 +13,7 @@ The username plugin wraps the email and password authenticator and adds username
```ts title="auth.ts" ```ts title="auth.ts"
import { betterAuth } from "better-auth" import { betterAuth } from "better-auth"
import { username } from "better-auth/plugins" import { username } from "better-auth/plugins/username"
const auth = betterAuth({ const auth = betterAuth({
plugins: [ // [!code highlight] plugins: [ // [!code highlight]

View File

@@ -93,9 +93,69 @@
"require": "./dist/plugins.cjs" "require": "./dist/plugins.cjs"
}, },
"./plugins/access": { "./plugins/access": {
"types": "./dist/access.d.ts", "types": "./dist/plugins/access.d.ts",
"import": "./dist/access.js", "import": "./dist/plugins/access.js",
"require": "./dist/access.cjs" "require": "./dist/plugins/access.cjs"
},
"./plugins/admin": {
"types": "./dist/plugins/admin.d.ts",
"import": "./dist/plugins/admin.js",
"require": "./dist/plugins/admin.cjs"
},
"./plugins/anonymous": {
"types": "./dist/plugins/anonymous.d.ts",
"import": "./dist/plugins/anonymous.js",
"require": "./dist/plugins/anonymous.cjs"
},
"./plugins/bearer": {
"types": "./dist/plugins/bearer.d.ts",
"import": "./dist/plugins/bearer.js",
"require": "./dist/plugins/bearer.cjs"
},
"./plugins/email-otp": {
"types": "./dist/plugins/email-otp.d.ts",
"import": "./dist/plugins/email-otp.js",
"require": "./dist/plugins/email-otp.cjs"
},
"./plugins/generic-oauth": {
"types": "./dist/plugins/generic-oauth.d.ts",
"import": "./dist/plugins/generic-oauth.js",
"require": "./dist/plugins/generic-oauth.cjs"
},
"./plugins/jwt": {
"types": "./dist/plugins/jwt.d.ts",
"import": "./dist/plugins/jwt.js",
"require": "./dist/plugins/jwt.cjs"
},
"./plugins/magic-link": {
"types": "./dist/plugins/magic-link.d.ts",
"import": "./dist/plugins/magic-link.js",
"require": "./dist/plugins/magic-link.cjs"
},
"./plugins/organization": {
"types": "./dist/plugins/organization.d.ts",
"import": "./dist/plugins/organization.js",
"require": "./dist/plugins/organization.cjs"
},
"./plugins/passkey": {
"types": "./dist/plugins/passkey.d.ts",
"import": "./dist/plugins/passkey.js",
"require": "./dist/plugins/passkey.cjs"
},
"./plugins/phone-number": {
"types": "./dist/plugins/phone-number.d.ts",
"import": "./dist/plugins/phone-number.js",
"require": "./dist/plugins/phone-number.cjs"
},
"./plugins/two-factor": {
"types": "./dist/plugins/two-factor.d.ts",
"import": "./dist/plugins/two-factor.js",
"require": "./dist/plugins/two-factor.cjs"
},
"./plugins/username": {
"types": "./dist/plugins/username.d.ts",
"import": "./dist/plugins/username.js",
"require": "./dist/plugins/username.cjs"
}, },
"./svelte-kit": { "./svelte-kit": {
"types": "./dist/svelte-kit.d.ts", "types": "./dist/svelte-kit.d.ts",
@@ -274,4 +334,4 @@
"files": [ "files": [
"dist" "dist"
] ]
} }

View File

@@ -1,4 +1,4 @@
import type { LiteralString } from "../../../../types/helper"; import type { LiteralString } from "../../../types/helper";
// Transforms an array into any combination of 0 or more of its members // Transforms an array into any combination of 0 or more of its members
export type SubArray<T extends unknown[] | readonly unknown[] | any[]> = export type SubArray<T extends unknown[] | readonly unknown[] | any[]> =

View File

@@ -1,8 +1,8 @@
import { APIError, type Context, createEndpointCreator } from "better-call"; import { type Context } from "better-call";
import type { Session, User } from "../../db/schema"; import type { Session, User } from "../../db/schema";
import { createAuthMiddleware, optionsMiddleware } from "../../api/call"; import { createAuthMiddleware } from "../../api/call";
import { sessionMiddleware } from "../../api"; import { sessionMiddleware } from "../../api";
import type { Role, defaultRoles } from "./access"; import type { Role, defaultRoles } from "../access";
import type { OrganizationOptions } from "./organization"; import type { OrganizationOptions } from "./organization";
export const orgMiddleware = createAuthMiddleware(async (ctx) => { export const orgMiddleware = createAuthMiddleware(async (ctx) => {

View File

@@ -5,7 +5,7 @@ import type {
Organization, Organization,
} from "../../plugins/organization/schema"; } from "../../plugins/organization/schema";
import type { Prettify } from "../../types/helper"; import type { Prettify } from "../../types/helper";
import { defaultStatements, type AccessControl, type Role } from "./access"; import { defaultStatements, type AccessControl, type Role } from "../access";
import type { BetterAuthClientPlugin } from "../../client/types"; import type { BetterAuthClientPlugin } from "../../client/types";
import type { organization } from "./organization"; import type { organization } from "./organization";
import type { BetterFetchOption } from "@better-fetch/fetch"; import type { BetterFetchOption } from "@better-fetch/fetch";

View File

@@ -1,2 +1 @@
export * from "./organization"; export * from "./organization";
export * as ac from "./access";

View File

@@ -17,7 +17,7 @@ import {
type Role, type Role,
defaultRoles, defaultRoles,
type defaultStatements, type defaultStatements,
} from "./access"; } from "../access";
import { getOrgAdapter } from "./adapter"; import { getOrgAdapter } from "./adapter";
import { orgSessionMiddleware } from "./call"; import { orgSessionMiddleware } from "./call";
import { import {

View File

@@ -1,8 +1,26 @@
import * as fs from "fs/promises";
import { defineConfig } from "tsup"; import { defineConfig } from "tsup";
export default defineConfig((env) => { export default defineConfig(async (env) => {
const pluginEntries = await fs
.readFile("./package.json", "utf-8")
.then((content) => {
const { exports } = JSON.parse(content);
let entries = {};
Object.keys(exports).forEach((key) => {
if (key.startsWith("./plugins")) {
entries[key.replace("./", "")] = `./src${key.replace(
".",
"",
)}/index.ts`;
}
});
return entries;
});
console.log(pluginEntries);
return { return {
entry: { entry: {
...pluginEntries,
index: "./src/index.ts", index: "./src/index.ts",
social: "./src/social-providers/index.ts", social: "./src/social-providers/index.ts",
types: "./src/types/index.ts", types: "./src/types/index.ts",
@@ -24,7 +42,6 @@ export default defineConfig((env) => {
api: "./src/api/index.ts", api: "./src/api/index.ts",
"client/plugins": "./src/client/plugins/index.ts", "client/plugins": "./src/client/plugins/index.ts",
"svelte-kit": "./src/integrations/svelte-kit.ts", "svelte-kit": "./src/integrations/svelte-kit.ts",
access: "./src/plugins/organization/access/index.ts",
"solid-start": "./src/integrations/solid-start.ts", "solid-start": "./src/integrations/solid-start.ts",
"next-js": "./src/integrations/next-js.ts", "next-js": "./src/integrations/next-js.ts",
node: "./src/integrations/node.ts", node: "./src/integrations/node.ts",