@hearth-auth/sdk 2.0.4 → 3.0.1
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/README.md +295 -101
- package/dist/admin.d.ts +82 -47
- package/dist/admin.js +179 -132
- package/dist/admin.js.map +1 -1
- package/dist/claims.d.ts +10 -0
- package/dist/claims.js +16 -0
- package/dist/claims.js.map +1 -1
- package/dist/errors.d.ts +18 -6
- package/dist/errors.js +70 -7
- package/dist/errors.js.map +1 -1
- package/dist/generated/admin/schema.d.ts +3650 -0
- package/dist/generated/admin/schema.js +6 -0
- package/dist/generated/admin/schema.js.map +1 -0
- package/dist/hearth-client.d.ts +129 -10
- package/dist/hearth-client.js +278 -83
- package/dist/hearth-client.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/introspection-client.d.ts +9 -3
- package/dist/introspection-client.js +35 -14
- package/dist/introspection-client.js.map +1 -1
- package/dist/jwks-client.d.ts +8 -2
- package/dist/jwks-client.js +20 -10
- package/dist/jwks-client.js.map +1 -1
- package/dist/middleware.d.ts +117 -0
- package/dist/middleware.js +171 -1
- package/dist/middleware.js.map +1 -1
- package/dist/nextjs/edge.d.ts +26 -0
- package/dist/nextjs/edge.js +31 -0
- package/dist/nextjs/edge.js.map +1 -0
- package/dist/nextjs/index.d.ts +50 -0
- package/dist/nextjs/index.js +55 -0
- package/dist/nextjs/index.js.map +1 -0
- package/dist/session-version-cache.js.map +1 -1
- package/dist/types.d.ts +62 -4
- package/package.json +20 -3
package/dist/admin.d.ts
CHANGED
|
@@ -1,22 +1,56 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { components } from "./generated/admin/schema.js";
|
|
2
|
+
import type { CreateUserParams, PageOptions, PageResponse, Realm, UpdateUserParams, User } from "./types.js";
|
|
3
|
+
type Schemas = components["schemas"];
|
|
4
|
+
/** An organization, as `GET /admin/organizations/{id}` returns it. */
|
|
5
|
+
export type Organization = Schemas["AdminOrganization"];
|
|
6
|
+
/** Body of `POST /admin/organizations`. */
|
|
7
|
+
export type CreateOrganizationParams = Schemas["AdminCreateOrganizationRequest"];
|
|
8
|
+
/** Body of `PATCH /admin/organizations/{id}`; absent fields are unchanged. */
|
|
9
|
+
export type UpdateOrganizationParams = Schemas["AdminUpdateOrganizationRequest"];
|
|
10
|
+
/** An OAuth 2.0 client, as the `/admin/applications` routes return it. */
|
|
11
|
+
export type AdminApplication = Schemas["v1OAuthClient"];
|
|
12
|
+
/** Body of `POST /admin/applications`. */
|
|
13
|
+
export type CreateApplicationParams = Schemas["v1RegisterClientRequest"];
|
|
14
|
+
/** Body of `PATCH /admin/applications/{client_id}`; absent fields are unchanged. */
|
|
15
|
+
export type UpdateApplicationParams = Schemas["v1UpdateClientRequest"];
|
|
16
|
+
/** A role, as the `/admin/roles` routes return it. */
|
|
17
|
+
export type AdminRole = Schemas["AdminRole"];
|
|
18
|
+
/** Body of `POST /admin/roles`. */
|
|
19
|
+
export type CreateRoleParams = Schemas["AdminCreateRoleRequest"];
|
|
20
|
+
/** Body of `PATCH /admin/roles/{id}`; absent fields are unchanged. */
|
|
21
|
+
export type UpdateRoleParams = Schemas["AdminUpdateRoleRequest"];
|
|
22
|
+
/** A group, as the `/admin/groups` routes return it. */
|
|
23
|
+
export type AdminGroup = Schemas["AdminGroup"];
|
|
24
|
+
/** Body of `POST /admin/groups`. */
|
|
25
|
+
export type CreateGroupParams = Schemas["AdminCreateGroupRequest"];
|
|
26
|
+
/** Body of `PATCH /admin/groups/{id}`; absent fields are unchanged. */
|
|
27
|
+
export type UpdateGroupParams = Schemas["AdminUpdateGroupRequest"];
|
|
2
28
|
/**
|
|
3
29
|
* Admin API client for Hearth.
|
|
4
30
|
*
|
|
5
31
|
* Requires a valid admin access token. All operations go through
|
|
6
32
|
* the /admin/* endpoints which enforce RBAC admin role checks.
|
|
33
|
+
*
|
|
34
|
+
* Routes and path parameters are typed by the client generated from
|
|
35
|
+
* `docs/api/openapi.json` (`src/generated/admin/`, `make sdk-admin-gen`); the
|
|
36
|
+
* generated names stay internal.
|
|
37
|
+
*
|
|
38
|
+
* Every non-2xx response throws {@link HearthError} carrying the HTTP status
|
|
39
|
+
* and the response body (parsed JSON, or the raw text when it is not JSON).
|
|
7
40
|
*/
|
|
8
41
|
export declare class AdminClient {
|
|
9
|
-
private readonly
|
|
10
|
-
|
|
11
|
-
|
|
42
|
+
private readonly api;
|
|
43
|
+
/**
|
|
44
|
+
* @param baseUrl - Root URL of the Hearth instance.
|
|
45
|
+
* @param realmId - Realm to administer; sent as `X-Realm-ID`.
|
|
46
|
+
* @param accessToken - Token whose subject holds the admin role in that realm.
|
|
47
|
+
* @throws {@link ConfigurationError} when any argument is empty.
|
|
48
|
+
*/
|
|
12
49
|
constructor(baseUrl: string, realmId: string, accessToken: string);
|
|
13
50
|
/** POST /admin/users — create a user. */
|
|
14
51
|
createUser(params: CreateUserParams): Promise<User>;
|
|
15
52
|
/** GET /admin/users — list users with pagination. */
|
|
16
|
-
listUsers(options?:
|
|
17
|
-
limit?: number;
|
|
18
|
-
cursor?: string;
|
|
19
|
-
}): Promise<PageResponse<User>>;
|
|
53
|
+
listUsers(options?: PageOptions): Promise<PageResponse<User>>;
|
|
20
54
|
/** GET /admin/users/:id — get a user by ID. */
|
|
21
55
|
getUser(userId: string): Promise<User>;
|
|
22
56
|
/** PATCH /admin/users/:id — update a user. */
|
|
@@ -24,70 +58,71 @@ export declare class AdminClient {
|
|
|
24
58
|
/** DELETE /admin/users/:id — delete a user. */
|
|
25
59
|
deleteUser(userId: string): Promise<void>;
|
|
26
60
|
/** GET /admin/realms — list realms with pagination. */
|
|
27
|
-
listRealms(options?:
|
|
28
|
-
limit?: number;
|
|
29
|
-
cursor?: string;
|
|
30
|
-
}): Promise<PageResponse<Realm>>;
|
|
61
|
+
listRealms(options?: PageOptions): Promise<PageResponse<Realm>>;
|
|
31
62
|
/** GET /admin/realms/:id — get a realm by ID. */
|
|
32
63
|
getRealm(realmId: string): Promise<Realm>;
|
|
33
64
|
/** DELETE /admin/realms/:id — delete a realm. */
|
|
34
65
|
deleteRealm(realmId: string): Promise<void>;
|
|
35
66
|
/** POST /admin/applications — register an OAuth 2.0 client. */
|
|
36
|
-
createClient(params:
|
|
67
|
+
createClient(params: CreateApplicationParams): Promise<AdminApplication>;
|
|
37
68
|
/** GET /admin/applications/:id — get a client by ID. */
|
|
38
|
-
getClient(clientId: string): Promise<
|
|
69
|
+
getClient(clientId: string): Promise<AdminApplication>;
|
|
39
70
|
/** PATCH /admin/applications/:id — update a client. */
|
|
40
|
-
updateClient(clientId: string, params:
|
|
71
|
+
updateClient(clientId: string, params: UpdateApplicationParams): Promise<AdminApplication>;
|
|
41
72
|
/**
|
|
42
73
|
* POST /admin/applications/:id/regenerate-secret — replace a confidential
|
|
43
74
|
* client's secret. The response carries the new `client_secret` once; the
|
|
44
75
|
* old secret stops working immediately.
|
|
45
76
|
*/
|
|
46
|
-
regenerateClientSecret(clientId: string): Promise<
|
|
77
|
+
regenerateClientSecret(clientId: string): Promise<AdminApplication>;
|
|
47
78
|
/** DELETE /admin/applications/:id — delete a client. */
|
|
48
79
|
deleteClient(clientId: string): Promise<void>;
|
|
49
80
|
/** GET /admin/applications — list clients with optional pagination. */
|
|
50
|
-
listClients(options?:
|
|
51
|
-
limit?: number;
|
|
52
|
-
cursor?: string;
|
|
53
|
-
}): Promise<{
|
|
54
|
-
items: Record<string, unknown>[];
|
|
55
|
-
next_cursor: string | null;
|
|
56
|
-
}>;
|
|
81
|
+
listClients(options?: PageOptions): Promise<PageResponse<AdminApplication>>;
|
|
57
82
|
/** POST /admin/roles — create a role. */
|
|
58
|
-
createRole(params:
|
|
83
|
+
createRole(params: CreateRoleParams): Promise<AdminRole>;
|
|
59
84
|
/** GET /admin/roles/:id — get a role by ID. */
|
|
60
|
-
getRole(roleId: string): Promise<
|
|
85
|
+
getRole(roleId: string): Promise<AdminRole>;
|
|
61
86
|
/** PATCH /admin/roles/:id — update a role. */
|
|
62
|
-
updateRole(roleId: string, params:
|
|
87
|
+
updateRole(roleId: string, params: UpdateRoleParams): Promise<AdminRole>;
|
|
63
88
|
/** DELETE /admin/roles/:id — delete a role. */
|
|
64
89
|
deleteRole(roleId: string): Promise<void>;
|
|
65
90
|
/** GET /admin/roles — list roles with optional pagination. */
|
|
66
|
-
listRoles(options?:
|
|
67
|
-
limit?: number;
|
|
68
|
-
cursor?: string;
|
|
69
|
-
}): Promise<{
|
|
70
|
-
items: Record<string, unknown>[];
|
|
71
|
-
next_cursor: string | null;
|
|
72
|
-
}>;
|
|
91
|
+
listRoles(options?: PageOptions): Promise<PageResponse<AdminRole>>;
|
|
73
92
|
/** POST /admin/groups — create a group. */
|
|
74
|
-
createGroup(params:
|
|
93
|
+
createGroup(params: CreateGroupParams): Promise<AdminGroup>;
|
|
75
94
|
/** GET /admin/groups/:id — get a group by ID. */
|
|
76
|
-
getGroup(groupId: string): Promise<
|
|
95
|
+
getGroup(groupId: string): Promise<AdminGroup>;
|
|
77
96
|
/** PATCH /admin/groups/:id — update a group. */
|
|
78
|
-
updateGroup(groupId: string, params:
|
|
97
|
+
updateGroup(groupId: string, params: UpdateGroupParams): Promise<AdminGroup>;
|
|
79
98
|
/** DELETE /admin/groups/:id — delete a group. */
|
|
80
99
|
deleteGroup(groupId: string): Promise<void>;
|
|
81
100
|
/** GET /admin/groups — list groups with optional pagination. */
|
|
82
|
-
listGroups(options?:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
listGroups(options?: PageOptions): Promise<PageResponse<AdminGroup>>;
|
|
102
|
+
/** GET /admin/organizations — list organizations with pagination. */
|
|
103
|
+
listOrganizations(options?: PageOptions): Promise<PageResponse<Organization>>;
|
|
104
|
+
/** POST /admin/organizations — create an organization. */
|
|
105
|
+
createOrganization(params: CreateOrganizationParams): Promise<Organization>;
|
|
106
|
+
/** GET /admin/organizations/:id — get an organization by ID. */
|
|
107
|
+
getOrganization(orgId: string): Promise<Organization>;
|
|
108
|
+
/**
|
|
109
|
+
* PATCH /admin/organizations/:id — update an organization. A `slug` change
|
|
110
|
+
* is refused with 400 (the slug is immutable).
|
|
111
|
+
*/
|
|
112
|
+
updateOrganization(orgId: string, params: UpdateOrganizationParams): Promise<Organization>;
|
|
113
|
+
/** DELETE /admin/organizations/:id — delete an organization. */
|
|
114
|
+
deleteOrganization(orgId: string): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* GET /admin/organizations/:id/members/:userId/roles — the names of the
|
|
117
|
+
* extra org roles a member holds on top of the organization's base role.
|
|
118
|
+
*/
|
|
119
|
+
listMemberRoles(orgId: string, userId: string): Promise<string[]>;
|
|
120
|
+
/**
|
|
121
|
+
* POST /admin/organizations/:id/members/:userId/roles — give a member an
|
|
122
|
+
* extra org role. The user must already be a member (409 otherwise).
|
|
123
|
+
*/
|
|
124
|
+
addMemberRole(orgId: string, userId: string, roleName: string): Promise<void>;
|
|
125
|
+
/** DELETE /admin/organizations/:id/members/:userId/roles/:roleName — remove an extra org role. */
|
|
126
|
+
removeMemberRole(orgId: string, userId: string, roleName: string): Promise<void>;
|
|
93
127
|
}
|
|
128
|
+
export {};
|
package/dist/admin.js
CHANGED
|
@@ -1,57 +1,68 @@
|
|
|
1
|
+
import createClient from "openapi-fetch";
|
|
1
2
|
import { HearthError } from "./client.js";
|
|
3
|
+
import { ConfigurationError } from "./errors.js";
|
|
2
4
|
/**
|
|
3
5
|
* Admin API client for Hearth.
|
|
4
6
|
*
|
|
5
7
|
* Requires a valid admin access token. All operations go through
|
|
6
8
|
* the /admin/* endpoints which enforce RBAC admin role checks.
|
|
9
|
+
*
|
|
10
|
+
* Routes and path parameters are typed by the client generated from
|
|
11
|
+
* `docs/api/openapi.json` (`src/generated/admin/`, `make sdk-admin-gen`); the
|
|
12
|
+
* generated names stay internal.
|
|
13
|
+
*
|
|
14
|
+
* Every non-2xx response throws {@link HearthError} carrying the HTTP status
|
|
15
|
+
* and the response body (parsed JSON, or the raw text when it is not JSON).
|
|
7
16
|
*/
|
|
8
17
|
export class AdminClient {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
api;
|
|
19
|
+
/**
|
|
20
|
+
* @param baseUrl - Root URL of the Hearth instance.
|
|
21
|
+
* @param realmId - Realm to administer; sent as `X-Realm-ID`.
|
|
22
|
+
* @param accessToken - Token whose subject holds the admin role in that realm.
|
|
23
|
+
* @throws {@link ConfigurationError} when any argument is empty.
|
|
24
|
+
*/
|
|
12
25
|
constructor(baseUrl, realmId, accessToken) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
if (!baseUrl)
|
|
27
|
+
throw new ConfigurationError("AdminClient: baseUrl is required");
|
|
28
|
+
if (!realmId)
|
|
29
|
+
throw new ConfigurationError("AdminClient: realmId is required");
|
|
30
|
+
if (!accessToken)
|
|
31
|
+
throw new ConfigurationError("AdminClient: accessToken is required");
|
|
32
|
+
this.api = createClient({
|
|
33
|
+
baseUrl: baseUrl.replace(/\/$/, ""),
|
|
34
|
+
headers: { "X-Realm-ID": realmId, Authorization: `Bearer ${accessToken}` },
|
|
35
|
+
fetch: forwardToGlobalFetch,
|
|
36
|
+
});
|
|
16
37
|
}
|
|
17
38
|
// === Users ===
|
|
18
39
|
/** POST /admin/users — create a user. */
|
|
19
40
|
async createUser(params) {
|
|
20
|
-
|
|
21
|
-
email: params.email,
|
|
22
|
-
|
|
23
|
-
|
|
41
|
+
const user = await unwrap(this.api.POST("/admin/users", {
|
|
42
|
+
body: { email: params.email, display_name: params.displayName },
|
|
43
|
+
}));
|
|
44
|
+
return toUser(user);
|
|
24
45
|
}
|
|
25
46
|
/** GET /admin/users — list users with pagination. */
|
|
26
47
|
async listUsers(options) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
q.set("limit", String(options.limit));
|
|
30
|
-
if (options?.cursor)
|
|
31
|
-
q.set("cursor", options.cursor);
|
|
32
|
-
return this.get(`/admin/users?${q}`);
|
|
48
|
+
const result = await unwrap(this.api.GET("/admin/users", { params: { query: page(options) } }));
|
|
49
|
+
return { items: (result.items ?? []).map(toUser), next_cursor: result.next_cursor ?? null };
|
|
33
50
|
}
|
|
34
51
|
/** GET /admin/users/:id — get a user by ID. */
|
|
35
52
|
async getUser(userId) {
|
|
36
|
-
return this.
|
|
53
|
+
return toUser(await unwrap(this.api.GET("/admin/users/{id}", { params: { path: { id: userId } } })));
|
|
37
54
|
}
|
|
38
55
|
/** PATCH /admin/users/:id — update a user. */
|
|
39
56
|
async updateUser(userId, params) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
display_name: params.displayName,
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
const user = await unwrap(this.api.PATCH("/admin/users/{id}", {
|
|
58
|
+
params: { path: { id: userId } },
|
|
59
|
+
body: { email: params.email, display_name: params.displayName, status: params.status },
|
|
60
|
+
}));
|
|
61
|
+
return toUser(user);
|
|
45
62
|
}
|
|
46
63
|
/** DELETE /admin/users/:id — delete a user. */
|
|
47
64
|
async deleteUser(userId) {
|
|
48
|
-
|
|
49
|
-
method: "DELETE",
|
|
50
|
-
headers: this.headers(),
|
|
51
|
-
});
|
|
52
|
-
if (!resp.ok) {
|
|
53
|
-
throw new HearthError(resp.status, await resp.json());
|
|
54
|
-
}
|
|
65
|
+
await unwrap(this.api.DELETE("/admin/users/{id}", { params: { path: { id: userId } } }));
|
|
55
66
|
}
|
|
56
67
|
// === Realms ===
|
|
57
68
|
//
|
|
@@ -62,39 +73,34 @@ export class AdminClient {
|
|
|
62
73
|
// paths and deletion are exposed.
|
|
63
74
|
/** GET /admin/realms — list realms with pagination. */
|
|
64
75
|
async listRealms(options) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
q.set("limit", String(options.limit));
|
|
68
|
-
if (options?.cursor)
|
|
69
|
-
q.set("cursor", options.cursor);
|
|
70
|
-
return this.get(`/admin/realms?${q}`);
|
|
76
|
+
const result = await unwrap(this.api.GET("/admin/realms", { params: { query: page(options) } }));
|
|
77
|
+
return { items: (result.items ?? []).map(toRealm), next_cursor: result.next_cursor ?? null };
|
|
71
78
|
}
|
|
72
79
|
/** GET /admin/realms/:id — get a realm by ID. */
|
|
73
80
|
async getRealm(realmId) {
|
|
74
|
-
return this.
|
|
81
|
+
return toRealm(await unwrap(this.api.GET("/admin/realms/{id}", { params: { path: { id: realmId } } })));
|
|
75
82
|
}
|
|
76
83
|
/** DELETE /admin/realms/:id — delete a realm. */
|
|
77
84
|
async deleteRealm(realmId) {
|
|
78
|
-
|
|
79
|
-
method: "DELETE",
|
|
80
|
-
headers: this.headers(),
|
|
81
|
-
});
|
|
82
|
-
if (!resp.ok) {
|
|
83
|
-
throw new HearthError(resp.status, await resp.json());
|
|
84
|
-
}
|
|
85
|
+
await unwrap(this.api.DELETE("/admin/realms/{id}", { params: { path: { id: realmId } } }));
|
|
85
86
|
}
|
|
86
87
|
// === OAuth Clients ===
|
|
87
88
|
/** POST /admin/applications — register an OAuth 2.0 client. */
|
|
88
89
|
async createClient(params) {
|
|
89
|
-
return this.
|
|
90
|
+
return unwrap(this.api.POST("/admin/applications", { body: params }));
|
|
90
91
|
}
|
|
91
92
|
/** GET /admin/applications/:id — get a client by ID. */
|
|
92
93
|
async getClient(clientId) {
|
|
93
|
-
return this.
|
|
94
|
+
return unwrap(this.api.GET("/admin/applications/{client_id}", {
|
|
95
|
+
params: { path: { client_id: clientId } },
|
|
96
|
+
}));
|
|
94
97
|
}
|
|
95
98
|
/** PATCH /admin/applications/:id — update a client. */
|
|
96
99
|
async updateClient(clientId, params) {
|
|
97
|
-
return this.
|
|
100
|
+
return unwrap(this.api.PATCH("/admin/applications/{client_id}", {
|
|
101
|
+
params: { path: { client_id: clientId } },
|
|
102
|
+
body: params,
|
|
103
|
+
}));
|
|
98
104
|
}
|
|
99
105
|
/**
|
|
100
106
|
* POST /admin/applications/:id/regenerate-secret — replace a confidential
|
|
@@ -102,130 +108,171 @@ export class AdminClient {
|
|
|
102
108
|
* old secret stops working immediately.
|
|
103
109
|
*/
|
|
104
110
|
async regenerateClientSecret(clientId) {
|
|
105
|
-
return this.
|
|
111
|
+
return unwrap(this.api.POST("/admin/applications/{client_id}/regenerate-secret", {
|
|
112
|
+
params: { path: { client_id: clientId } },
|
|
113
|
+
}));
|
|
106
114
|
}
|
|
107
115
|
/** DELETE /admin/applications/:id — delete a client. */
|
|
108
116
|
async deleteClient(clientId) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
});
|
|
113
|
-
if (!resp.ok) {
|
|
114
|
-
throw new HearthError(resp.status, await resp.json());
|
|
115
|
-
}
|
|
117
|
+
await unwrap(this.api.DELETE("/admin/applications/{client_id}", {
|
|
118
|
+
params: { path: { client_id: clientId } },
|
|
119
|
+
}));
|
|
116
120
|
}
|
|
117
121
|
/** GET /admin/applications — list clients with optional pagination. */
|
|
118
122
|
async listClients(options) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
q.set("limit", String(options.limit));
|
|
122
|
-
if (options?.cursor)
|
|
123
|
-
q.set("cursor", options.cursor);
|
|
124
|
-
const qs = q.toString();
|
|
125
|
-
return this.get(`/admin/applications${qs ? `?${qs}` : ""}`);
|
|
123
|
+
const result = await unwrap(this.api.GET("/admin/applications", { params: { query: page(options) } }));
|
|
124
|
+
return { items: result.items ?? [], next_cursor: result.next_cursor ?? null };
|
|
126
125
|
}
|
|
127
126
|
// === Roles ===
|
|
128
127
|
/** POST /admin/roles — create a role. */
|
|
129
128
|
async createRole(params) {
|
|
130
|
-
return this.
|
|
129
|
+
return unwrap(this.api.POST("/admin/roles", { body: params }));
|
|
131
130
|
}
|
|
132
131
|
/** GET /admin/roles/:id — get a role by ID. */
|
|
133
132
|
async getRole(roleId) {
|
|
134
|
-
return this.
|
|
133
|
+
return unwrap(this.api.GET("/admin/roles/{id}", { params: { path: { id: roleId } } }));
|
|
135
134
|
}
|
|
136
135
|
/** PATCH /admin/roles/:id — update a role. */
|
|
137
136
|
async updateRole(roleId, params) {
|
|
138
|
-
return this.
|
|
137
|
+
return unwrap(this.api.PATCH("/admin/roles/{id}", { params: { path: { id: roleId } }, body: params }));
|
|
139
138
|
}
|
|
140
139
|
/** DELETE /admin/roles/:id — delete a role. */
|
|
141
140
|
async deleteRole(roleId) {
|
|
142
|
-
|
|
143
|
-
method: "DELETE",
|
|
144
|
-
headers: this.headers(),
|
|
145
|
-
});
|
|
146
|
-
if (!resp.ok) {
|
|
147
|
-
throw new HearthError(resp.status, await resp.json());
|
|
148
|
-
}
|
|
141
|
+
await unwrap(this.api.DELETE("/admin/roles/{id}", { params: { path: { id: roleId } } }));
|
|
149
142
|
}
|
|
150
143
|
/** GET /admin/roles — list roles with optional pagination. */
|
|
151
144
|
async listRoles(options) {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
q.set("limit", String(options.limit));
|
|
155
|
-
if (options?.cursor)
|
|
156
|
-
q.set("cursor", options.cursor);
|
|
157
|
-
const qs = q.toString();
|
|
158
|
-
return this.get(`/admin/roles${qs ? `?${qs}` : ""}`);
|
|
145
|
+
const result = await unwrap(this.api.GET("/admin/roles", { params: { query: page(options) } }));
|
|
146
|
+
return { items: result.items, next_cursor: result.next_cursor ?? null };
|
|
159
147
|
}
|
|
160
148
|
// === Groups ===
|
|
161
149
|
/** POST /admin/groups — create a group. */
|
|
162
150
|
async createGroup(params) {
|
|
163
|
-
return this.
|
|
151
|
+
return unwrap(this.api.POST("/admin/groups", { body: params }));
|
|
164
152
|
}
|
|
165
153
|
/** GET /admin/groups/:id — get a group by ID. */
|
|
166
154
|
async getGroup(groupId) {
|
|
167
|
-
return this.
|
|
155
|
+
return unwrap(this.api.GET("/admin/groups/{id}", { params: { path: { id: groupId } } }));
|
|
168
156
|
}
|
|
169
157
|
/** PATCH /admin/groups/:id — update a group. */
|
|
170
158
|
async updateGroup(groupId, params) {
|
|
171
|
-
return this.
|
|
159
|
+
return unwrap(this.api.PATCH("/admin/groups/{id}", { params: { path: { id: groupId } }, body: params }));
|
|
172
160
|
}
|
|
173
161
|
/** DELETE /admin/groups/:id — delete a group. */
|
|
174
162
|
async deleteGroup(groupId) {
|
|
175
|
-
|
|
176
|
-
method: "DELETE",
|
|
177
|
-
headers: this.headers(),
|
|
178
|
-
});
|
|
179
|
-
if (!resp.ok) {
|
|
180
|
-
throw new HearthError(resp.status, await resp.json());
|
|
181
|
-
}
|
|
163
|
+
await unwrap(this.api.DELETE("/admin/groups/{id}", { params: { path: { id: groupId } } }));
|
|
182
164
|
}
|
|
183
165
|
/** GET /admin/groups — list groups with optional pagination. */
|
|
184
166
|
async listGroups(options) {
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (!resp.ok) {
|
|
226
|
-
throw new HearthError(resp.status, await resp.json());
|
|
227
|
-
}
|
|
228
|
-
return resp.json();
|
|
167
|
+
const result = await unwrap(this.api.GET("/admin/groups", { params: { query: page(options) } }));
|
|
168
|
+
return { items: result.items, next_cursor: result.next_cursor ?? null };
|
|
169
|
+
}
|
|
170
|
+
// === Organizations ===
|
|
171
|
+
/** GET /admin/organizations — list organizations with pagination. */
|
|
172
|
+
async listOrganizations(options) {
|
|
173
|
+
const result = await unwrap(this.api.GET("/admin/organizations", { params: { query: page(options) } }));
|
|
174
|
+
return { items: result.items, next_cursor: result.next_cursor ?? null };
|
|
175
|
+
}
|
|
176
|
+
/** POST /admin/organizations — create an organization. */
|
|
177
|
+
async createOrganization(params) {
|
|
178
|
+
return unwrap(this.api.POST("/admin/organizations", { body: params }));
|
|
179
|
+
}
|
|
180
|
+
/** GET /admin/organizations/:id — get an organization by ID. */
|
|
181
|
+
async getOrganization(orgId) {
|
|
182
|
+
return unwrap(this.api.GET("/admin/organizations/{id}", { params: { path: { id: orgId } } }));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* PATCH /admin/organizations/:id — update an organization. A `slug` change
|
|
186
|
+
* is refused with 400 (the slug is immutable).
|
|
187
|
+
*/
|
|
188
|
+
async updateOrganization(orgId, params) {
|
|
189
|
+
return unwrap(this.api.PATCH("/admin/organizations/{id}", {
|
|
190
|
+
params: { path: { id: orgId } },
|
|
191
|
+
body: params,
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
/** DELETE /admin/organizations/:id — delete an organization. */
|
|
195
|
+
async deleteOrganization(orgId) {
|
|
196
|
+
await unwrap(this.api.DELETE("/admin/organizations/{id}", { params: { path: { id: orgId } } }));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* GET /admin/organizations/:id/members/:userId/roles — the names of the
|
|
200
|
+
* extra org roles a member holds on top of the organization's base role.
|
|
201
|
+
*/
|
|
202
|
+
async listMemberRoles(orgId, userId) {
|
|
203
|
+
const result = await unwrap(this.api.GET("/admin/organizations/{id}/members/{user_id}/roles", {
|
|
204
|
+
params: { path: { id: orgId, user_id: userId } },
|
|
205
|
+
}));
|
|
206
|
+
return result.items;
|
|
229
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* POST /admin/organizations/:id/members/:userId/roles — give a member an
|
|
210
|
+
* extra org role. The user must already be a member (409 otherwise).
|
|
211
|
+
*/
|
|
212
|
+
async addMemberRole(orgId, userId, roleName) {
|
|
213
|
+
await unwrap(this.api.POST("/admin/organizations/{id}/members/{user_id}/roles", {
|
|
214
|
+
params: { path: { id: orgId, user_id: userId } },
|
|
215
|
+
body: { role_name: roleName },
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
/** DELETE /admin/organizations/:id/members/:userId/roles/:roleName — remove an extra org role. */
|
|
219
|
+
async removeMemberRole(orgId, userId, roleName) {
|
|
220
|
+
await unwrap(this.api.DELETE("/admin/organizations/{id}/members/{user_id}/roles/{role_name}", {
|
|
221
|
+
params: { path: { id: orgId, user_id: userId, role_name: roleName } },
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** The `limit` and `cursor` query parameters of a list call; unset ones are left out. */
|
|
226
|
+
function page(options) {
|
|
227
|
+
return { limit: options?.limit, cursor: options?.cursor };
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* A user from the proto-derived `v1User` schema. Proto3 JSON leaves out a
|
|
231
|
+
* field that holds its default value, so an absent string reads as `""`.
|
|
232
|
+
*/
|
|
233
|
+
function toUser(user) {
|
|
234
|
+
return {
|
|
235
|
+
id: user.id ?? "",
|
|
236
|
+
email: user.email ?? "",
|
|
237
|
+
display_name: user.display_name ?? "",
|
|
238
|
+
status: user.status ?? "USER_STATUS_UNSPECIFIED",
|
|
239
|
+
created_at: user.created_at,
|
|
240
|
+
updated_at: user.updated_at,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** A realm from the proto-derived `v1Realm` schema (see {@link toUser}). */
|
|
244
|
+
function toRealm(realm) {
|
|
245
|
+
return {
|
|
246
|
+
id: realm.id ?? "",
|
|
247
|
+
name: realm.name ?? "",
|
|
248
|
+
status: realm.status ?? "REALM_STATUS_UNSPECIFIED",
|
|
249
|
+
config: realm.config ?? null,
|
|
250
|
+
created_at: realm.created_at,
|
|
251
|
+
updated_at: realm.updated_at,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Resolve an openapi-fetch call to its parsed body, typed by the generated
|
|
256
|
+
* schema of the route's success response (`undefined` for an empty body, e.g.
|
|
257
|
+
* 204), or throw {@link HearthError} on any non-2xx status.
|
|
258
|
+
*/
|
|
259
|
+
async function unwrap(call) {
|
|
260
|
+
const { data, error, response } = await call;
|
|
261
|
+
if (!response.ok)
|
|
262
|
+
throw new HearthError(response.status, error === "" ? null : (error ?? null));
|
|
263
|
+
return data;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* openapi-fetch calls `fetch(request)`. Forward to the global `fetch` as
|
|
267
|
+
* `(url, init)`, read at call time, so the SDK keeps one transport shape and a
|
|
268
|
+
* stubbed global `fetch` sees every admin call.
|
|
269
|
+
*/
|
|
270
|
+
async function forwardToGlobalFetch(request) {
|
|
271
|
+
const body = request.body === null ? undefined : await request.text();
|
|
272
|
+
return globalThis.fetch(request.url, {
|
|
273
|
+
method: request.method,
|
|
274
|
+
headers: request.headers,
|
|
275
|
+
body,
|
|
276
|
+
});
|
|
230
277
|
}
|
|
231
278
|
//# sourceMappingURL=admin.js.map
|