better-auth-studio 1.1.2-beta.8 → 1.1.2
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/README.md +48 -24
- package/data/default-geo.json +12 -1
- package/dist/adapters/astro.d.ts +1 -1
- package/dist/adapters/astro.d.ts.map +1 -1
- package/dist/adapters/astro.js +17 -15
- package/dist/adapters/astro.js.map +1 -1
- package/dist/adapters/elysia.d.ts +2 -2
- package/dist/adapters/elysia.d.ts.map +1 -1
- package/dist/adapters/elysia.js +17 -15
- package/dist/adapters/elysia.js.map +1 -1
- package/dist/adapters/express.d.ts +2 -2
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +8 -6
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/hono.d.ts +2 -2
- package/dist/adapters/hono.d.ts.map +1 -1
- package/dist/adapters/hono.js +16 -14
- package/dist/adapters/hono.js.map +1 -1
- package/dist/adapters/nextjs.d.ts +1 -1
- package/dist/adapters/nextjs.d.ts.map +1 -1
- package/dist/adapters/nextjs.js +14 -12
- package/dist/adapters/nextjs.js.map +1 -1
- package/dist/adapters/nuxt.d.ts +1 -1
- package/dist/adapters/nuxt.d.ts.map +1 -1
- package/dist/adapters/nuxt.js +26 -24
- package/dist/adapters/nuxt.js.map +1 -1
- package/dist/adapters/remix.d.ts +1 -1
- package/dist/adapters/remix.d.ts.map +1 -1
- package/dist/adapters/remix.js +17 -15
- package/dist/adapters/remix.js.map +1 -1
- package/dist/adapters/solid-start.d.ts +1 -1
- package/dist/adapters/solid-start.d.ts.map +1 -1
- package/dist/adapters/solid-start.js +17 -15
- package/dist/adapters/solid-start.js.map +1 -1
- package/dist/adapters/svelte-kit.d.ts +2 -2
- package/dist/adapters/svelte-kit.d.ts.map +1 -1
- package/dist/adapters/svelte-kit.js +17 -15
- package/dist/adapters/svelte-kit.js.map +1 -1
- package/dist/adapters/tanstack-start.d.ts +1 -1
- package/dist/adapters/tanstack-start.d.ts.map +1 -1
- package/dist/adapters/tanstack-start.js +17 -15
- package/dist/adapters/tanstack-start.js.map +1 -1
- package/dist/add-svelte-kit-env-modules.js +11 -11
- package/dist/auth-adapter.d.ts +1 -1
- package/dist/auth-adapter.js +96 -96
- package/dist/cli/commands/init.js +57 -57
- package/dist/cli.js +75 -75
- package/dist/config.d.ts +5 -5
- package/dist/config.js +37 -37
- package/dist/core/handler.d.ts +1 -1
- package/dist/core/handler.d.ts.map +1 -1
- package/dist/core/handler.js +129 -115
- package/dist/core/handler.js.map +1 -1
- package/dist/data.d.ts +2 -2
- package/dist/data.js +60 -60
- package/dist/geo-service.d.ts +20 -2
- package/dist/geo-service.d.ts.map +1 -1
- package/dist/geo-service.js +185 -82
- package/dist/geo-service.js.map +1 -1
- package/dist/get-tsconfig-info.js +4 -4
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/providers/events/helpers.d.ts +11 -2
- package/dist/providers/events/helpers.d.ts.map +1 -1
- package/dist/providers/events/helpers.js +443 -155
- package/dist/providers/events/helpers.js.map +1 -1
- package/dist/public/assets/main-CXXqNP8R.js +1216 -0
- package/dist/public/assets/main-Dx_SZlEy.css +1 -0
- package/dist/public/index.html +2 -2
- package/dist/routes/api-router.d.ts +2 -2
- package/dist/routes/api-router.js +3 -3
- package/dist/routes.d.ts +4 -4
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +1617 -1329
- package/dist/routes.js.map +1 -1
- package/dist/studio.d.ts +3 -3
- package/dist/studio.d.ts.map +1 -1
- package/dist/studio.js +64 -65
- package/dist/studio.js.map +1 -1
- package/dist/types/events.d.ts +18 -7
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js +185 -165
- package/dist/types/events.js.map +1 -1
- package/dist/types/handler.d.ts +43 -4
- package/dist/types/handler.d.ts.map +1 -1
- package/dist/types/handler.js.map +1 -1
- package/dist/utils/auth-callbacks-injector.d.ts +2 -2
- package/dist/utils/auth-callbacks-injector.js +27 -27
- package/dist/utils/auth-callbacks-wrapper.d.ts +3 -3
- package/dist/utils/auth-callbacks-wrapper.js +117 -107
- package/dist/utils/database-detection.d.ts +1 -1
- package/dist/utils/database-detection.js +44 -44
- package/dist/utils/database-hook-injector.d.ts +3 -3
- package/dist/utils/database-hook-injector.js +135 -131
- package/dist/utils/email-otp-hooks-injector.d.ts +28 -12
- package/dist/utils/email-otp-hooks-injector.js +104 -97
- package/dist/utils/event-ingestion.d.ts +5 -5
- package/dist/utils/event-ingestion.d.ts.map +1 -1
- package/dist/utils/event-ingestion.js +43 -12
- package/dist/utils/event-ingestion.js.map +1 -1
- package/dist/utils/hook-injector.d.ts +8 -2
- package/dist/utils/hook-injector.d.ts.map +1 -1
- package/dist/utils/hook-injector.js +458 -199
- package/dist/utils/hook-injector.js.map +1 -1
- package/dist/utils/html-injector.d.ts +17 -2
- package/dist/utils/html-injector.d.ts.map +1 -1
- package/dist/utils/html-injector.js +44 -39
- package/dist/utils/html-injector.js.map +1 -1
- package/dist/utils/org-hooks-injector.d.ts +3 -3
- package/dist/utils/org-hooks-injector.js +63 -63
- package/dist/utils/org-hooks-wrapper.d.ts +41 -35
- package/dist/utils/org-hooks-wrapper.js +778 -658
- package/dist/utils/organization-hooks-wrapper.d.ts +23 -17
- package/dist/utils/organization-hooks-wrapper.js +325 -277
- package/dist/utils/package-json.js +11 -11
- package/dist/utils/paths.js +1 -1
- package/dist/utils/server-init.d.ts +1 -1
- package/dist/utils/server-init.js +25 -25
- package/dist/utils/session.d.ts +0 -1
- package/dist/utils/session.d.ts.map +1 -1
- package/dist/utils/session.js +19 -12
- package/dist/utils/session.js.map +1 -1
- package/dist/utils.js +24 -24
- package/package.json +26 -24
- package/public/assets/main-CXXqNP8R.js +1216 -0
- package/public/assets/main-Dx_SZlEy.css +1 -0
- package/public/index.html +2 -2
- package/scripts/download-geolite2.js +22 -15
- package/scripts/generate-default-db.js +324 -324
- package/scripts/postinstall.js +25 -25
- package/dist/public/assets/main-CeN9M3ie.js +0 -1194
- package/dist/public/assets/main-GcANPjqc.css +0 -1
- package/public/assets/main-CeN9M3ie.js +0 -1194
- package/public/assets/main-GcANPjqc.css +0 -1
package/README.md
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
# Better Auth Studio
|
|
1
|
+
# Better Auth Studio
|
|
2
2
|
|
|
3
3
|
> ⚠️ **Beta Version Notice**
|
|
4
|
-
>
|
|
4
|
+
>
|
|
5
5
|
> Better Auth Studio is currently in **beta** and in early development. You may encounter bugs or incomplete features. Please report any issues you find on our GitHub repository to help us improve the project. Your feedback is greatly appreciated!
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
A web-based studio interface for managing Better Auth applications. Better Auth Studio provides a comprehensive dashboard for managing users, organizations, teams, and more.
|
|
9
8
|
|
|
10
|
-
##
|
|
11
|
-
|
|
9
|
+
## ✨ Try Better Auth Studio Demo
|
|
10
|
+
|
|
11
|
+
You can try a live, demo version of Better Auth Studio here:
|
|
12
|
+
|
|
13
|
+
👉 **[https://bt-nextjs.vercel.app/admin](https://bt-nextjs.vercel.app/admin)**
|
|
14
|
+
|
|
15
|
+
- **Login email:** `admin@user.com`
|
|
16
|
+
- **Password:** `admin@user.com`
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
This online demo lets you explore the admin studio UI. Please note this is a test environment.
|
|
14
19
|
|
|
15
20
|
## 🚀 Quick Start
|
|
16
21
|
|
|
@@ -37,24 +42,27 @@ pnpm add -g better-auth-studio
|
|
|
37
42
|
Or use pnpx to run it without installation:
|
|
38
43
|
|
|
39
44
|
```bash
|
|
40
|
-
pnpx better-auth-studio [cmd]
|
|
45
|
+
pnpx better-auth-studio [cmd]
|
|
41
46
|
```
|
|
42
47
|
|
|
43
48
|
### Basic Usage
|
|
44
49
|
|
|
45
50
|
1. **Navigate to your Better Auth project directory**
|
|
51
|
+
|
|
46
52
|
```bash
|
|
47
53
|
cd your-better-auth-project
|
|
48
54
|
```
|
|
49
55
|
|
|
50
56
|
2. **Start the studio**
|
|
51
|
-
|
|
57
|
+
|
|
52
58
|
If installed as dev dependency:
|
|
59
|
+
|
|
53
60
|
```bash
|
|
54
61
|
pnpm better-auth-studio start
|
|
55
62
|
```
|
|
56
|
-
|
|
63
|
+
|
|
57
64
|
Or with pnpx:
|
|
65
|
+
|
|
58
66
|
```bash
|
|
59
67
|
pnpx better-auth-studio start
|
|
60
68
|
```
|
|
@@ -78,7 +86,7 @@ Before using Better Auth Studio, ensure you have:
|
|
|
78
86
|
Better Auth Studio automatically detects and works with:
|
|
79
87
|
|
|
80
88
|
- **Prisma** (`prismaAdapter`)
|
|
81
|
-
- **Drizzle** (`drizzleAdapter`)
|
|
89
|
+
- **Drizzle** (`drizzleAdapter`)
|
|
82
90
|
- **SQLite** (`new Database()` from better-sqlite3)
|
|
83
91
|
- **PostgreSQL** (via Prisma or Drizzle)
|
|
84
92
|
- **MySQL** (via Prisma or Drizzle)
|
|
@@ -86,6 +94,7 @@ Better Auth Studio automatically detects and works with:
|
|
|
86
94
|
### Example Configuration Files
|
|
87
95
|
|
|
88
96
|
#### Prisma Setup
|
|
97
|
+
|
|
89
98
|
```typescript
|
|
90
99
|
// auth.ts
|
|
91
100
|
import { betterAuth } from "better-auth";
|
|
@@ -103,6 +112,7 @@ export const auth = betterAuth({
|
|
|
103
112
|
```
|
|
104
113
|
|
|
105
114
|
#### Drizzle Setup
|
|
115
|
+
|
|
106
116
|
```typescript
|
|
107
117
|
// auth.ts
|
|
108
118
|
import { betterAuth } from "better-auth";
|
|
@@ -118,6 +128,7 @@ export const auth = betterAuth({
|
|
|
118
128
|
```
|
|
119
129
|
|
|
120
130
|
#### SQLite Setup
|
|
131
|
+
|
|
121
132
|
```typescript
|
|
122
133
|
// auth.ts
|
|
123
134
|
import { betterAuth } from "better-auth";
|
|
@@ -132,17 +143,21 @@ export const auth = betterAuth({
|
|
|
132
143
|
## 🎯 Features
|
|
133
144
|
|
|
134
145
|
### 📊 Dashboard
|
|
146
|
+
|
|
135
147
|
- **Overview statistics** - User, teams and organization counts data
|
|
136
148
|
|
|
137
149
|
### 👥 User Management
|
|
150
|
+
|
|
138
151
|
- **View all users** - Paginated list with search and filtering
|
|
139
152
|
- **Create users** - Add new users with email/password
|
|
140
153
|
- **Edit users** - Update user information, email verification status
|
|
141
154
|
- **Delete users** - Remove users from the system
|
|
142
155
|
- **Bulk operations** - Seed multiple test users
|
|
143
156
|
- **User details** - View user profiles, and accounts
|
|
157
|
+
- **Last seen** - When events are enabled, the studio injects an optional `lastSeenAt` field on the user model and updates it on each sign-in or session creation. Run your database migration (e.g. `prisma migrate dev` or Drizzle push) to add the `lastSeenAt` column to the user table.
|
|
144
158
|
|
|
145
159
|
### 🏢 Organization Management
|
|
160
|
+
|
|
146
161
|
- **View organizations** - List all organizations with pagination
|
|
147
162
|
- **Create organizations** - Add new organizations with custom slugs
|
|
148
163
|
- **Edit organizations** - Update organization details
|
|
@@ -152,6 +167,7 @@ export const auth = betterAuth({
|
|
|
152
167
|
- **Bulk seeding** - Generate test organizations and teams
|
|
153
168
|
|
|
154
169
|
### ⚙️ Settings & Configuration
|
|
170
|
+
|
|
155
171
|
- **Plugin status** - Check which Better Auth plugins are enabled
|
|
156
172
|
- **Database configuration** - View current database adapter and settings
|
|
157
173
|
- **Social providers** - Configure OAuth providers (GitHub, Google, etc.)
|
|
@@ -160,11 +176,13 @@ export const auth = betterAuth({
|
|
|
160
176
|
## 🛠️ Command Line Options
|
|
161
177
|
|
|
162
178
|
### Start Studio
|
|
179
|
+
|
|
163
180
|
```bash
|
|
164
181
|
pnpx better-auth-studio start [options]
|
|
165
182
|
```
|
|
166
183
|
|
|
167
184
|
**Options:**
|
|
185
|
+
|
|
168
186
|
- `--port <number>` - Specify port (default: 3000)
|
|
169
187
|
- `--host <string>` - Specify host (default: localhost)
|
|
170
188
|
- `--no-open` - Don't automatically open browser
|
|
@@ -172,6 +190,7 @@ pnpx better-auth-studio start [options]
|
|
|
172
190
|
- `--watch` - Watch for changes in auth config file and reload server automatically
|
|
173
191
|
|
|
174
192
|
**Examples:**
|
|
193
|
+
|
|
175
194
|
```bash
|
|
176
195
|
# Start on custom port (if installed as dev dependency)
|
|
177
196
|
pnpm better-auth-studio start --port 3001
|
|
@@ -197,6 +216,7 @@ pnpx better-auth-studio start --port 3001 --watch --config ./src/auth.ts
|
|
|
197
216
|
Specify a custom path to your auth config file when it's in a non-standard location or auto-detection fails.
|
|
198
217
|
|
|
199
218
|
**Example:**
|
|
219
|
+
|
|
200
220
|
```bash
|
|
201
221
|
# With relative path
|
|
202
222
|
pnpm better-auth-studio start --config ./src/lib/auth.ts
|
|
@@ -212,6 +232,7 @@ pnpm better-auth-studio start --config /path/to/project/auth.ts
|
|
|
212
232
|
Automatically reload the server when your `auth.ts` file changes. Perfect for development when iterating on your auth configuration.
|
|
213
233
|
|
|
214
234
|
**Example:**
|
|
235
|
+
|
|
215
236
|
```bash
|
|
216
237
|
# Start with watch mode enabled
|
|
217
238
|
pnpx better-auth-studio start --watch
|
|
@@ -220,6 +241,7 @@ pnpx better-auth-studio start --watch
|
|
|
220
241
|
**How it works:** Monitors your auth config file for changes, automatically restarts the server, and updates the browser UI via WebSocket - no manual refresh needed.
|
|
221
242
|
|
|
222
243
|
### Other Commands
|
|
244
|
+
|
|
223
245
|
```bash
|
|
224
246
|
# Check version
|
|
225
247
|
pnpx better-auth-studio --version
|
|
@@ -247,11 +269,13 @@ pnpm add better-auth-studio
|
|
|
247
269
|
### Setup
|
|
248
270
|
|
|
249
271
|
**Step 1: Initialize configuration**
|
|
272
|
+
|
|
250
273
|
```bash
|
|
251
274
|
pnpx better-auth-studio init
|
|
252
275
|
```
|
|
253
276
|
|
|
254
277
|
This creates a `studio.config.ts` file:
|
|
278
|
+
|
|
255
279
|
```typescript
|
|
256
280
|
import type { StudioConfig } from "better-auth-studio";
|
|
257
281
|
import { auth } from "./lib/auth";
|
|
@@ -275,19 +299,14 @@ export default config;
|
|
|
275
299
|
### Next.js (App Router)
|
|
276
300
|
|
|
277
301
|
The init command automatically creates `app/api/studio/[[...path]]/route.ts`:
|
|
302
|
+
|
|
278
303
|
```typescript
|
|
279
304
|
import { betterAuthStudio } from "better-auth-studio/nextjs";
|
|
280
305
|
import studioConfig from "@/studio.config";
|
|
281
306
|
|
|
282
307
|
const handler = betterAuthStudio(studioConfig);
|
|
283
308
|
|
|
284
|
-
export {
|
|
285
|
-
handler as GET,
|
|
286
|
-
handler as POST,
|
|
287
|
-
handler as PUT,
|
|
288
|
-
handler as DELETE,
|
|
289
|
-
handler as PATCH,
|
|
290
|
-
};
|
|
309
|
+
export { handler as GET, handler as POST, handler as PUT, handler as DELETE, handler as PATCH };
|
|
291
310
|
```
|
|
292
311
|
|
|
293
312
|
Access at `http://localhost:3000/api/studio`
|
|
@@ -295,6 +314,7 @@ Access at `http://localhost:3000/api/studio`
|
|
|
295
314
|
### Express
|
|
296
315
|
|
|
297
316
|
Add the studio handler to your server:
|
|
317
|
+
|
|
298
318
|
```typescript
|
|
299
319
|
import express from "express";
|
|
300
320
|
import { toNodeHandler } from "better-auth/node";
|
|
@@ -315,17 +335,20 @@ Access at `http://localhost:3000/api/studio`
|
|
|
315
335
|
|
|
316
336
|
### Configuration Options
|
|
317
337
|
|
|
318
|
-
| Option
|
|
319
|
-
|
|
320
|
-
| `auth`
|
|
321
|
-
| `basePath`
|
|
322
|
-
| `access.allowEmails` | No
|
|
323
|
-
| `access.roles`
|
|
324
|
-
| `
|
|
338
|
+
| Option | Required | Description |
|
|
339
|
+
| -------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
340
|
+
| `auth` | Yes | Your Better Auth instance |
|
|
341
|
+
| `basePath` | Yes | URL path where studio is mounted |
|
|
342
|
+
| `access.allowEmails` | No | Array of admin email addresses |
|
|
343
|
+
| `access.roles` | No | Array of allowed user roles |
|
|
344
|
+
| `ipAddress` | No | IP geolocation for Events/Sessions: `provider` ("ipinfo" \| "ipapi"), `apiToken`, `baseUrl`, optional `endpoint` (ipinfo: "lite" \| "lookup") |
|
|
345
|
+
| `lastSeenAt` | No | Enable last-seen tracking: `{ enabled: true, columnName?: string }` |
|
|
346
|
+
| `metadata` | No | Custom branding (title, theme) |
|
|
325
347
|
|
|
326
348
|
## 📝 Development
|
|
327
349
|
|
|
328
350
|
### Running from Source
|
|
351
|
+
|
|
329
352
|
```bash
|
|
330
353
|
# Clone the repository
|
|
331
354
|
git clone https://github.com/Kinfe123/better-auth-studio.git
|
|
@@ -342,6 +365,7 @@ pnpm dev
|
|
|
342
365
|
```
|
|
343
366
|
|
|
344
367
|
### Contributing
|
|
368
|
+
|
|
345
369
|
1. Fork the repository
|
|
346
370
|
2. Create a feature branch
|
|
347
371
|
3. Make your changes
|
package/data/default-geo.json
CHANGED
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
"description": "Default IP geolocation database for Better Auth Studio",
|
|
5
5
|
"coverage": "Major IP ranges worldwide",
|
|
6
6
|
"ranges": [
|
|
7
|
+
{
|
|
8
|
+
"country": "Ethiopia",
|
|
9
|
+
"countryCode": "ET",
|
|
10
|
+
"city": "Addis Ababa",
|
|
11
|
+
"region": "Addis Ababa",
|
|
12
|
+
"ranges": [
|
|
13
|
+
{ "min": "102.208.97.0", "max": "102.208.97.255" },
|
|
14
|
+
{ "min": "102.208.99.0", "max": "102.208.99.255" },
|
|
15
|
+
{ "min": "102.213.68.0", "max": "102.213.68.255" }
|
|
16
|
+
]
|
|
17
|
+
},
|
|
7
18
|
{
|
|
8
19
|
"country": "United States",
|
|
9
20
|
"countryCode": "US",
|
|
@@ -1123,4 +1134,4 @@
|
|
|
1123
1134
|
],
|
|
1124
1135
|
"totalRanges": 255,
|
|
1125
1136
|
"countries": 12
|
|
1126
|
-
}
|
|
1137
|
+
}
|
package/dist/adapters/astro.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../../src/adapters/astro.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAG7F;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../../src/adapters/astro.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAG7F;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,IAMrC,KAAK;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,KAAG,OAAO,CAAC,QAAQ,CAAC,CAa5D"}
|
package/dist/adapters/astro.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { handleStudioRequest } from
|
|
2
|
-
import { injectEventHooks } from
|
|
1
|
+
import { handleStudioRequest } from "../core/handler.js";
|
|
2
|
+
import { injectEventHooks, injectLastSeenAtHooks } from "../utils/hook-injector.js";
|
|
3
3
|
/**
|
|
4
4
|
* Astro adapter for Better Auth Studio
|
|
5
5
|
*
|
|
@@ -18,8 +18,10 @@ import { injectEventHooks } from '../utils/hook-injector.js';
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export function betterAuthStudio(config) {
|
|
21
|
-
if (config.
|
|
22
|
-
|
|
21
|
+
if (config.auth) {
|
|
22
|
+
injectLastSeenAtHooks(config.auth, config);
|
|
23
|
+
if (config.events?.enabled)
|
|
24
|
+
injectEventHooks(config.auth, config.events);
|
|
23
25
|
}
|
|
24
26
|
return async (ctx) => {
|
|
25
27
|
try {
|
|
@@ -28,10 +30,10 @@ export function betterAuthStudio(config) {
|
|
|
28
30
|
return universalToResponse(universalRes);
|
|
29
31
|
}
|
|
30
32
|
catch (error) {
|
|
31
|
-
console.error(
|
|
32
|
-
return new Response(JSON.stringify({ error:
|
|
33
|
+
console.error("Studio handler error:", error);
|
|
34
|
+
return new Response(JSON.stringify({ error: "Internal server error" }), {
|
|
33
35
|
status: 500,
|
|
34
|
-
headers: {
|
|
36
|
+
headers: { "Content-Type": "application/json" },
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
39
|
};
|
|
@@ -40,16 +42,16 @@ async function convertAstroToUniversal(ctx, config) {
|
|
|
40
42
|
const request = ctx.request;
|
|
41
43
|
let body;
|
|
42
44
|
const method = request.method;
|
|
43
|
-
if (method !==
|
|
44
|
-
const contentType = request.headers.get(
|
|
45
|
-
if (contentType.includes(
|
|
45
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
46
|
+
const contentType = request.headers.get("content-type") || "";
|
|
47
|
+
if (contentType.includes("application/json")) {
|
|
46
48
|
try {
|
|
47
49
|
body = await request.json();
|
|
48
50
|
}
|
|
49
51
|
catch { }
|
|
50
52
|
}
|
|
51
|
-
else if (contentType.includes(
|
|
52
|
-
contentType.includes(
|
|
53
|
+
else if (contentType.includes("application/x-www-form-urlencoded") ||
|
|
54
|
+
contentType.includes("multipart/form-data")) {
|
|
53
55
|
try {
|
|
54
56
|
const formData = await request.formData();
|
|
55
57
|
body = Object.fromEntries(formData.entries());
|
|
@@ -75,12 +77,12 @@ async function convertAstroToUniversal(ctx, config) {
|
|
|
75
77
|
request.headers.forEach((value, key) => {
|
|
76
78
|
headers[key] = value;
|
|
77
79
|
});
|
|
78
|
-
const basePath = config.basePath ||
|
|
79
|
-
const normalizedBasePath = basePath.endsWith(
|
|
80
|
+
const basePath = config.basePath || "/api/studio";
|
|
81
|
+
const normalizedBasePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
|
|
80
82
|
const url = new URL(request.url);
|
|
81
83
|
let path = url.pathname;
|
|
82
84
|
if (path.startsWith(normalizedBasePath)) {
|
|
83
|
-
path = path.slice(normalizedBasePath.length) ||
|
|
85
|
+
path = path.slice(normalizedBasePath.length) || "/";
|
|
84
86
|
}
|
|
85
87
|
const pathWithQuery = path + url.search;
|
|
86
88
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro.js","sourceRoot":"","sources":["../../src/adapters/astro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"astro.js","sourceRoot":"","sources":["../../src/adapters/astro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEpF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAoB;IACnD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,qBAAqB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC3C,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO;YAAE,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,KAAK,EAAE,GAAyB,EAAqB,EAAE;QAC5D,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,MAAM,uBAAuB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAChE,MAAM,YAAY,GAAG,MAAM,mBAAmB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YACrE,OAAO,mBAAmB,CAAC,YAAY,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC,EAAE;gBACtE,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kB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AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAG7F;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"elysia.d.ts","sourceRoot":"","sources":["../../src/adapters/elysia.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAG7F;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,IAMrC,SAAS,OAAO,kBAY/B"}
|
package/dist/adapters/elysia.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { handleStudioRequest } from
|
|
2
|
-
import { injectEventHooks } from
|
|
1
|
+
import { handleStudioRequest } from "../core/handler.js";
|
|
2
|
+
import { injectEventHooks, injectLastSeenAtHooks } from "../utils/hook-injector.js";
|
|
3
3
|
/**
|
|
4
4
|
* Elysia adapter for Better Auth Studio
|
|
5
5
|
*/
|
|
6
6
|
export function betterAuthStudio(config) {
|
|
7
|
-
if (config.
|
|
8
|
-
|
|
7
|
+
if (config.auth) {
|
|
8
|
+
injectLastSeenAtHooks(config.auth, config);
|
|
9
|
+
if (config.events?.enabled)
|
|
10
|
+
injectEventHooks(config.auth, config.events);
|
|
9
11
|
}
|
|
10
12
|
return async (context) => {
|
|
11
13
|
try {
|
|
@@ -14,28 +16,28 @@ export function betterAuthStudio(config) {
|
|
|
14
16
|
return sendElysiaResponse(context, universalRes);
|
|
15
17
|
}
|
|
16
18
|
catch (error) {
|
|
17
|
-
console.error(
|
|
19
|
+
console.error("Studio handler error:", error);
|
|
18
20
|
context.set.status = 500;
|
|
19
|
-
return { error:
|
|
21
|
+
return { error: "Internal server error" };
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
}
|
|
23
25
|
async function convertElysiaToUniversal(context) {
|
|
24
26
|
let body;
|
|
25
27
|
const method = context.request.method;
|
|
26
|
-
if (method !==
|
|
28
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
27
29
|
const elysiaBody = context.body ?? context.query ?? undefined;
|
|
28
30
|
if (elysiaBody !== undefined) {
|
|
29
31
|
body = elysiaBody;
|
|
30
32
|
}
|
|
31
33
|
else {
|
|
32
|
-
const contentType = context.request.headers.get(
|
|
34
|
+
const contentType = context.request.headers.get("content-type") || "";
|
|
33
35
|
try {
|
|
34
|
-
if (contentType.includes(
|
|
36
|
+
if (contentType.includes("application/json")) {
|
|
35
37
|
body = await context.request.json();
|
|
36
38
|
}
|
|
37
|
-
else if (contentType.includes(
|
|
38
|
-
contentType.includes(
|
|
39
|
+
else if (contentType.includes("application/x-www-form-urlencoded") ||
|
|
40
|
+
contentType.includes("multipart/form-data")) {
|
|
39
41
|
const formData = await context.request.formData();
|
|
40
42
|
body = Object.fromEntries(formData.entries());
|
|
41
43
|
}
|
|
@@ -78,9 +80,9 @@ function sendElysiaResponse(context, universal) {
|
|
|
78
80
|
headers: universal.headers,
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
|
-
else if (typeof universal.body ===
|
|
82
|
-
const contentType = universal.headers[
|
|
83
|
-
if (contentType.includes(
|
|
83
|
+
else if (typeof universal.body === "string") {
|
|
84
|
+
const contentType = universal.headers["content-type"] || universal.headers["Content-Type"] || "";
|
|
85
|
+
if (contentType.includes("application/json")) {
|
|
84
86
|
try {
|
|
85
87
|
return JSON.parse(universal.body);
|
|
86
88
|
}
|
|
@@ -88,7 +90,7 @@ function sendElysiaResponse(context, universal) {
|
|
|
88
90
|
return universal.body;
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
|
-
else if (contentType.includes(
|
|
93
|
+
else if (contentType.includes("text/html")) {
|
|
92
94
|
return new Response(universal.body, {
|
|
93
95
|
status: universal.status,
|
|
94
96
|
headers: universal.headers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elysia.js","sourceRoot":"","sources":["../../src/adapters/elysia.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"elysia.js","sourceRoot":"","sources":["../../src/adapters/elysia.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEpF;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAoB;IACnD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,qBAAqB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC3C,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO;YAAE,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,KAAK,EAAE,OAAgB,EAAE,EAAE;QAChC,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,MAAM,wBAAwB,CAAC,OAAO,CAAC,CAAC;YAC7D,MAAM,YAAY,GAAG,MAAM,mBAAmB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YAErE,OAAO,kBAAkB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACnD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;YACzB,OAAO,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,wBAAwB,CAAC,OAAgB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c,CAAC,IAAI,EAAE,CAAC;QAC/E,IAAI,WAAW,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACpC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,SAAS,CAAC,IAAI,CAAC;YACxB,CAAC;QACH,CAAC;aAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7C,OAAO,IAAI,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE;gBAClC,MAAM,EAAE,SAAS,CAAC,MAAM;gBACxB,OAAO,EAAE,SAAS,CAAC,OAAO;aAC3B,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC,IAAI,CAAC;QACxB,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Router as ExpressRouter } from
|
|
2
|
-
import type { StudioConfig } from
|
|
1
|
+
import type { Router as ExpressRouter } from "express";
|
|
2
|
+
import type { StudioConfig } from "../types/handler.js";
|
|
3
3
|
/**
|
|
4
4
|
* Express adapter for Better Auth Studio
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAmC,MAAM,SAAS,CAAC;AAGxF,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAG7F;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAmC,MAAM,SAAS,CAAC;AAGxF,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAG7F;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa,CAqBpE"}
|
package/dist/adapters/express.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { Router } from
|
|
2
|
-
import { handleStudioRequest } from
|
|
3
|
-
import { injectEventHooks } from
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { handleStudioRequest } from "../core/handler.js";
|
|
3
|
+
import { injectEventHooks, injectLastSeenAtHooks } from "../utils/hook-injector.js";
|
|
4
4
|
/**
|
|
5
5
|
* Express adapter for Better Auth Studio
|
|
6
6
|
*/
|
|
7
7
|
export function betterAuthStudio(config) {
|
|
8
|
-
if (config.
|
|
9
|
-
|
|
8
|
+
if (config.auth) {
|
|
9
|
+
injectLastSeenAtHooks(config.auth, config);
|
|
10
|
+
if (config.events?.enabled)
|
|
11
|
+
injectEventHooks(config.auth, config.events);
|
|
10
12
|
}
|
|
11
13
|
const router = Router();
|
|
12
|
-
router.all(
|
|
14
|
+
router.all("*", async (req, res, next) => {
|
|
13
15
|
try {
|
|
14
16
|
const universalReq = convertExpressToUniversal(req);
|
|
15
17
|
const universalRes = await handleStudioRequest(universalReq, config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/adapters/express.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,M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AC,CAAC;IAE7B,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACzD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC"}
|
package/dist/adapters/hono.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../src/adapters/hono.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAG7F;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../src/adapters/hono.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAG7F;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,IAMrC,GAAG,OAAO,uBAYzB"}
|
package/dist/adapters/hono.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { handleStudioRequest } from
|
|
2
|
-
import { injectEventHooks } from
|
|
1
|
+
import { handleStudioRequest } from "../core/handler.js";
|
|
2
|
+
import { injectEventHooks, injectLastSeenAtHooks } from "../utils/hook-injector.js";
|
|
3
3
|
/**
|
|
4
4
|
* Hono adapter for Better Auth Studio
|
|
5
5
|
*/
|
|
6
6
|
export function betterAuthStudio(config) {
|
|
7
|
-
if (config.
|
|
8
|
-
|
|
7
|
+
if (config.auth) {
|
|
8
|
+
injectLastSeenAtHooks(config.auth, config);
|
|
9
|
+
if (config.events?.enabled)
|
|
10
|
+
injectEventHooks(config.auth, config.events);
|
|
9
11
|
}
|
|
10
12
|
return async (c) => {
|
|
11
13
|
try {
|
|
@@ -14,23 +16,23 @@ export function betterAuthStudio(config) {
|
|
|
14
16
|
return sendHonoResponse(c, universalRes);
|
|
15
17
|
}
|
|
16
18
|
catch (error) {
|
|
17
|
-
console.error(
|
|
18
|
-
return c.json({ error:
|
|
19
|
+
console.error("Studio handler error:", error);
|
|
20
|
+
return c.json({ error: "Internal server error" }, 500);
|
|
19
21
|
}
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
24
|
async function convertHonoToUniversal(c) {
|
|
23
25
|
let body;
|
|
24
26
|
const method = c.req.method;
|
|
25
|
-
if (method !==
|
|
26
|
-
const contentType = c.req.header(
|
|
27
|
-
if (contentType.includes(
|
|
27
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
28
|
+
const contentType = c.req.header("content-type") || "";
|
|
29
|
+
if (contentType.includes("application/json")) {
|
|
28
30
|
try {
|
|
29
31
|
body = await c.req.json();
|
|
30
32
|
}
|
|
31
33
|
catch { }
|
|
32
34
|
}
|
|
33
|
-
else if (contentType.includes(
|
|
35
|
+
else if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
34
36
|
try {
|
|
35
37
|
body = await c.req.parseBody();
|
|
36
38
|
}
|
|
@@ -58,9 +60,9 @@ function sendHonoResponse(c, universal) {
|
|
|
58
60
|
if (Buffer.isBuffer(universal.body)) {
|
|
59
61
|
return c.body(universal.body);
|
|
60
62
|
}
|
|
61
|
-
else if (typeof universal.body ===
|
|
62
|
-
const contentType = universal.headers[
|
|
63
|
-
if (contentType.includes(
|
|
63
|
+
else if (typeof universal.body === "string") {
|
|
64
|
+
const contentType = universal.headers["content-type"] || universal.headers["Content-Type"] || "";
|
|
65
|
+
if (contentType.includes("application/json")) {
|
|
64
66
|
try {
|
|
65
67
|
return c.json(JSON.parse(universal.body));
|
|
66
68
|
}
|
|
@@ -68,7 +70,7 @@ function sendHonoResponse(c, universal) {
|
|
|
68
70
|
return c.text(universal.body);
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
|
-
else if (contentType.includes(
|
|
73
|
+
else if (contentType.includes("text/html")) {
|
|
72
74
|
return c.html(universal.body);
|
|
73
75
|
}
|
|
74
76
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.js","sourceRoot":"","sources":["../../src/adapters/hono.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"hono.js","sourceRoot":"","sources":["../../src/adapters/hono.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEpF;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAoB;IACnD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,qBAAqB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC3C,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO;YAAE,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,KAAK,EAAE,CAAU,EAAE,EAAE;QAC1B,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,CAAC,CAAC,CAAC;YAErD,MAAM,Y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;QACH,CAAC;aAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7C,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../../src/adapters/nextjs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAY7F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../../src/adapters/nextjs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAuC,MAAM,qBAAqB,CAAC;AAY7F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,IAMrC,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAanD"}
|