@aiveth/react 0.5.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0 — 2026-11-26
4
+
5
+ - `signIn({ workspace })` signs the person in to a workspace; `switchWorkspace(ref)` (client and `useAiveth()`) switches it with the refresh token. `user` carries `workspace_id`, `workspace_slug`, `workspace_role`, `workspace_permissions`, and `workspaces` with the scope of that name.
6
+
3
7
  ## 0.5.0 — 2026-11-26
4
8
 
5
9
  - `audience` (on `AivethProvider` / `AivethClient`): your own API's address. The access token is then a signed token for that API, which it checks with `verifyAccessToken` (`@aiveth/node`).
package/README.md CHANGED
@@ -23,6 +23,11 @@ const token = await getAccessToken(); // Authorization: Bearer … for your API
23
23
  - Refresh tokens (`offline_access`, asked by default) are swapped at every use.
24
24
  - One app belongs to one organization in Aiveth, so there is no organization switcher.
25
25
 
26
+ ## Workspaces
27
+
28
+ `signIn({ workspace: 'acme' })` signs in to a workspace; `switchWorkspace('acme-two')` switches it
29
+ (needs `offline_access`). `user.workspace_id`, `workspace_role` and `workspace_permissions` follow.
30
+
26
31
  ## A token for your own API
27
32
 
28
33
  Add `audience="https://api.your-app.com"` (registered under Developers → Your APIs) to
package/dist/client.d.ts CHANGED
@@ -39,6 +39,18 @@ export interface User {
39
39
  picture?: string;
40
40
  /** The organization's feature flags that are on for this person — present once it has one. */
41
41
  feature_flags?: string[];
42
+ /** The active workspace (`signIn({ workspace })`, or `switchWorkspace`). */
43
+ workspace_id?: string;
44
+ workspace_slug?: string;
45
+ workspace_role?: string;
46
+ workspace_permissions?: string[];
47
+ /** With the `workspaces` scope: every workspace the person is in, for your switcher. */
48
+ workspaces?: {
49
+ id: string;
50
+ slug: string;
51
+ name: string;
52
+ role: string;
53
+ }[];
42
54
  [claim: string]: unknown;
43
55
  }
44
56
  /** What `handleRedirect` did: `handled` — this load was a return from Aiveth (clean the address
@@ -76,13 +88,17 @@ export declare class AivethClient {
76
88
  private changed;
77
89
  private discover;
78
90
  /** To Aiveth's sign-in page; back at `redirectUri`, `handleRedirect` finishes. */
79
- signIn({ returnTo }?: {
91
+ signIn({ returnTo, workspace }?: {
80
92
  returnTo?: string;
93
+ workspace?: string;
81
94
  }): Promise<void>;
82
95
  /** On the return address: swap the code for tokens. Answers where the app wanted to go
83
96
  * (`returnTo`), or null when this page load isn't a return from Aiveth. */
84
97
  handleRedirect(url: string): Promise<Returned>;
85
98
  private exchange;
99
+ /** Switch the active workspace (id or slug): the new tokens name it, and `user` changes with
100
+ * them. The person must be a member. Needs the refresh token (`offline_access`). */
101
+ switchWorkspace(workspace: string): Promise<void>;
86
102
  /** A live access token for calling your API — renewed with the refresh token when it is near
87
103
  * its end; null when signed out (or the refresh token has ended: sign in again). */
88
104
  getAccessToken(): Promise<string | null>;
package/dist/client.js CHANGED
@@ -99,7 +99,7 @@ export class AivethClient {
99
99
  return this.discovery;
100
100
  }
101
101
  /** To Aiveth's sign-in page; back at `redirectUri`, `handleRedirect` finishes. */
102
- async signIn({ returnTo } = {}) {
102
+ async signIn({ returnTo, workspace } = {}) {
103
103
  const found = await this.discover();
104
104
  const verifier = random(48);
105
105
  const pending = { state: random(), nonce: random(), verifier, returnTo: returnTo ?? null };
@@ -111,6 +111,8 @@ export class AivethClient {
111
111
  });
112
112
  if (this.config.audience)
113
113
  query.set('resource', this.config.audience); // RFC 8707
114
+ if (workspace)
115
+ query.set('workspace', workspace); // signed in to that workspace (a member's only)
114
116
  this.navigate(`${found.authorization_endpoint}?${query}`);
115
117
  }
116
118
  /** On the return address: swap the code for tokens. Answers where the app wanted to go
@@ -171,6 +173,14 @@ export class AivethClient {
171
173
  this.changed();
172
174
  return this.tokens;
173
175
  }
176
+ /** Switch the active workspace (id or slug): the new tokens name it, and `user` changes with
177
+ * them. The person must be a member. Needs the refresh token (`offline_access`). */
178
+ async switchWorkspace(workspace) {
179
+ const held = this.tokens?.refreshToken;
180
+ if (!held)
181
+ throw new SignInError('Switching a workspace needs offline_access.');
182
+ await this.exchange({ grant_type: 'refresh_token', refresh_token: held, workspace }, null);
183
+ }
174
184
  /** A live access token for calling your API — renewed with the refresh token when it is near
175
185
  * its end; null when signed out (or the refresh token has ended: sign in again). */
176
186
  async getAccessToken() {
package/dist/react.d.ts CHANGED
@@ -15,6 +15,7 @@ export interface UseAiveth {
15
15
  error: Error | null;
16
16
  signIn: (options?: {
17
17
  returnTo?: string;
18
+ workspace?: string;
18
19
  }) => Promise<void>;
19
20
  signOut: () => Promise<void>;
20
21
  /** For your API calls: `Authorization: Bearer …`. Null when signed out. */
@@ -27,6 +28,8 @@ export interface UseAiveth {
27
28
  hasFlag: (key: string) => boolean;
28
29
  /** Aiveth's page that ends acting as someone. */
29
30
  actingUrl: string;
31
+ /** Switch the active workspace (id or slug); `user` changes with the new tokens. */
32
+ switchWorkspace: (workspace: string) => Promise<void>;
30
33
  }
31
34
  export declare function useAiveth(): UseAiveth;
32
35
  export declare function SignedIn({ children }: {
package/dist/react.js CHANGED
@@ -49,6 +49,7 @@ export function useAiveth() {
49
49
  getAccessToken: () => client.getAccessToken(), accountUrl: client.accountUrl(),
50
50
  actor: actorOf(user), actingUrl: client.actingUrl(),
51
51
  hasFlag: (key) => Array.isArray(user?.feature_flags) && user.feature_flags.includes(key),
52
+ switchWorkspace: (workspace) => client.switchWorkspace(workspace),
52
53
  };
53
54
  }
54
55
  export function SignedIn({ children }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiveth/react",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Aiveth by Gooclaim for React: sign in on Aiveth's page (PKCE), tokens in memory, ready-made pieces.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Gooclaim",