@~lyre/auth 0.5.0 → 0.7.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/admin.d.ts CHANGED
@@ -96,6 +96,14 @@ interface InviteEmailCheck {
96
96
  /** When the pending invite lapses — only for `invited`. */
97
97
  expiresAt?: string;
98
98
  }
99
+ /** A workspace (user_group) with its app-scoped profile values. */
100
+ interface WorkspaceProfile {
101
+ id: string;
102
+ slug: string;
103
+ displayName: string;
104
+ /** App-scoped values keyed by field name — e.g. `support_email`. Empty when no app was scoped. */
105
+ profileData: Record<string, string>;
106
+ }
99
107
  /** A pending (not yet accepted, not yet expired) app invitation. */
100
108
  interface PendingInvite {
101
109
  id: string;
@@ -167,20 +175,65 @@ declare class AccountsAdmin {
167
175
  profileData?: Record<string, string> | null;
168
176
  }): Promise<InviteResult>;
169
177
  /**
170
- * The profile fields this app collects about a user — the spec to render an invite form from.
171
- * Session-authed. Never includes email: that is the invite's identity, not a profile value.
178
+ * The profile fields this app collects about a SUBJECT — the spec to render a form from.
179
+ * `ownerType: 'user'` (default) is what an invite form collects about a person; `'user_group'` is
180
+ * what a workspace's edit form collects about itself. Session-authed. A user's email is never
181
+ * included: that is identity, not a profile value.
172
182
  */
173
- listAppProfileFields(appSlug: string): Promise<ProfileFieldSpec[]>;
183
+ listAppProfileFields(appSlug: string, ownerType?: 'user' | 'user_group'): Promise<ProfileFieldSpec[]>;
174
184
  /**
175
185
  * Whether an email can be invited — for a live check on an invite form, so the inviter learns
176
186
  * BEFORE submitting that someone is already a member or already invited. Email only, exact match.
177
187
  * Session-authed.
178
188
  */
179
189
  checkInviteEmail(appSlug: string, email: string): Promise<InviteEmailCheck>;
190
+ /**
191
+ * A workspace's own details — name plus its app-scoped profile values (support email, …).
192
+ * Service-key authed (`stats:read`). Pass `appId` to scope the profile values.
193
+ *
194
+ * Workspace details live in Accounts, which owns the group. Consumers previously had no way to
195
+ * read them and fell back to a retiring legacy system's copy.
196
+ */
197
+ getUserGroup(groupId: string, opts?: {
198
+ appId?: string;
199
+ }): Promise<WorkspaceProfile>;
200
+ /**
201
+ * Update a workspace's name and/or its app-scoped profile values. Service-key authed
202
+ * (`users:write`). An empty profile value CLEARS that field rather than storing an empty string.
203
+ * Accounts drops any key the app does not declare for `user_group`.
204
+ */
205
+ updateUserGroup(groupId: string, input: {
206
+ displayName?: string;
207
+ profileData?: Record<string, string>;
208
+ appId?: string;
209
+ }): Promise<WorkspaceProfile>;
210
+ /**
211
+ * Add a user to a workspace group. Service-key authed (`users:write`).
212
+ *
213
+ * Membership was read-only over the API, which is why "reactivate user" had to fall back to
214
+ * re-INVITING an existing colleague. Use this to restore membership instead.
215
+ */
216
+ addGroupMember(groupId: string, userId: string, opts?: {
217
+ role?: string;
218
+ }): Promise<void>;
219
+ /**
220
+ * Remove a user from a workspace group. Service-key authed (`users:write`). Idempotent.
221
+ *
222
+ * Removing a user's APP access does NOT remove their group membership, and the members list
223
+ * reads membership — so without this a "deleted" user keeps reappearing in the workspace.
224
+ */
225
+ removeGroupMember(groupId: string, userId: string): Promise<void>;
180
226
  /** Revoke a pending invite (withdraw one sent in error). Session-authed. */
181
227
  revokeAppInvite(appSlug: string, inviteId: string): Promise<void>;
182
228
  /** Everyone with access to an app. Session-authed. */
183
229
  listAppUsers(appSlug: string): Promise<AppMember[]>;
230
+ /**
231
+ * Restore an existing user's access to an app. Session-authed. Idempotent.
232
+ *
233
+ * The counterpart to `removeAppUser`. Distinct from `inviteToApp`: this is for an account that
234
+ * already exists and already consented, so it must NOT put the person through registration again.
235
+ */
236
+ addAppUser(appSlug: string, userId: string): Promise<void>;
184
237
  /** Revoke a user's access to an app. Session-authed. */
185
238
  removeAppUser(appSlug: string, userId: string): Promise<void>;
186
239
  /** Members of a user_group (the workspace's agents). Service-key authed (`stats:read`). */
@@ -247,4 +300,4 @@ declare class AccountsAdmin {
247
300
  /** Convenience factory mirroring the SDK's other `create*` helpers. */
248
301
  declare function createAccountsAdmin(opts: AccountsAdminOptions): AccountsAdmin;
249
302
 
250
- export { AccountsAdmin, AccountsAdminError, type AccountsAdminOptions, type AccountsUser, type AppMember, type ChangePasswordResult, type GroupMember, type InviteEmailCheck, type InviteResult, type ListUsersQuery, type ListUsersResult, type PendingInvite, type ProfileFieldSpec, createAccountsAdmin };
303
+ export { AccountsAdmin, AccountsAdminError, type AccountsAdminOptions, type AccountsUser, type AppMember, type ChangePasswordResult, type GroupMember, type InviteEmailCheck, type InviteResult, type ListUsersQuery, type ListUsersResult, type PendingInvite, type ProfileFieldSpec, type WorkspaceProfile, createAccountsAdmin };
package/dist/admin.js CHANGED
@@ -80,13 +80,16 @@ var AccountsAdmin = class {
80
80
  });
