@emulators/adapter-next 0.4.0 → 0.4.1

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.
Files changed (2) hide show
  1. package/README.md +120 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # @emulators/adapter-next
2
+
3
+ Next.js App Router integration for emulate. Embed emulators directly in your Next.js app so they run on the same origin, solving the Vercel preview deployment problem where OAuth callback URLs change with every deployment.
4
+
5
+ Part of [emulate](https://github.com/vercel-labs/emulate) — local drop-in replacement services for CI and no-network sandboxes.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @emulators/adapter-next
11
+ ```
12
+
13
+ Only install the emulators you need alongside the adapter:
14
+
15
+ ```bash
16
+ npm install @emulators/adapter-next @emulators/github @emulators/google
17
+ ```
18
+
19
+ ## Route handler
20
+
21
+ Create a catch-all route that serves emulator traffic:
22
+
23
+ ```typescript
24
+ // app/emulate/[...path]/route.ts
25
+ import { createEmulateHandler } from '@emulators/adapter-next'
26
+ import * as github from '@emulators/github'
27
+ import * as google from '@emulators/google'
28
+
29
+ export const { GET, POST, PUT, PATCH, DELETE } = createEmulateHandler({
30
+ services: {
31
+ github: {
32
+ emulator: github,
33
+ seed: {
34
+ users: [{ login: 'octocat', name: 'The Octocat' }],
35
+ repos: [{ owner: 'octocat', name: 'hello-world', auto_init: true }],
36
+ },
37
+ },
38
+ google: {
39
+ emulator: google,
40
+ seed: {
41
+ users: [{ email: 'test@example.com', name: 'Test User' }],
42
+ },
43
+ },
44
+ },
45
+ })
46
+ ```
47
+
48
+ ## Auth.js / NextAuth configuration
49
+
50
+ Point your provider at the emulator paths on the same origin:
51
+
52
+ ```typescript
53
+ import GitHub from 'next-auth/providers/github'
54
+
55
+ const baseUrl = process.env.VERCEL_URL
56
+ ? `https://${process.env.VERCEL_URL}`
57
+ : 'http://localhost:3000'
58
+
59
+ GitHub({
60
+ clientId: 'any-value',
61
+ clientSecret: 'any-value',
62
+ authorization: { url: `${baseUrl}/emulate/github/login/oauth/authorize` },
63
+ token: { url: `${baseUrl}/emulate/github/login/oauth/access_token` },
64
+ userinfo: { url: `${baseUrl}/emulate/github/user` },
65
+ })
66
+ ```
67
+
68
+ No `oauth_apps` need to be seeded. When none are configured, the emulator skips `client_id`, `client_secret`, and `redirect_uri` validation.
69
+
70
+ ## Font files in serverless
71
+
72
+ Emulator UI pages use bundled fonts. Wrap your Next.js config to include them in the serverless trace:
73
+
74
+ ```typescript
75
+ // next.config.mjs
76
+ import { withEmulate } from '@emulators/adapter-next'
77
+
78
+ export default withEmulate({
79
+ // your normal Next.js config
80
+ })
81
+ ```
82
+
83
+ If you mount the catch-all at a custom path, pass the matching prefix:
84
+
85
+ ```typescript
86
+ export default withEmulate(nextConfig, { routePrefix: '/api/emulate' })
87
+ ```
88
+
89
+ ## Persistence
90
+
91
+ By default, emulator state is in-memory and resets on every cold start. To persist state across restarts, pass a `persistence` adapter:
92
+
93
+ ```typescript
94
+ import { createEmulateHandler } from '@emulators/adapter-next'
95
+ import * as github from '@emulators/github'
96
+
97
+ const kvAdapter = {
98
+ async load() { return await kv.get('emulate-state') },
99
+ async save(data: string) { await kv.set('emulate-state', data) },
100
+ }
101
+
102
+ export const { GET, POST, PUT, PATCH, DELETE } = createEmulateHandler({
103
+ services: { github: { emulator: github } },
104
+ persistence: kvAdapter,
105
+ })
106
+ ```
107
+
108
+ For local development, `@emulators/core` ships `filePersistence`:
109
+
110
+ ```typescript
111
+ import { filePersistence } from '@emulators/core'
112
+
113
+ // ...
114
+ persistence: filePersistence('.emulate/state.json'),
115
+ ```
116
+
117
+ ## Links
118
+
119
+ - [Full documentation](https://emulate.dev)
120
+ - [GitHub](https://github.com/vercel-labs/emulate)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emulators/adapter-next",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
- "@emulators/core": "0.4.0"
31
+ "@emulators/core": "0.4.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "tsup": "^8",