@ebay-dt/bonfire-next 0.1.0-alpha.0 → 0.1.0-alpha.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.
Files changed (45) hide show
  1. package/README.md +254 -31
  2. package/dist/client/index.d.ts.map +1 -1
  3. package/dist/client/index.js.map +1 -1
  4. package/dist/client/lifecycle-provider.d.ts +2 -1
  5. package/dist/client/lifecycle-provider.d.ts.map +1 -1
  6. package/dist/client/lifecycle-provider.js +5 -7
  7. package/dist/client/lifecycle-provider.js.map +1 -1
  8. package/dist/server/agent-actions.d.ts +13 -0
  9. package/dist/server/agent-actions.d.ts.map +1 -0
  10. package/dist/server/agent-actions.js +80 -0
  11. package/dist/server/agent-actions.js.map +1 -0
  12. package/dist/server/auth-boundary.d.ts +1 -0
  13. package/dist/server/auth-boundary.d.ts.map +1 -1
  14. package/dist/server/auth-boundary.js +10 -3
  15. package/dist/server/auth-boundary.js.map +1 -1
  16. package/dist/server/auth-routes.d.ts.map +1 -1
  17. package/dist/server/auth-routes.js.map +1 -1
  18. package/dist/server/create-bonfire-next.d.ts +12 -1
  19. package/dist/server/create-bonfire-next.d.ts.map +1 -1
  20. package/dist/server/create-bonfire-next.js +41 -1
  21. package/dist/server/create-bonfire-next.js.map +1 -1
  22. package/dist/server/index.d.ts +4 -1
  23. package/dist/server/index.d.ts.map +1 -1
  24. package/dist/server/index.js +1 -0
  25. package/dist/server/index.js.map +1 -1
  26. package/dist/server/login-page-model.d.ts.map +1 -1
  27. package/dist/server/login-page-model.js.map +1 -1
  28. package/dist/server/prototype-actions.d.ts +7 -3
  29. package/dist/server/prototype-actions.d.ts.map +1 -1
  30. package/dist/server/prototype-actions.js +84 -5
  31. package/dist/server/prototype-actions.js.map +1 -1
  32. package/dist/server/prototype-dashboard.d.ts +2 -1
  33. package/dist/server/prototype-dashboard.d.ts.map +1 -1
  34. package/dist/server/prototype-dashboard.js +3 -0
  35. package/dist/server/prototype-dashboard.js.map +1 -1
  36. package/dist/server/prototype-environment.d.ts +18 -0
  37. package/dist/server/prototype-environment.d.ts.map +1 -0
  38. package/dist/server/prototype-environment.js +67 -0
  39. package/dist/server/prototype-environment.js.map +1 -0
  40. package/dist/server/prototype-routes.d.ts.map +1 -1
  41. package/dist/server/prototype-routes.js +9 -4
  42. package/dist/server/prototype-routes.js.map +1 -1
  43. package/dist/server/session.d.ts.map +1 -1
  44. package/dist/server/session.js.map +1 -1
  45. package/package.json +6 -6
package/README.md CHANGED
@@ -38,15 +38,80 @@ Create `src/bonfire.ts`:
38
38
  import { createBonfireNext } from "@ebay-dt/bonfire-next/server";
39
39
  import config from "../bonfire.config";
40
40
 
41
+ import { createDeploymentProvider } from "@ebay-dt/bonfire-next/server";
42
+
43
+ const deploymentProvider =
44
+ process.env.NODE_ENV !== "production" &&
45
+ process.env.BONFIRE_DEPLOYMENT_ENDPOINT !== undefined
46
+ ? createDeploymentProvider({
47
+ endpoint: process.env.BONFIRE_DEPLOYMENT_ENDPOINT,
48
+ })
49
+ : undefined;
50
+
41
51
  export const bonfire = createBonfireNext({
42
52
  config,
43
53
  repositoryRoot: process.cwd(),
44
54
  primaryBranch: process.env.BF_PROTOTYPE_BASE_BRANCH,
55
+ deploymentProvider,
45
56
  sessionSecret: process.env.BF_SESSION_SECRET,
46
57
  disableAutoBranchSwitch: process.env.BF_DISABLE_AUTO_BRANCH_SWITCH,
47
58
  });