81
81
  }
82
82
  /**
83
- * The profile fields this app collects about a user — the spec to render an invite form from.
84
- * Session-authed. Never includes email: that is the invite's identity, not a profile value.
83
+ * The profile fields this app collects about a SUBJECT — the spec to render a form from.
84
+ * `ownerType: 'user'` (default) is what an invite form collects about a person; `'user_group'` is
85
+ * what a workspace's edit form collects about itself. Session-authed. A user's email is never
86
+ * included: that is identity, not a profile value.
85
87
  */
86
- async listAppProfileFields(appSlug) {
88
+ async listAppProfileFields(appSlug, ownerType = "user") {
89
+ const suffix = ownerType === "user_group" ? "?ownerType=user_group" : "";
87
90
  const data = await this.request(
88
91
  "GET",
89
- `/api/auth/apps/${encodeURIComponent(appSlug)}/profile-fields`,
92
+ `/api/auth/apps/${encodeURIComponent(appSlug)}/profile-fields${suffix}`,
90
93
  { auth: "session" }
91
94
  );
92
95
  return data.fields ?? [];
@@ -103,6 +106,59 @@ var AccountsAdmin = class {
103
106
  { auth: "session" }
104
107
  );
105
108
  }
109
+ /**
110
+ * A workspace's own details — name plus its app-scoped profile values (support email, …).
111
+ * Service-key authed (`stats:read`). Pass `appId` to scope the profile values.
112
+ *
113
+ * Workspace details live in Accounts, which owns the group. Consumers previously had no way to
114
+ * read them and fell back to a retiring legacy system's copy.
115
+ */
116
+ async getUserGroup(groupId, opts = {}) {
117
+ const suffix = opts.appId ? `?appId=${encodeURIComponent(opts.appId)}` : "";
118
+ return this.request(
119
+ "GET",
120
+ `/api/auth/user-groups/${encodeURIComponent(groupId)}${suffix}`,
121
+ { auth: "key" }
122
+ );
123
+ }
124
+ /**
125
+ * Update a workspace's name and/or its app-scoped profile values. Service-key authed
126
+ * (`users:write`). An empty profile value CLEARS that field rather than storing an empty string.
127
+ * Accounts drops any key the app does not declare for `user_group`.
128
+ */
129
+ async updateUserGroup(groupId, input) {
130
+ return this.request(
131
+ "PATCH",
132
+ `/api/auth/user-groups/${encodeURIComponent(groupId)}`,
133
+ { auth: "key", body: input }
134
+ );
135
+ }
136
+ /**
137
+ * Add a user to a workspace group. Service-key authed (`users:write`).
138
+ *
139
+ * Membership was read-only over the API, which is why "reactivate user" had to fall back to
140
+ * re-INVITING an existing colleague. Use this to restore membership instead.
141
+ */
142
+ async addGroupMember(groupId, userId, opts = {}) {
143
+ await this.request(
144
+ "POST",
145
+ `/api/auth/user-groups/${encodeURIComponent(groupId)}/members`,
146
+ { auth: "key", body: { userId, ...opts.role ? { role: opts.role } : {} } }
147
+ );
148
+ }
149
+ /**
150
+ * Remove a user from a workspace group. Service-key authed (`users:write`). Idempotent.
151
+ *
152
+ * Removing a user's APP access does NOT remove their group membership, and the members list
153
+ * reads membership — so without this a "deleted" user keeps reappearing in the workspace.
154
+ */
155
+ async removeGroupMember(groupId, userId) {
156
+ await this.request(
157
+ "DELETE",
158
+ `/api/auth/user-groups/${encodeURIComponent(groupId)}/members?userId=${encodeURIComponent(userId)}`,
159
+ { auth: "key" }
160
+ );
161
+ }
106
162
  /** Revoke a pending invite (withdraw one sent in error). Session-authed. */
107
163
  async revokeAppInvite(appSlug, inviteId) {
108
164
  await this.request(
@@ -120,6 +176,19 @@ var AccountsAdmin = class {
120
176
  );
121
177
  return data.users ?? [];
122
178
  }
179
+ /**
180
+ * Restore an existing user's access to an app. Session-authed. Idempotent.
181
+ *
182
+ * The counterpart to `removeAppUser`. Distinct from `inviteToApp`: this is for an account that
183
+ * already exists and already consented, so it must NOT put the person through registration again.
184
+ */
185
+ async addAppUser(appSlug, userId) {
186
+ await this.request(
187
+ "POST",
188
+ `/api/auth/apps/${encodeURIComponent(appSlug)}/users`,
189
+ { auth: "session", body: { userId } }
190
+ );
191
+ }
123
192
  /** Revoke a user's access to an app. Session-authed. */
124
193
  async removeAppUser(appSlug, userId) {
125
194
  await this.request(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@~lyre/auth",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Shared Axis Accounts auth SDK \u2014 framework-agnostic session/identity core (HMAC-signed cookies, accounts login/callback/logout) plus an optional turnkey SvelteKit adapter.",
5
5
  "type": "module",
6
6
  "sideEffects": false,