@aiveth/react 0.6.0 → 0.8.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/dist/client.d.ts +53 -0
- package/dist/client.js +32 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/react.d.ts +3 -1
- 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.8.0 — 2026-11-26
|
|
4
|
+
|
|
5
|
+
- Same version as `@aiveth/node` 0.8.0. No change in behaviour.
|
|
6
|
+
|
|
7
|
+
## 0.7.0 — 2026-11-26
|
|
8
|
+
|
|
9
|
+
- `client.myWorkspace` — the signed-in workspace from your own pages (Aiveth's My workspace API): `get`, `members`, `setRole`, `remove` (or leave), `invitations`, `invite`, `withdraw`. Set `audience` to `myWorkspaceAudience(issuer)` and sign in with `workspace`.
|
|
10
|
+
|
|
3
11
|
## 0.6.0 — 2026-11-26
|
|
4
12
|
|
|
5
13
|
- `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.
|
package/dist/client.d.ts
CHANGED
|
@@ -16,6 +16,36 @@ export interface AivethConfig {
|
|
|
16
16
|
storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
|
17
17
|
navigate?: (url: string) => void;
|
|
18
18
|
}
|
|
19
|
+
/** The audience of Aiveth's My workspace API for this issuer. */
|
|
20
|
+
export declare function myWorkspaceAudience(issuer: string): string;
|
|
21
|
+
export interface MyWorkspace {
|
|
22
|
+
workspace: {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
slug: string;
|
|
26
|
+
external_id: string | null;
|
|
27
|
+
members: number;
|
|
28
|
+
created_at: string;
|
|
29
|
+
};
|
|
30
|
+
role: string;
|
|
31
|
+
permissions: string[];
|
|
32
|
+
is_admin: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface WorkspaceMember {
|
|
35
|
+
user_id: string;
|
|
36
|
+
email: string;
|
|
37
|
+
name: string;
|
|
38
|
+
role: string;
|
|
39
|
+
since: string;
|
|
40
|
+
}
|
|
41
|
+
export interface WorkspaceInvitationView {
|
|
42
|
+
id: string;
|
|
43
|
+
email: string;
|
|
44
|
+
role: string;
|
|
45
|
+
invited_at: string;
|
|
46
|
+
expires_at: string;
|
|
47
|
+
new_person: boolean;
|
|
48
|
+
}
|
|
19
49
|
/** Someone acting as the person (Aiveth's "Acting for others"; RFC 8693's `act` claim). */
|
|
20
50
|
export interface Actor {
|
|
21
51
|
/** The support person's Aiveth id. */
|
|
@@ -96,6 +126,29 @@ export declare class AivethClient {
|
|
|
96
126
|
* (`returnTo`), or null when this page load isn't a return from Aiveth. */
|
|
97
127
|
handleRedirect(url: string): Promise<Returned>;
|
|
98
128
|
private exchange;
|
|
129
|
+
/** The signed-in workspace from your own pages (Aiveth's My workspace API): set `audience` to
|
|
130
|
+
* `myWorkspaceAudience(issuer)` and sign in with `workspace`. Every member reads; only the
|
|
131
|
+
* workspace's admins change anything. */
|
|
132
|
+
readonly myWorkspace: {
|
|
133
|
+
get: () => Promise<MyWorkspace>;
|
|
134
|
+
members: (offset?: number) => Promise<{
|
|
135
|
+
members: WorkspaceMember[];
|
|
136
|
+
total: number;
|
|
137
|
+
offset: number;
|
|
138
|
+
page_size: number;
|
|
139
|
+
}>;
|
|
140
|
+
setRole: (userId: string, role: string) => Promise<void>;
|
|
141
|
+
/** An admin removes someone; anyone may leave with their own id. */
|
|
142
|
+
remove: (userId: string) => Promise<void>;
|
|
143
|
+
invitations: () => Promise<WorkspaceInvitationView[]>;
|
|
144
|
+
invite: (email: string, role?: string) => Promise<{
|
|
145
|
+
invitation: WorkspaceInvitationView;
|
|
146
|
+
emailed: boolean;
|
|
147
|
+
link: string | null;
|
|
148
|
+
}>;
|
|
149
|
+
withdraw: (invitationId: string) => Promise<void>;
|
|
150
|
+
};
|
|
151
|
+
private mine;
|
|
99
152
|
/** Switch the active workspace (id or slug): the new tokens name it, and `user` changes with
|
|
100
153
|
* them. The person must be a member. Needs the refresh token (`offline_access`). */
|
|
101
154
|
switchWorkspace(workspace: string): Promise<void>;
|
package/dist/client.js
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* A reload forgets the tokens: `signIn()` again comes straight back while the person is still
|
|
8
8
|
* signed in at Aiveth. The app must be a PUBLIC app (no secret) whose return address is
|
|
9
9
|
* `redirectUri`; its origin may then call Aiveth's token endpoint (CORS). */
|
|
10
|
+
/** The audience of Aiveth's My workspace API for this issuer. */
|
|
11
|
+
export function myWorkspaceAudience(issuer) {
|
|
12
|
+
return `${issuer.replace(/\/+$/, '')}/my-workspace`;
|
|
13
|
+
}
|
|
10
14
|
const PENDING = 'aiveth:pending';
|
|
11
15
|
const DEFAULT_SCOPE = 'openid email profile offline_access';
|
|
12
16
|
/** An access token this close to its end is renewed first. */
|
|
@@ -173,6 +177,34 @@ export class AivethClient {
|
|
|
173
177
|
this.changed();
|
|
174
178
|
return this.tokens;
|
|
175
179
|
}
|
|
180
|
+
/** The signed-in workspace from your own pages (Aiveth's My workspace API): set `audience` to
|
|
181
|
+
* `myWorkspaceAudience(issuer)` and sign in with `workspace`. Every member reads; only the
|
|
182
|
+
* workspace's admins change anything. */
|
|
183
|
+
myWorkspace = {
|
|
184
|
+
get: () => this.mine('GET', ''),
|
|
185
|
+
members: (offset = 0) => this.mine('GET', `/members?offset=${offset}`),
|
|
186
|
+
setRole: (userId, role) => this.mine('PATCH', `/members/${encodeURIComponent(userId)}`, { role }),
|
|
187
|
+
/** An admin removes someone; anyone may leave with their own id. */
|
|
188
|
+
remove: (userId) => this.mine('DELETE', `/members/${encodeURIComponent(userId)}`),
|
|
189
|
+
invitations: () => this.mine('GET', '/invitations'),
|
|
190
|
+
invite: (email, role) => this.mine('POST', '/invitations', role ? { email, role } : { email }),
|
|
191
|
+
withdraw: (invitationId) => this.mine('DELETE', `/invitations/${encodeURIComponent(invitationId)}`),
|
|
192
|
+
};
|
|
193
|
+
async mine(method, path, body) {
|
|
194
|
+
const token = await this.getAccessToken();
|
|
195
|
+
if (!token)
|
|
196
|
+
throw new SignInError('Sign in first.');
|
|
197
|
+
const res = await this.fetcher(`${this.issuer}/v1/my-workspace${path}`, {
|
|
198
|
+
method, headers: { Authorization: `Bearer ${token}`, ...(body === undefined ? {} : { 'Content-Type': 'application/json' }) },
|
|
199
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
200
|
+
});
|
|
201
|
+
if (res.status === 204)
|
|
202
|
+
return undefined;
|
|
203
|
+
const found = (await res.json().catch(() => ({})));
|
|
204
|
+
if (!res.ok)
|
|
205
|
+
throw new RefusedError(String(res.status), typeof found.detail === 'string' ? found.detail : `Aiveth answered ${res.status}.`);
|
|
206
|
+
return found;
|
|
207
|
+
}
|
|
176
208
|
/** Switch the active workspace (id or slug): the new tokens name it, and `user` changes with
|
|
177
209
|
* them. The person must be a member. Needs the refresh token (`offline_access`). */
|
|
178
210
|
async switchWorkspace(workspace) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AivethClient, RefusedError, SignInError, claimsOf, type Actor, type AivethConfig, type Returned, type User } from './client.js';
|
|
1
|
+
export { AivethClient, RefusedError, SignInError, claimsOf, myWorkspaceAudience, type MyWorkspace, type WorkspaceMember, type WorkspaceInvitationView, type Actor, type AivethConfig, type Returned, type User } from './client.js';
|
|
2
2
|
export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, AivethButton, SignOutButton, UserButton, ActingBanner, type AivethProviderProps, type UseAiveth } from './react.js';
|
|
3
3
|
export { BrandedButton, useBrandLook, type BrandLook, type BrandedButtonProps } from './brand.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AivethClient, RefusedError, SignInError, claimsOf } from './client.js';
|
|
1
|
+
export { AivethClient, RefusedError, SignInError, claimsOf, myWorkspaceAudience } from './client.js';
|
|
2
2
|
export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, AivethButton, SignOutButton, UserButton, ActingBanner } from './react.js';
|
|
3
3
|
export { BrandedButton, useBrandLook } from './brand.js';
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
-
import { type Actor, type AivethConfig, type User } from './client.js';
|
|
2
|
+
import { AivethClient, type Actor, type AivethConfig, type User } from './client.js';
|
|
3
3
|
export interface AivethProviderProps extends AivethConfig {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
/** After a return from Aiveth: where to go (your router's navigate), given `returnTo`. */
|
|
@@ -30,6 +30,8 @@ export interface UseAiveth {
|
|
|
30
30
|
actingUrl: string;
|
|
31
31
|
/** Switch the active workspace (id or slug); `user` changes with the new tokens. */
|
|
32
32
|
switchWorkspace: (workspace: string) => Promise<void>;
|
|
33
|
+
/** The signed-in workspace from your pages (needs `audience={myWorkspaceAudience(issuer)}`). */
|
|
34
|
+
myWorkspace: AivethClient['myWorkspace'];
|
|
33
35
|
}
|
|
34
36
|
export declare function useAiveth(): UseAiveth;
|
|
35
37
|
export declare function SignedIn({ children }: {
|
package/dist/react.js
CHANGED
|
@@ -50,6 +50,7 @@ export function useAiveth() {
|
|
|
50
50
|
actor: actorOf(user), actingUrl: client.actingUrl(),
|
|
51
51
|
hasFlag: (key) => Array.isArray(user?.feature_flags) && user.feature_flags.includes(key),
|
|
52
52
|
switchWorkspace: (workspace) => client.switchWorkspace(workspace),
|
|
53
|
+
myWorkspace: client.myWorkspace,
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
export function SignedIn({ children }) {
|
package/package.json
CHANGED