48
59
  ```
49
60
 
61
+ ### Theme registry configuration
62
+
63
+ Theme configuration is optional. When present, the registry is validated by
64
+ `@ebay-dt/bonfire-core` and is included in prototype route models:
65
+
66
+ ```ts
67
+ const config = {
68
+ appId: "my-app",
69
+ name: "My App",
70
+ themes: {
71
+ definitions: [
72
+ {
73
+ id: "alpha",
74
+ label: "Alpha",
75
+ allowedColorSchemes: ["system", "light", "dark"],
76
+ },
77
+ { id: "beta", label: "Beta", allowedColorSchemes: ["dark"] },
78
+ ],
79
+ defaultTheme: "alpha",
80
+ defaultColorScheme: "system",
81
+ },
82
+ } satisfies BonfireConfigInput;
83
+ ```
84
+
85
+ Prototype metadata can provide a validated `theme` policy. If it is omitted,
86
+ Bonfire applies the instance defaults and registered capabilities. The server
87
+ integration passes the normalized policy and registry to the host; it does not
88
+ scan metadata or construct a theme map in the application. The preferred host
89
+ composition passes `prototype.themeRegistry` directly to
90
+ `PrototypeEnvironment` alongside `prototype.theme`.
91
+
92
+ The host owns theme CSS. Use the provider's `data-theme` and
93
+ `data-color-scheme` attributes in an instance stylesheet. Keep a `system`
94
+ selector and a `prefers-color-scheme` media rule when a theme supports System;
95
+ Bonfire retains `system` as the attribute value and exposes the resolved Light
96
+ or Dark value separately through React.
97
+
98
+ The deployment endpoint is complete, has no embedded default, and must remain in
99
+ server-only configuration. When configured, the provider sends only
100
+ `{ applicationId, login }`; it does not send owner or branch values. The
101
+ `applicationId` (normally `config.appId`) must exactly match the application's
102
+ DT deployment-service registration. The service resolves the repository,
103
+ project, deployment target, and credentials from the application ID and login.
104
+ HTTP 201 confirms deployment creation, while `readyState` reports the
105
+ provider's current state; Bonfire preserves the `deploymentId` but does not
106
+ poll it. `deploymentAvailable` exposes configured development capability to the
107
+ lifecycle provider, not authorization.
108
+
109
+ A registration mismatch is intentionally surfaced as a safe deployment failure;
110
+ Bonfire does not send the provider's response details to the browser. Diagnose
111
+ it server-side by comparing the configured application ID with the registered
112
+ value. Any host-facing message should remain generic, such as “Deployment is
113
+ not configured for this application.”
114
+
50
115
  Run `bonfire prepare` before development so the secret exists in
51
116
  `.env.local`. An externally supplied `BF_SESSION_SECRET` takes precedence.
52
117
  The explicit repository root enables request-time discovery under
@@ -67,44 +132,104 @@ this callback together with a `prototypeLifecycle` override.
67
132
  Next.js cannot install filesystem routes for a package, so each application
68
133
  adds these small bindings. Keep authentication logic in the package.
69
134
 
70
- `src/app/layout.tsx`:
135
+ `src/app/layout.tsx` should own the document and long-lived providers, but not
136
+ route-specific application chrome. Apply `htmlProps` to the root `<html>`
137
+ element:
71
138
 
72
139
  ```tsx
73
- import type { Metadata } from "next";
74
- import { AppHeader } from "@ebay-dt/bonfire-react";
75
- import { bonfire } from "@/bonfire";
76
140
  import "@ebay-dt/bonfire-react/styles/defaults.css";
141
+ import { bonfire } from "@/bonfire";
77
142
 
78
143
  export default async function RootLayout({ children }: LayoutProps<"/">) {
79
- const { htmlProps, headerProps } = await bonfire.auth.getAppLayoutModel();
144
+ const { htmlProps } = await bonfire.auth.getAppLayoutModel();
80
145
 
81
146
  return (
82
147
  <html lang="en" {...htmlProps}>
83
- <body>
84
- <AppHeader {...headerProps} />
85
- {children}
86
- </body>
148
+ <body>{children}</body>
87
149
  </html>
88
150
  );
89
151
  }
90
152
  ```
91
153
 
92
- `getAppLayoutModel()` returns opaque document props for the packaged header
93
- layout contract and serializable header props. It bypasses session access in
94
- production. `AppHeader` receives `user: null` and renders nothing when the
95
- header is absent, so the host does not implement environment or identity
96
- branching. For a lifecycle-enabled development header, use
97
- `LifecycleAppHeader` from `@ebay-dt/bonfire-react/lifecycle` inside the provider; it
98
- composes the prototype indicator and save/discard popover without duplicating
99
- that UI in the host.
154
+ `getAppLayoutModel()` returns a paired set of opaque document props and
155
+ serializable header props. Spread `htmlProps` on `<html>` and `headerProps` on
156
+ `<AppHeader>`; do not omit the document props when rendering the header. Both
157
+ values come from the same `getAppLayoutModel()` result. Render `AppHeader` in
158
+ the route layout that owns it. Keep the dashboard header in a system layout and
159
+ the prototype header inside the prototype environment, so the header can
160
+ consume the environment context:
161
+
162
+ ```tsx
163
+ // src/app/(system)/layout.tsx
164
+ const { headerProps } = await bonfire.auth.getAppLayoutModel();
165
+ return (
166
+ <>
167
+ <AppHeader {...headerProps} />
168
+ {children}
169
+ </>
170
+ );
171
+ ```
172
+
173
+ ### Prototype environment composition
174
+
175
+ Use `getCurrentRouteModel()` from a shared prototype route-group layout when the
176
+ application enters prototypes from the dashboard and does not support soft
177
+ navigation between prototypes. The model includes the configured registry when
178
+ themes are enabled, so the host does not scan metadata or rebuild a
179
+ `themesByPath` map:
180
+
181
+ ```tsx
182
+ // src/app/(prototypes)/layout.tsx
183
+ import { notFound } from "next/navigation";
184
+ import { AppHeader, PrototypeEnvironment } from "@ebay-dt/bonfire-react";
185
+ import { openInClaudeCode, openInCursor } from "@/actions/agents";
186
+ import { bonfire } from "@/bonfire";
187
+
188
+ export default async function PrototypeLayout({ children }: LayoutProps<"/">) {
189
+ const [{ headerProps }, prototype] = await Promise.all([
190
+ bonfire.auth.getAppLayoutModel(),
191
+ bonfire.prototypes.getCurrentRouteModel(),
192
+ ]);
193
+ if (prototype === null) notFound();
194
+
195
+ const agentActions = { openInClaudeCode, openInCursor };
196
+ const header = <AppHeader {...headerProps} agentActions={agentActions} />;
197
+ if (prototype.theme === undefined)
198
+ return (
199
+ <>
200
+ {header}
201
+ {children}
202
+ </>
203
+ );
204
+ return (
205
+ <PrototypeEnvironment
206
+ prototypeUrl={prototype.url}
207
+ theme={prototype.theme}
208
+ themeRegistry={prototype.themeRegistry}
209
+ agentActions={agentActions}
210
+ >
211
+ {header}
212
+ {children}
213
+ </PrototypeEnvironment>
214
+ );
215
+ }
216
+ ```
217
+
218
+ Keep this layout scoped to prototype routes. Dashboard, login, and other
219
+ application-level pages should remain outside it. If the application later
220
+ adds soft navigation between prototypes, move the boundary to the route
221
+ segment that identifies one prototype (for example `[login]/[slug]/layout.tsx`)
222
+ and use `getRouteModel({ login, slug })` there. That is what allows navigation
223
+ within one prototype to preserve state while navigation to another remounts it.
100
224
 
101
225
  ## Prototype lifecycle composition
102
226
 
103
227
  The lifecycle-aware dashboard uses the framework-neutral controller and React
104
- components from `@ebay-dt/bonfire-react/lifecycle`. The Next-specific provider owns
105
- router integration, dirty-state observation, and controller lifetime, so the
106
- host supplies its Server Action references and the current layout user. Add the
107
- thin dirty route binding as well:
228
+ components from `@ebay-dt/bonfire-react/lifecycle`. The Next-specific provider
229
+ supplies router integration, dirty-state observation, and Server Action
230
+ bindings, while `LifecycleProvider` owns the React controller lifecycle. The
231
+ dirty endpoint is a long-lived SSE route and must run on the Node runtime. Bind
232
+ it directly; do not wrap it in another handler:
108
233
 
109
234
  ```ts
