@lunnoa/client 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.cts CHANGED
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
3
3
  import { UIMessage, UIMessageChunk } from 'ai';
4
4
 
5
5
  /**
6
- * Pluggable storage for Pattern B JWTs.
6
+ * Pluggable storage for Lunnoa user JWTs.
7
7
  * The SDK never uses httpOnly cookies: Automate auth is bearer JWT based.
8
8
  */
9
9
  interface TokenStore {
@@ -24,20 +24,20 @@ interface LunnoaClientOptions {
24
24
  */
25
25
  baseUrl: string;
26
26
  /**
27
- * Server-side machine credential (`lna_...`). Never usable in browsers —
28
- * the constructor throws if one is supplied while `window` exists.
27
+ * Machine credential (`lna_...`) for the CLI and operator scripts, not for app login.
28
+ * Never usable in browsers: the constructor throws if one is supplied while `window` exists.
29
29
  */
30
30
  apiKey?: string;
31
31
  /**
32
32
  * User JWT obtained from login / SSO. The supported credential for browser
33
33
  * applications. May be a function so refreshed tokens are picked up per request.
34
34
  *
35
- * Prefer {@link tokenStore} for Pattern B so login/refresh can persist tokens
35
+ * Prefer {@link tokenStore} so login/refresh can persist tokens
36
36
  * and optionally auto-refresh on 401.
37
37
  */
38
38
  accessToken?: string | (() => string | Promise<string>);
39
39
  /**
40
- * Optional JWT store for Pattern B. When set, authenticated requests read
40
+ * Optional JWT store for a signed-in Lunnoa user. When set, authenticated requests read
41
41
  * the access token from the store. Login / refresh helpers write back into it.
42
42
  */
43
43
  tokenStore?: TokenStore;
@@ -2796,7 +2796,7 @@ interface CurrentUser {
2796
2796
  }
2797
2797
 
2798
2798
  /**
2799
- * Login, refresh, SSO discovery, and session helpers for Pattern B.
2799
+ * Login, refresh, SSO discovery, and session helpers for Lunnoa users.
2800
2800
  *
2801
2801
  * Password login, token exchange, refresh, and SSO provider listing are
2802
2802
  * **public** endpoints (no Bearer). `me()` requires a user JWT.
@@ -3453,28 +3453,21 @@ declare class WorkflowsResource {
3453
3453
  /**
3454
3454
  * Typed client for the Lunnoa Automate Public API.
3455
3455
  *
3456
- * Server-side (Pattern A — the backend holds the key):
3457
- * ```ts
3458
- * const lunnoa = new LunnoaClient({
3459
- * baseUrl: 'https://lunnoa.acme.example',
3460
- * apiKey: process.env.LUNNOA_API_KEY, // lna_...
3461
- * });
3462
- * ```
3463
- *
3464
- * Browser (Pattern B — the end user is a Lunnoa user):
3456
+ * Apps sign people in as Lunnoa users:
3465
3457
  * ```ts
3466
3458
  * import { createBrowserClient } from '@lunnoa/client';
3467
3459
  * const lunnoa = createBrowserClient({ baseUrl: 'https://lunnoa.acme.example' });
3468
3460
  * await lunnoa.auth.login({ email, password });
3469
3461
  * ```
3470
3462
  *
3471
- * Passing an `lna_` API key in a browser throws immediately: API keys are
3472
- * workspace-wide server credentials and must never ship to browsers.
3463
+ * `apiKey` (`lna_...`) is for the CLI and operator scripts (codegen, discovery,
3464
+ * deploy). It is not an app login. Passing one while `window` exists throws:
3465
+ * a leaked key acts as that service account across its whole workspace.
3473
3466
  */
3474
3467
  declare class LunnoaClient {
3475
3468
  /** The underlying HTTP layer, exposed for advanced/escape-hatch requests. */
3476
3469
  readonly http: HttpClient;
3477
- /** Login, refresh, SSO discovery, and session helpers (Pattern B). */
3470
+ /** Login, refresh, SSO discovery, and session helpers for Lunnoa users. */
3478
3471
  readonly auth: AuthResource;
3479
3472
  readonly agents: AgentsResource;
3480
3473
  readonly tasks: TasksResource;
@@ -3525,7 +3518,7 @@ interface CreateBrowserClientOptions {
3525
3518
 
3526
3519
  type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';
3527
3520
  interface LunnoaAuthContextValue {
3528
- /** Shared Lunnoa client (Pattern B token store). */
3521
+ /** Shared Lunnoa client (user JWT token store). */
3529
3522
  client: LunnoaClient;
3530
3523
  /** Current user from `GET /api/users/me`, or null when signed out. */
3531
3524
  user: CurrentUser | null;
@@ -3567,7 +3560,7 @@ interface LunnoaAuthContextValue {
3567
3560
  getAccessToken: () => Promise<string | null>;
3568
3561
  }
3569
3562
  type LunnoaAuthProviderProps = {
3570
- /** Existing Pattern B client (from `createBrowserClient`). */
3563
+ /** Existing browser client (from `createBrowserClient`). */
3571
3564
  client: LunnoaClient;
3572
3565
  children: ReactNode;
3573
3566
  } | (CreateBrowserClientOptions & {
@@ -3575,7 +3568,7 @@ type LunnoaAuthProviderProps = {
3575
3568
  children: ReactNode;
3576
3569
  });
3577
3570
  /**
3578
- * Provides a Pattern B Lunnoa client and session helpers to React trees.
3571
+ * Provides a Lunnoa user client and session helpers to React trees.
3579
3572
  *
3580
3573
  * ```tsx
3581
3574
  * <LunnoaAuthProvider baseUrl={import.meta.env.VITE_LUNNOA_URL}>
@@ -3584,7 +3577,7 @@ type LunnoaAuthProviderProps = {
3584
3577
  * ```
3585
3578
  */
3586
3579
  declare function LunnoaAuthProvider(props: LunnoaAuthProviderProps): react.FunctionComponentElement<react.ProviderProps<LunnoaAuthContextValue | null>>;
3587
- /** Full auth session API for Pattern B React apps. */
3580
+ /** Full auth session API for React apps whose users sign in to Lunnoa. */
3588
3581
  declare function useLunnoaAuth(): LunnoaAuthContextValue;
3589
3582
  /** The Lunnoa client from the nearest {@link LunnoaAuthProvider}. */
3590
3583
  declare function useLunnoaClient(): LunnoaClient;
package/dist/react.d.ts CHANGED
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
3
3
  import { UIMessage, UIMessageChunk } from 'ai';
4
4
 
5
5
  /**
6
- * Pluggable storage for Pattern B JWTs.
6
+ * Pluggable storage for Lunnoa user JWTs.
7
7
  * The SDK never uses httpOnly cookies: Automate auth is bearer JWT based.
8
8
  */
9
9
  interface TokenStore {
@@ -24,20 +24,20 @@ interface LunnoaClientOptions {
24
24
  */
25
25
  baseUrl: string;
26
26
  /**
27
- * Server-side machine credential (`lna_...`). Never usable in browsers —
28
- * the constructor throws if one is supplied while `window` exists.
27
+ * Machine credential (`lna_...`) for the CLI and operator scripts, not for app login.
28
+ * Never usable in browsers: the constructor throws if one is supplied while `window` exists.
29
29
  */
30
30
  apiKey?: string;
31
31
  /**
32
32
  * User JWT obtained from login / SSO. The supported credential for browser
33
33
  * applications. May be a function so refreshed tokens are picked up per request.
34
34
  *
35
- * Prefer {@link tokenStore} for Pattern B so login/refresh can persist tokens
35
+ * Prefer {@link tokenStore} so login/refresh can persist tokens
36
36
  * and optionally auto-refresh on 401.
37
37
  */
38
38
  accessToken?: string | (() => string | Promise<string>);
39
39
  /**
40
- * Optional JWT store for Pattern B. When set, authenticated requests read
40
+ * Optional JWT store for a signed-in Lunnoa user. When set, authenticated requests read
41
41
  * the access token from the store. Login / refresh helpers write back into it.
42
42
  */
43
43
  tokenStore?: TokenStore;
@@ -2796,7 +2796,7 @@ interface CurrentUser {
2796
2796
  }
2797
2797
 
2798
2798
  /**
2799
- * Login, refresh, SSO discovery, and session helpers for Pattern B.
2799
+ * Login, refresh, SSO discovery, and session helpers for Lunnoa users.
2800
2800
  *
2801
2801
  * Password login, token exchange, refresh, and SSO provider listing are
2802
2802
  * **public** endpoints (no Bearer). `me()` requires a user JWT.
@@ -3453,28 +3453,21 @@ declare class WorkflowsResource {
3453
3453
  /**
3454
3454
  * Typed client for the Lunnoa Automate Public API.
3455
3455
  *
3456
- * Server-side (Pattern A — the backend holds the key):
3457
- * ```ts
3458
- * const lunnoa = new LunnoaClient({
3459
- * baseUrl: 'https://lunnoa.acme.example',
3460
- * apiKey: process.env.LUNNOA_API_KEY, // lna_...
3461
- * });
3462
- * ```
3463
- *
3464
- * Browser (Pattern B — the end user is a Lunnoa user):
3456
+ * Apps sign people in as Lunnoa users:
3465
3457
  * ```ts
3466
3458
  * import { createBrowserClient } from '@lunnoa/client';
3467
3459
  * const lunnoa = createBrowserClient({ baseUrl: 'https://lunnoa.acme.example' });
3468
3460
  * await lunnoa.auth.login({ email, password });
3469
3461
  * ```
3470
3462
  *
3471
- * Passing an `lna_` API key in a browser throws immediately: API keys are
3472
- * workspace-wide server credentials and must never ship to browsers.
3463
+ * `apiKey` (`lna_...`) is for the CLI and operator scripts (codegen, discovery,
3464
+ * deploy). It is not an app login. Passing one while `window` exists throws:
3465
+ * a leaked key acts as that service account across its whole workspace.
3473
3466
  */
3474
3467
  declare class LunnoaClient {
3475
3468
  /** The underlying HTTP layer, exposed for advanced/escape-hatch requests. */
3476
3469
  readonly http: HttpClient;
3477
- /** Login, refresh, SSO discovery, and session helpers (Pattern B). */
3470
+ /** Login, refresh, SSO discovery, and session helpers for Lunnoa users. */
3478
3471
  readonly auth: AuthResource;
3479
3472
  readonly agents: AgentsResource;
3480
3473
  readonly tasks: TasksResource;
@@ -3525,7 +3518,7 @@ interface CreateBrowserClientOptions {
3525
3518
 
3526
3519
  type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';
3527
3520
  interface LunnoaAuthContextValue {
3528
- /** Shared Lunnoa client (Pattern B token store). */
3521
+ /** Shared Lunnoa client (user JWT token store). */
3529
3522
  client: LunnoaClient;
3530
3523
  /** Current user from `GET /api/users/me`, or null when signed out. */
3531
3524
  user: CurrentUser | null;
@@ -3567,7 +3560,7 @@ interface LunnoaAuthContextValue {
3567
3560
  getAccessToken: () => Promise<string | null>;
3568
3561
  }
3569
3562
  type LunnoaAuthProviderProps = {
3570
- /** Existing Pattern B client (from `createBrowserClient`). */
3563
+ /** Existing browser client (from `createBrowserClient`). */
3571
3564
  client: LunnoaClient;
3572
3565
  children: ReactNode;
3573
3566
  } | (CreateBrowserClientOptions & {
@@ -3575,7 +3568,7 @@ type LunnoaAuthProviderProps = {
3575
3568
  children: ReactNode;
3576
3569
  });
3577
3570
  /**
3578
- * Provides a Pattern B Lunnoa client and session helpers to React trees.
3571
+ * Provides a Lunnoa user client and session helpers to React trees.
3579
3572
  *
3580
3573
  * ```tsx
3581
3574
  * <LunnoaAuthProvider baseUrl={import.meta.env.VITE_LUNNOA_URL}>
@@ -3584,7 +3577,7 @@ type LunnoaAuthProviderProps = {
3584
3577
  * ```
3585
3578
  */
3586
3579
  declare function LunnoaAuthProvider(props: LunnoaAuthProviderProps): react.FunctionComponentElement<react.ProviderProps<LunnoaAuthContextValue | null>>;
3587
- /** Full auth session API for Pattern B React apps. */
3580
+ /** Full auth session API for React apps whose users sign in to Lunnoa. */
3588
3581
  declare function useLunnoaAuth(): LunnoaAuthContextValue;
3589
3582
  /** The Lunnoa client from the nearest {@link LunnoaAuthProvider}. */
3590
3583
  declare function useLunnoaClient(): LunnoaClient;
package/dist/react.js CHANGED
@@ -56,7 +56,7 @@ function isBrowserEnvironment() {
56
56
  function assertApiKeyAllowedInEnvironment(apiKey) {
57
57
  if (isBrowserEnvironment()) {
58
58
  throw new Error(
59
- "Refusing to use a Lunnoa API key (lna_...) in a browser environment. API keys are server-side credentials: anyone opening dev tools could read the key and act as the service account across its whole workspace. Either call the Lunnoa API from your own backend which holds the key (backend-for-frontend pattern), or authenticate the end user with a Lunnoa user JWT and pass it as `accessToken`."
59
+ "Refusing to use a Lunnoa API key (lna_...) in a browser environment. API keys are for the CLI and operator scripts, not for app login. Anyone opening dev tools could read the key and act as the service account across its whole workspace. Sign the end user in with lunnoa.auth.login and pass their JWT as `accessToken`."
60
60
  );
61
61
  }
62
62
  if (!apiKey.startsWith(API_KEY_PREFIX)) {
@@ -138,7 +138,7 @@ var HttpClient = class {
138
138
  }
139
139
  if (!options.apiKey && !options.accessToken && !options.tokenStore) {
140
140
  throw new Error(
141
- "LunnoaClient requires an apiKey (server-side), an accessToken (user JWT), or a tokenStore (Pattern B)."
141
+ "LunnoaClient requires an accessToken or tokenStore (Lunnoa user JWT), or an apiKey for operator scripts."
142
142
  );
143
143
  }
144
144
  if (options.apiKey) {
@@ -2089,7 +2089,7 @@ var WorkflowsResource = class {
2089
2089
  var LunnoaClient = class {
2090
2090
  /** The underlying HTTP layer, exposed for advanced/escape-hatch requests. */
2091
2091
  http;
2092
- /** Login, refresh, SSO discovery, and session helpers (Pattern B). */
2092
+ /** Login, refresh, SSO discovery, and session helpers for Lunnoa users. */
2093
2093
  auth;
2094
2094
  agents;
2095
2095
  tasks;