@aiveth/react 0.4.1 → 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 +8 -0
- package/README.md +11 -0
- package/dist/client.d.ts +21 -1
- package/dist/client.js +13 -1
- package/dist/react.d.ts +3 -0
- package/dist/react.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
7
|
+
## 0.5.0 — 2026-11-26
|
|
8
|
+
|
|
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`).
|
|
10
|
+
|
|
3
11
|
## 0.4.1 — 2026-11-25
|
|
4
12
|
|
|
5
13
|
- Same version as `@aiveth/nextjs` 0.4.1. No change: `AivethButton` reads Aiveth's address, which
|
package/README.md
CHANGED
|
@@ -23,6 +23,17 @@ 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
|
+
|
|
31
|
+
## A token for your own API
|
|
32
|
+
|
|
33
|
+
Add `audience="https://api.your-app.com"` (registered under Developers → Your APIs) to
|
|
34
|
+
`AivethProvider`. The access token is then a signed token your API checks with
|
|
35
|
+
`verifyAccessToken` from `@aiveth/node`, with no call to Aiveth.
|
|
36
|
+
|
|
26
37
|
## Sign in in your organization's own look
|
|
27
38
|
|
|
28
39
|
`<AivethButton>` draws "Sign in" with what you set in Aiveth → Branding — colours (light and
|
package/dist/client.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export interface AivethConfig {
|
|
|
5
5
|
/** Exactly one of the app's registered return addresses. */
|
|
6
6
|
redirectUri: string;
|
|
7
7
|
scope?: string;
|
|
8
|
+
/** Your own API's address, as registered under Developers → Your APIs. Set it and the access
|
|
9
|
+
* token is a signed token for that API, which it checks with `verifyAccessToken`
|
|
10
|
+
* (`@aiveth/node`) — no call to Aiveth. */
|
|
11
|
+
audience?: string;
|
|
8
12
|
/** Where Aiveth sends the person after signing out (registered under the app's sign-out). */
|
|
9
13
|
postLogoutRedirectUri?: string;
|
|
10
14
|
/** For tests. */
|
|
@@ -35,6 +39,18 @@ export interface User {
|
|
|
35
39
|
picture?: string;
|
|
36
40
|
/** The organization's feature flags that are on for this person — present once it has one. */
|
|
37
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
|
+
}[];
|
|
38
54
|
[claim: string]: unknown;
|
|
39
55
|
}
|
|
40
56
|
/** What `handleRedirect` did: `handled` — this load was a return from Aiveth (clean the address
|
|
@@ -72,13 +88,17 @@ export declare class AivethClient {
|
|
|
72
88
|
private changed;
|
|
73
89
|
private discover;
|
|
74
90
|
/** To Aiveth's sign-in page; back at `redirectUri`, `handleRedirect` finishes. */
|
|
75
|
-
signIn({ returnTo }?: {
|
|
91
|
+
signIn({ returnTo, workspace }?: {
|
|
76
92
|
returnTo?: string;
|
|
93
|
+
workspace?: string;
|
|
77
94
|
}): Promise<void>;
|
|
78
95
|
/** On the return address: swap the code for tokens. Answers where the app wanted to go
|
|
79
96
|
* (`returnTo`), or null when this page load isn't a return from Aiveth. */
|
|
80
97
|
handleRedirect(url: string): Promise<Returned>;
|
|
81
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>;
|
|
82
102
|
/** A live access token for calling your API — renewed with the refresh token when it is near
|
|
83
103
|
* its end; null when signed out (or the refresh token has ended: sign in again). */
|
|
84
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 };
|
|
@@ -109,6 +109,10 @@ export class AivethClient {
|
|
|
109
109
|
scope: this.config.scope ?? DEFAULT_SCOPE, state: pending.state, nonce: pending.nonce,
|
|
110
110
|
code_challenge: await challengeOf(verifier), code_challenge_method: 'S256',
|
|
111
111
|
});
|
|
112
|
+
if (this.config.audience)
|
|
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)
|
|
112
116
|
this.navigate(`${found.authorization_endpoint}?${query}`);
|
|
113
117
|
}
|
|
114
118
|
/** On the return address: swap the code for tokens. Answers where the app wanted to go
|
|
@@ -169,6 +173,14 @@ export class AivethClient {
|
|
|
169
173
|
this.changed();
|
|
170
174
|
return this.tokens;
|
|
171
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
|
+
}
|
|
172
184
|
/** A live access token for calling your API — renewed with the refresh token when it is near
|
|
173
185
|
* its end; null when signed out (or the refresh token has ended: sign in again). */
|
|
174
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