110
235
  // src/app/api/prototype-dirty/route.ts
@@ -118,11 +243,14 @@ Then mount the provider and lifecycle-aware header from the root layout:
118
243
 
119
244
  ```tsx
120
245
  import { NextLifecycleProvider } from "@ebay-dt/bonfire-next/client";
121
- import { LifecycleAppHeader } from "@ebay-dt/bonfire-react/lifecycle";
246
+ import { AppHeader } from "@ebay-dt/bonfire-react";
122
247
  import {
123
248
  createPrototype,
249
+ deletePrototype,
124
250
  discardPrototype,
125
251
  duplicatePrototype,
252
+ editPrototype,
253
+ deployPrototype,
126
254
  savePrototype,
127
255
  } from "@/actions/prototypes";
128
256
  import { bonfire } from "@/bonfire";
@@ -132,22 +260,111 @@ const { headerProps } = await bonfire.auth.getAppLayoutModel();
132
260
  <NextLifecycleProvider
133
261
  enabled={process.env.NODE_ENV !== "production"}
134
262
  user={headerProps.user}
263
+ deploymentAvailable={bonfire.prototypes.capabilities.deployment}
135
264
  dirtyEndpoint="/api/prototype-dirty"
136
265
  actions={{
137
266
  create: createPrototype,
138
267
  duplicate: duplicatePrototype,
268
+ edit: editPrototype,
269
+ delete: deletePrototype,
139
270
  save: savePrototype,
140
271
  discard: discardPrototype,
272
+ ...(process.env.NODE_ENV !== "production"
273
+ ? { deploy: deployPrototype }
274
+ : {}),
141
275
  }}
142
276
  >
143
- <LifecycleAppHeader {...headerProps} />
277
+ <AppHeader {...headerProps} />
144
278
  {children}
145
279
  </NextLifecycleProvider>;
146
280
  ```
147
281
 
148
282
  Mount it from the root layout so the controller survives dashboard/prototype
149
- navigation. Production can leave the provider disabled; the lifecycle-aware
150
- dashboard then renders its public read-only view.
283
+ navigation. Render the regular `PrototypeDashboard` from the page and pass the
284
+ resolved user; it consumes lifecycle context directly. Production can leave
285
+ the provider disabled, in which case the dashboard renders its public
286
+ read-only view. The action bindings must include `create`, `duplicate`, `edit`, `delete`,
287
+ `save`, `discard`, and `deploy` when deployment is enabled. Edit/delete/deploy
288
+ are authorized by the server-side lifecycle adapter; UI visibility is not an
289
+ authorization boundary.
290
+ The provider performs one host refresh after a successful edit or delete.
291
+
292
+ Agent launch bindings follow the same thin host-action pattern. Add a
293
+ server-only wrapper module; it must delegate to `bonfire.prototypes.agents` and
294
+ must not reproduce authentication, ownership, process, or filesystem logic:
295
+
296
+ ```ts
297
+ // src/actions/agents.ts
298
+ "use server";
299
+
300
+ import { bonfire } from "@/bonfire";
301
+ import type {
302
+ OpenInAgentInput,
303
+ OpenInClaudeCodeInput,
304
+ } from "@ebay-dt/bonfire-core";
305
+
306
+ export async function openInCursor(input: OpenInAgentInput) {
307
+ return bonfire.prototypes.agents.openInCursor(input);
308
+ }
309
+
310
+ export async function openInClaudeCode(input: OpenInClaudeCodeInput) {
311
+ return bonfire.prototypes.agents.openInClaudeCode(input);
312
+ }
313
+ ```
314
+
315
+ Pass these Server Action references to both packaged surfaces. The dashboard
316
+ page can provide them to owner cards:
317
+
318
+ ```tsx
319
+ <PrototypeDashboard
320
+ {...model}
321
+ agentActions={{ openInClaudeCode, openInCursor }}
322
+ user={user}
323
+ />
324
+ ```
325
+
326
+ The root header accepts the same bindings:
327
+
328
+ ```tsx
329
+ <AppHeader {...headerProps} agentActions={{ openInClaudeCode, openInCursor }} />
330
+ ```
331
+
332
+ The card controls are owner-only icon buttons with tooltips. A successful card
333
+ launch navigates into the selected prototype; preflight and launch failures
334
+ remain on the current page so their dialogs can be shown. The header controls
335
+ are text menu rows and close the account popover when clicked. Both surfaces
336
+ use the validated prototype reference on the server; browser props contain no
337
+ absolute filesystem path or shell command.
338
+
339
+ Cursor requires `cursor` and Claude Code requires `claude` on the `PATH` inherited
340
+ by the Bonfire server process. On macOS, Claude Code also requires
341
+ `osascript`. A GUI-launched Node process may have a different `PATH` from an
342
+ interactive shell, so restart Bonfire after changing a shell profile. Claude
343
+ Code terminal preferences support Terminal.app, iTerm2, and Warp. The first
344
+ launch without a preference presents the packaged terminal-selection dialog;
345
+ the selected value is written server-side and then used for the launch.
346
+
347
+ Preferences are stored at `<prototypeRoot>/<login>/preferences.json`. This is a
348
+ local preference file, not prototype source, and hosts must ignore it in Git.
349
+ For the conventional integration prototype root, use:
350
+
351
+ ```gitignore
352
+ /src/app/(prototypes)/*/preferences.json
353
+ ```
354
+
355
+ No Claude Code skill, clipboard fallback, copy/paste setup command, or
356
+ unauthenticated preferences route is required. Production remains public and
357
+ read-only: it does not construct the local agent service, launch a process, or
358
+ read or write preferences.
359
+
360
+ ### Migration from the Sandbox reference
361
+
362
+ This flow adapts the Sandbox reference's direct Cursor/Claude Code launching,
363
+ owner checks, terminal selection, and actionable failure UI. Bonfire keeps those
364
+ responsibilities in Core, Node, Next adapters, and packaged React controls; it
365
+ does not copy the reference application's absolute paths, local Next actions,
366
+ client setup hook, skills, clipboard behavior, or unauthenticated preferences
367
+ API.
151
368
 
152
369
  `src/app/login/page.tsx`:
153
370
 
@@ -238,8 +455,11 @@ type HomeProps = {
238
455
  };
239
456
 
240
457
  export default async function Home({ searchParams }: HomeProps) {
241
- const model = await bonfire.prototypes.getDashboardModel(searchParams);
242
- return <PrototypeDashboard {...model} />;
458
+ const [model, user] = await Promise.all([
459
+ bonfire.prototypes.getDashboardModel(searchParams),
460
+ bonfire.auth.getCurrentUser(),
461
+ ]);
462
+ return <PrototypeDashboard {...model} user={user} />;
243
463
  }
244
464
  ```
245
465
 
@@ -260,9 +480,8 @@ and discard accept only a validated target reference and never push changes:
260
480
 
261
481
  import type {
262
482
  CreatePrototypeInput,
263
- DiscardPrototypeInput,
264
483
  DuplicatePrototypeInput,
265
- SavePrototypeInput,
484
+ PrototypeCommandInput,
266
485
  } from "@ebay-dt/bonfire-core";
267
486
  import { bonfire } from "@/bonfire";
268
487
 
@@ -274,13 +493,17 @@ export async function duplicatePrototype(input: DuplicatePrototypeInput) {
274
493
  return bonfire.prototypes.actions.duplicate(input);
275
494
  }
276
495
 
277
- export async function savePrototype(input: SavePrototypeInput) {
496
+ export async function savePrototype(input: PrototypeCommandInput) {
278
497
  return bonfire.prototypes.actions.save(input);
279
498
  }
280
499
 
281
- export async function discardPrototype(input: DiscardPrototypeInput) {
500
+ export async function discardPrototype(input: PrototypeCommandInput) {
282
501
  return bonfire.prototypes.actions.discard(input);
283
502
  }
503
+
504
+ export async function deployPrototype(input: PrototypeCommandInput) {
505
+ return bonfire.prototypes.actions.deploy(input);
506
+ }
284
507
  ```
285
508
 
286
509
  Keep these wrappers thin: form validation, session lookup, lifecycle errors,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,0BAA0B,GAChC,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,0BAA0B,GAChC,MAAM,yBAAyB,CAAC","sourcesContent":["export {\n NextLifecycleProvider,\n type NextLifecycleProviderProps,\n} from \"./lifecycle-provider.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC","sourcesContent":["export {\n NextLifecycleProvider,\n type NextLifecycleProviderProps,\n} from \"./lifecycle-provider.js\";\n"]}
@@ -7,6 +7,7 @@ export type NextLifecycleProviderProps = {
7
7
  enabled?: boolean;
8
8
  user?: BonfireIdentity | null;
9
9
  dirtyEndpoint?: string;
10
+ deploymentAvailable?: boolean;
10
11
  };
11
- export declare function NextLifecycleProvider({ actions, children, enabled, user, dirtyEndpoint, }: NextLifecycleProviderProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | null | undefined;
12
+ export declare function NextLifecycleProvider({ actions, children, enabled, user, dirtyEndpoint, deploymentAvailable, }: NextLifecycleProviderProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | null | undefined;
12
13
  //# sourceMappingURL=lifecycle-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle-provider.d.ts","sourceRoot":"","sources":["../../src/client/lifecycle-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,uBAAuB,EAG7B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,uBAAuB,CAAC;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,QAAQ,EACR,OAAc,EACd,IAAW,EACX,aAAa,GACd,EAAE,0BAA0B,+TAW5B"}
1
+ {"version":3,"file":"lifecycle-provider.d.ts","sourceRoot":"","sources":["../../src/client/lifecycle-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,uBAAuB,EAG7B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,uBAAuB,CAAC;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,QAAQ,EACR,OAAc,EACd,IAAW,EACX,aAAa,EACb,mBAAmB,GACpB,EAAE,0BAA0B,+TAY5B","sourcesContent":["\"use client\";\n\nimport {\n createDirtyObservationAdapter,\n createLifecycleController,\n LifecycleProvider,\n type LifecycleActionBindings,\n type LifecycleNavigationAdapter,\n type LifecycleRouteAdapter,\n} from \"@ebay-dt/bonfire-react/lifecycle\";\nimport type { BonfireIdentity } from \"@ebay-dt/bonfire-core\";\nimport { usePathname, useRouter } from \"next/navigation.js\";\nimport { useEffect, useState, type ReactNode } from \"react\";\n\nexport type NextLifecycleProviderProps = {\n actions: LifecycleActionBindings;\n children: ReactNode;\n enabled?: boolean;\n user?: BonfireIdentity | null;\n dirtyEndpoint?: string;\n deploymentAvailable?: boolean;\n};\n\nexport function NextLifecycleProvider({\n actions,\n children,\n enabled = true,\n user = null,\n dirtyEndpoint,\n deploymentAvailable,\n}: NextLifecycleProviderProps) {\n if (!enabled) return children;\n return (\n <EnabledNextLifecycleProvider\n actions={actions}\n dirtyEndpoint={dirtyEndpoint}\n deploymentAvailable={deploymentAvailable}\n user={user}\n >\n {children}\n </EnabledNextLifecycleProvider>\n );\n}\n\nfunction EnabledNextLifecycleProvider({\n actions,\n children,\n user,\n dirtyEndpoint,\n deploymentAvailable,\n}: Pick<\n NextLifecycleProviderProps,\n \"actions\" | \"children\" | \"user\" | \"dirtyEndpoint\" | \"deploymentAvailable\"\n>) {\n const pathname = usePathname() ?? \"/\";\n const router = useRouter();\n const [route] = useState(() => {\n let currentPathname = pathname;\n const listeners = new Set<() => void>();\n const adapter: LifecycleRouteAdapter = {\n getPathname: () => currentPathname,\n subscribe: (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n return {\n adapter,\n setPathname(nextPathname: string) {\n if (nextPathname === currentPathname) return;\n currentPathname = nextPathname;\n for (const listener of listeners) listener();\n },\n };\n });\n const [navigation] = useState<LifecycleNavigationAdapter>(() => ({\n pathname,\n push: (href) => router.push(href),\n replace: (href) => router.replace(href),\n back: () => router.back(),\n refresh: () => router.refresh(),\n }));\n const [dirtyObservation] = useState(() =>\n createDirtyObservationAdapter({ endpoint: dirtyEndpoint }),\n );\n const [controller] = useState(() =>\n createLifecycleController({\n actions,\n navigation,\n route: route.adapter,\n user,\n dirtyObservation,\n deploymentAvailable,\n }),\n );\n\n useEffect(() => {\n route.setPathname(pathname);\n }, [pathname, route]);\n\n return (\n <LifecycleProvider controller={controller}>{children}</LifecycleProvider>\n );\n}\n"]}
@@ -3,12 +3,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { createDirtyObservationAdapter, createLifecycleController, LifecycleProvider, } from "@ebay-dt/bonfire-react/lifecycle";
4
4
  import { usePathname, useRouter } from "next/navigation.js";
5
5
  import { useEffect, useState } from "react";
6
- export function NextLifecycleProvider({ actions, children, enabled = true, user = null, dirtyEndpoint, }) {
6
+ export function NextLifecycleProvider({ actions, children, enabled = true, user = null, dirtyEndpoint, deploymentAvailable, }) {
7
7
  if (!enabled)
8
8
  return children;
9
- return (_jsx(EnabledNextLifecycleProvider, { actions: actions, dirtyEndpoint: dirtyEndpoint, user: user, children: children }));
9
+ return (_jsx(EnabledNextLifecycleProvider, { actions: actions, dirtyEndpoint: dirtyEndpoint, deploymentAvailable: deploymentAvailable, user: user, children: children }));
10
10
  }
11
- function EnabledNextLifecycleProvider({ actions, children, user, dirtyEndpoint, }) {
11
+ function EnabledNextLifecycleProvider({ actions, children, user, dirtyEndpoint, deploymentAvailable, }) {
12
12
  const pathname = usePathname() ?? "/";
13
13
  const router = useRouter();
14
14
  const [route] = useState(() => {
@@ -37,6 +37,7 @@ function EnabledNextLifecycleProvider({ actions, children, user, dirtyEndpoint,
37
37
  push: (href) => router.push(href),
38
38
  replace: (href) => router.replace(href),
39
39
  back: () => router.back(),
40
+ refresh: () => router.refresh(),
40
41
  }));
41
42
  const [dirtyObservation] = useState(() => createDirtyObservationAdapter({ endpoint: dirtyEndpoint }));
42
43
  const [controller] = useState(() => createLifecycleController({
@@ -45,14 +46,11 @@ function EnabledNextLifecycleProvider({ actions, children, user, dirtyEndpoint,
45
46
  route: route.adapter,
46
47
  user,
47
48
  dirtyObservation,
49
+ deploymentAvailable,
48
50
  }));
49
51
  useEffect(() => {
50
52
  route.setPathname(pathname);
51
53
  }, [pathname, route]);
52
- useEffect(() => {
53
- controller.start();
54
- return () => controller.stop();
55
- }, [controller]);
56
54
  return (_jsx(LifecycleProvider, { controller: controller, children: children }));
57
55
  }
58
56
  //# sourceMappingURL=lifecycle-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle-provider.js","sourceRoot":"","sources":["../../src/client/lifecycle-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,EACzB,iBAAiB,GAIlB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAU5D,MAAM,UAAU,qBAAqB,CAAC,EACpC,OAAO,EACP,QAAQ,EACR,OAAO,GAAG,IAAI,EACd,IAAI,GAAG,IAAI,EACX,aAAa,GACc;IAC3B,IAAI,CAAC,OAAO;QAAE,OAAO,QAAQ,CAAC;IAC9B,OAAO,CACL,KAAC,4BAA4B,IAC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AAC;QACjC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;QACvC,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE;QACzB,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE;KAChC,CAAC,CAAC,CAAC;IACJ,MAAM,CAAC,gBAAgB,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CACvC,6BAA6B,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,CAC3D,CAAC;IACF,MAAM,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CACjC,yBAAyB,CAAC;QACxB,OAAO;QACP,UAAU;QACV,KAAK,EAAE,KAAK,CAAC,OAAO;QACpB,IAAI;QACJ,gBAAgB;QAChB,mBAAmB;KACpB,CAAC,CACH,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;IAEtB,OAAO,CACL,KAAC,iBAAiB,IAAC,UAAU,EAAE,UAAU,YAAG,QAAQ,GAAqB,CAC1E,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport {\n createDirtyObservationAdapter,\n createLifecycleController,\n LifecycleProvider,\n type LifecycleActionBindings,\n type LifecycleNavigationAdapter,\n type LifecycleRouteAdapter,\n} from \"@ebay-dt/bonfire-react/lifecycle\";\nimport type { BonfireIdentity } from \"@ebay-dt/bonfire-core\";\nimport { usePathname, useRouter } from \"next/navigation.js\";\nimport { useEffect, useState, type ReactNode } from \"react\";\n\nexport type NextLifecycleProviderProps = {\n actions: LifecycleActionBindings;\n children: ReactNode;\n enabled?: boolean;\n user?: BonfireIdentity | null;\n dirtyEndpoint?: string;\n deploymentAvailable?: boolean;\n};\n\nexport function NextLifecycleProvider({\n actions,\n children,\n enabled = true,\n user = null,\n dirtyEndpoint,\n deploymentAvailable,\n}: NextLifecycleProviderProps) {\n if (!enabled) return children;\n return (\n <EnabledNextLifecycleProvider\n actions={actions}\n dirtyEndpoint={dirtyEndpoint}\n deploymentAvailable={deploymentAvailable}\n user={user}\n >\n {children}\n </EnabledNextLifecycleProvider>\n );\n}\n\nfunction EnabledNextLifecycleProvider({\n actions,\n children,\n user,\n dirtyEndpoint,\n deploymentAvailable,\n}: Pick<\n NextLifecycleProviderProps,\n \"actions\" | \"children\" | \"user\" | \"dirtyEndpoint\" | \"deploymentAvailable\"\n>) {\n const pathname = usePathname() ?? \"/\";\n const router = useRouter();\n const [route] = useState(() => {\n let currentPathname = pathname;\n const listeners = new Set<() => void>();\n const adapter: LifecycleRouteAdapter = {\n getPathname: () => currentPathname,\n subscribe: (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n return {\n adapter,\n setPathname(nextPathname: string) {\n if (nextPathname === currentPathname) return;\n currentPathname = nextPathname;\n for (const listener of listeners) listener();\n },\n };\n });\n const [navigation] = useState<LifecycleNavigationAdapter>(() => ({\n pathname,\n push: (href) => router.push(href),\n replace: (href) => router.replace(href),\n back: () => router.back(),\n refresh: () => router.refresh(),\n }));\n const [dirtyObservation] = useState(() =>\n createDirtyObservationAdapter({ endpoint: dirtyEndpoint }),\n );\n const [controller] = useState(() =>\n createLifecycleController({\n actions,\n navigation,\n route: route.adapter,\n user,\n dirtyObservation,\n deploymentAvailable,\n }),\n );\n\n useEffect(() => {\n route.setPathname(pathname);\n }, [pathname, route]);\n\n return (\n <LifecycleProvider controller={controller}>{children}</LifecycleProvider>\n );\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { type AgentActionResult, type BonfireIdentity, type OpenInAgentInput, type OpenInClaudeCodeInput } from "@ebay-dt/bonfire-core";
2
+ import type { PrototypeAgentServiceLike } from "@ebay-dt/bonfire-node";
3
+ export type PrototypeAgentActions = {
4
+ openInCursor(input: OpenInAgentInput): Promise<AgentActionResult>;
5
+ openInClaudeCode(input: OpenInClaudeCodeInput): Promise<AgentActionResult>;
6
+ };
7
+ export type PrototypeAgentActionsOptions = {
8
+ production: boolean;
9
+ getCurrentUser: () => Promise<BonfireIdentity | null>;
10
+ agents: PrototypeAgentServiceLike | null;
11
+ };
12
+ export declare function createPrototypeAgentActions(options: PrototypeAgentActionsOptions): PrototypeAgentActions;
13
+ //# sourceMappingURL=agent-actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-actions.d.ts","sourceRoot":"","sources":["../../src/server/agent-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAEvE,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClE,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC5E,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,MAAM,EAAE,yBAAyB,GAAG,IAAI,CAAC;CAC1C,CAAC;AAkCF,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,4BAA4B,GACpC,qBAAqB,CA8CvB","sourcesContent":["import {\n AgentInputError,\n parseOpenInAgentInput,\n parseOpenInClaudeCodeInput,\n type AgentActionResult,\n type BonfireIdentity,\n type OpenInAgentInput,\n type OpenInClaudeCodeInput,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeAgentServiceLike } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeAgentActions = {\n openInCursor(input: OpenInAgentInput): Promise<AgentActionResult>;\n openInClaudeCode(input: OpenInClaudeCodeInput): Promise<AgentActionResult>;\n};\n\nexport type PrototypeAgentActionsOptions = {\n production: boolean;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n agents: PrototypeAgentServiceLike | null;\n};\n\nfunction forbidden() {\n return {\n ok: false,\n error: { code: \"forbidden\" },\n } satisfies AgentActionResult;\n}\n\nfunction unauthenticated() {\n return {\n ok: false,\n error: { code: \"unauthenticated\" },\n } satisfies AgentActionResult;\n}\n\nfunction invalidInput() {\n return {\n ok: false,\n error: { code: \"invalid-input\" },\n } satisfies AgentActionResult;\n}\n\nfunction unexpectedFailure() {\n return {\n ok: false,\n error: { code: \"launch-failed\" },\n } satisfies AgentActionResult;\n}\n\nfunction logUnexpectedFailure(operation: \"cursor\" | \"claude-code\") {\n console.error(`Bonfire ${operation} agent action failed unexpectedly.`);\n}\n\nexport function createPrototypeAgentActions(\n options: PrototypeAgentActionsOptions,\n): PrototypeAgentActions {\n async function openInCursor(input: OpenInAgentInput) {\n if (options.production || options.agents === null) return forbidden();\n\n let parsedInput;\n try {\n parsedInput = parseOpenInAgentInput(input);\n } catch (error) {\n if (error instanceof AgentInputError) return invalidInput();\n logUnexpectedFailure(\"cursor\");\n return unexpectedFailure();\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return unauthenticated();\n return await options.agents.openInCursor(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"cursor\");\n return unexpectedFailure();\n }\n }\n\n async function openInClaudeCode(input: OpenInClaudeCodeInput) {\n if (options.production || options.agents === null) return forbidden();\n\n let parsedInput;\n try {\n parsedInput = parseOpenInClaudeCodeInput(input);\n } catch (error) {\n if (error instanceof AgentInputError) return invalidInput();\n logUnexpectedFailure(\"claude-code\");\n return unexpectedFailure();\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return unauthenticated();\n return await options.agents.openInClaudeCode(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"claude-code\");\n return unexpectedFailure();\n }\n }\n\n return { openInCursor, openInClaudeCode };\n}\n"]}
@@ -0,0 +1,80 @@
1
+ import { AgentInputError, parseOpenInAgentInput, parseOpenInClaudeCodeInput, } from "@ebay-dt/bonfire-core";
2
+ function forbidden() {
3
+ return {
4
+ ok: false,
5
+ error: { code: "forbidden" },
6
+ };
7
+ }
8
+ function unauthenticated() {
9
+ return {
10
+ ok: false,
11
+ error: { code: "unauthenticated" },
12
+ };
13
+ }
14
+ function invalidInput() {
15
+ return {
16
+ ok: false,
17
+ error: { code: "invalid-input" },
18
+ };
19
+ }
20
+ function unexpectedFailure() {
21
+ return {
22
+ ok: false,
23
+ error: { code: "launch-failed" },
24
+ };
25
+ }
26
+ function logUnexpectedFailure(operation) {
27
+ console.error(`Bonfire ${operation} agent action failed unexpectedly.`);
28
+ }
29
+ export function createPrototypeAgentActions(options) {
30
+ async function openInCursor(input) {
31
+ if (options.production || options.agents === null)
32
+ return forbidden();
33
+ let parsedInput;
34
+ try {
35
+ parsedInput = parseOpenInAgentInput(input);
36
+ }
37
+ catch (error) {
38
+ if (error instanceof AgentInputError)
39
+ return invalidInput();
40
+ logUnexpectedFailure("cursor");
41
+ return unexpectedFailure();
42
+ }
43
+ try {
44
+ const identity = await options.getCurrentUser();
45
+ if (identity === null)
46
+ return unauthenticated();
47
+ return await options.agents.openInCursor(identity, parsedInput);
48
+ }
49
+ catch {
50
+ logUnexpectedFailure("cursor");
51
+ return unexpectedFailure();
52
+ }
53
+ }
54
+ async function openInClaudeCode(input) {
55
+ if (options.production || options.agents === null)
56
+ return forbidden();
57
+ let parsedInput;
58
+ try {
59
+ parsedInput = parseOpenInClaudeCodeInput(input);
60
+ }
61
+ catch (error) {
62
+ if (error instanceof AgentInputError)
63
+ return invalidInput();
64
+ logUnexpectedFailure("claude-code");
65
+ return unexpectedFailure();
66
+ }
67
+ try {
68
+ const identity = await options.getCurrentUser();
69
+ if (identity === null)
70
+ return unauthenticated();
71
+ return await options.agents.openInClaudeCode(identity, parsedInput);
72
+ }
73
+ catch {
74
+ logUnexpectedFailure("claude-code");
75
+ return unexpectedFailure();
76
+ }
77
+ }
78
+ return { openInCursor, openInClaudeCode };
79
+ }
80
+ //# sourceMappingURL=agent-actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-actions.js","sourceRoot":"","sources":["../../src/server/agent-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,0BAA0B,GAK3B,MAAM,uBAAuB,CAAC;AAc/B,SAAS,SAAS;IAChB,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;KACD,CAAC;AAChC,CAAC;AAED,SAAS,eAAe;IACtB,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE;KACP,CAAC;AAChC,CAAC;AAED,SAAS,YAAY;IACnB,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE;KACL,CAAC;AAChC,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE;KACL,CAAC;AAChC,CAAC;AAED,SAAS,oBAAoB,CAAC,SAAmC;IAC/D,OAAO,CAAC,KAAK,CAAC,WAAW,SAAS,oCAAoC,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,OAAqC;IAErC,KAAK,UAAU,YAAY,CAAC,KAAuB;QACjD,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI;YAAE,OAAO,SAAS,EAAE,CAAC;QAEtE,IAAI,WAAW,CAAC;QAChB,IAAI,CAAC;YACH,WAAW,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAC7C,CA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CAAC,CAAC;YACpC,OAAO,iBAAiB,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAC5C,CAAC","sourcesContent":["import {\n AgentInputError,\n parseOpenInAgentInput,\n parseOpenInClaudeCodeInput,\n type AgentActionResult,\n type BonfireIdentity,\n type OpenInAgentInput,\n type OpenInClaudeCodeInput,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeAgentServiceLike } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeAgentActions = {\n openInCursor(input: OpenInAgentInput): Promise<AgentActionResult>;\n openInClaudeCode(input: OpenInClaudeCodeInput): Promise<AgentActionResult>;\n};\n\nexport type PrototypeAgentActionsOptions = {\n production: boolean;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n agents: PrototypeAgentServiceLike | null;\n};\n\nfunction forbidden() {\n return {\n ok: false,\n error: { code: \"forbidden\" },\n } satisfies AgentActionResult;\n}\n\nfunction unauthenticated() {\n return {\n ok: false,\n error: { code: \"unauthenticated\" },\n } satisfies AgentActionResult;\n}\n\nfunction invalidInput() {\n return {\n ok: false,\n error: { code: \"invalid-input\" },\n } satisfies AgentActionResult;\n}\n\nfunction unexpectedFailure() {\n return {\n ok: false,\n error: { code: \"launch-failed\" },\n } satisfies AgentActionResult;\n}\n\nfunction logUnexpectedFailure(operation: \"cursor\" | \"claude-code\") {\n console.error(`Bonfire ${operation} agent action failed unexpectedly.`);\n}\n\nexport function createPrototypeAgentActions(\n options: PrototypeAgentActionsOptions,\n): PrototypeAgentActions {\n async function openInCursor(input: OpenInAgentInput) {\n if (options.production || options.agents === null) return forbidden();\n\n let parsedInput;\n try {\n parsedInput = parseOpenInAgentInput(input);\n } catch (error) {\n if (error instanceof AgentInputError) return invalidInput();\n logUnexpectedFailure(\"cursor\");\n return unexpectedFailure();\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return unauthenticated();\n return await options.agents.openInCursor(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"cursor\");\n return unexpectedFailure();\n }\n }\n\n async function openInClaudeCode(input: OpenInClaudeCodeInput) {\n if (options.production || options.agents === null) return forbidden();\n\n let parsedInput;\n try {\n parsedInput = parseOpenInClaudeCodeInput(input);\n } catch (error) {\n if (error instanceof AgentInputError) return invalidInput();\n logUnexpectedFailure(\"claude-code\");\n return unexpectedFailure();\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return unauthenticated();\n return await options.agents.openInClaudeCode(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"claude-code\");\n return unexpectedFailure();\n }\n }\n\n return { openInCursor, openInClaudeCode };\n}\n"]}
@@ -5,5 +5,6 @@ export type AuthProxyOptions = {
5
5
  sessionSecret: string | undefined;
6
6
  production: boolean;
7
7
  };
8
+ export declare const BONFIRE_PATHNAME_HEADER = "x-bonfire-pathname";
8
9
  export declare function createAuthProxy(options: AuthProxyOptions): (request: NextRequest) => Promise<NextResponse<unknown>>;
9
10
  //# sourceMappingURL=auth-boundary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth-boundary.d.ts","sourceRoot":"","sources":["../../src/server/auth-boundary.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAUF,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,aAGd,WAAW,oCAarD"}
1
+ {"version":3,"file":"auth-boundary.d.ts","sourceRoot":"","sources":["../../src/server/auth-boundary.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAUF,eAAO,MAAM,uBAAuB,uBAAuB,CAAC;AAE5D,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,aAGd,WAAW,oCAqBrD","sourcesContent":["import { getSessionCookieName } from \"@ebay-dt/bonfire-core\";\nimport { NextResponse } from \"next/server.js\";\nimport type { NextRequest } from \"next/server.js\";\nimport { verifySession } from \"./session.js\";\n\nexport type AuthProxyOptions = {\n appId: string;\n sessionSecret: string | undefined;\n production: boolean;\n};\n\nfunction isAuthPath(pathname: string): boolean {\n return (\n pathname === \"/login\" ||\n pathname === \"/auth\" ||\n pathname.startsWith(\"/auth/\")\n );\n}\n\nexport const BONFIRE_PATHNAME_HEADER = \"x-bonfire-pathname\";\n\nexport function createAuthProxy(options: AuthProxyOptions) {\n const cookieName = getSessionCookieName(options.appId);\n\n return async function authProxy(request: NextRequest) {\n // Forwarded so the shared prototype route-group layout can resolve the\n // active prototype's theme policy server-side without duplicating catalog\n // lookup in the host.\n const forwardedHeaders = new Headers(request.headers);\n forwardedHeaders.set(BONFIRE_PATHNAME_HEADER, request.nextUrl.pathname);\n const next = () =>\n NextResponse.next({ request: { headers: forwardedHeaders } });\n\n if (options.production) return next();\n if (isAuthPath(request.nextUrl.pathname)) return next();\n\n const token = request.cookies.get(cookieName)?.value;\n const identity =\n token && options.sessionSecret\n ? await verifySession(token, options.sessionSecret)\n : null;\n if (identity) return next();\n\n return NextResponse.redirect(new URL(\"/login\", request.url));\n };\n}\n"]}
@@ -6,19 +6,26 @@ function isAuthPath(pathname) {
6
6
  pathname === "/auth" ||
7
7
  pathname.startsWith("/auth/"));
8
8
  }
9
+ export const BONFIRE_PATHNAME_HEADER = "x-bonfire-pathname";
9
10
  export function createAuthProxy(options) {
10
11
  const cookieName = getSessionCookieName(options.appId);
11
12
  return async function authProxy(request) {
13
+ // Forwarded so the shared prototype route-group layout can resolve the
14
+ // active prototype's theme policy server-side without duplicating catalog
15
+ // lookup in the host.
16
+ const forwardedHeaders = new Headers(request.headers);
17
+ forwardedHeaders.set(BONFIRE_PATHNAME_HEADER, request.nextUrl.pathname);
18
+ const next = () => NextResponse.next({ request: { headers: forwardedHeaders } });
12
19
  if (options.production)
13
- return NextResponse.next();
20
+ return next();
14
21
  if (isAuthPath(request.nextUrl.pathname))
15
- return NextResponse.next();
22
+ return next();
16
23
  const token = request.cookies.get(cookieName)?.value;
17
24
  const identity = token && options.sessionSecret
18
25
  ? await verifySession(token, options.sessionSecret)
19
26
  : null;
20
27
  if (identity)
21
- return NextResponse.next();
28
+ return next();
22
29
  return NextResponse.redirect(new URL("/login", request.url));
23
30
  };
24
31
  }