Skip to content

Commit 91c5745

Browse files
committed
chore(bb-auth-cognito): update API report + add changeset for auth.admin
Regenerate API.md to include the admin surface (AdminOptions, AdminSurface, GroupAdmin/LifecycleAdmin, AdminGetterOf, AdminUser, AdminCreateInit) and the const O class generic. Add a minor changeset documenting the feature + the const O breaking change.
1 parent 89d8076 commit 91c5745

2 files changed

Lines changed: 93 additions & 1 deletion

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"@aws-blocks/bb-auth-cognito": minor
3+
---
4+
5+
Add an opt-in `auth.admin` handle to `AuthCognito` for server-side group-membership and user-lifecycle administration.
6+
7+
Enable it by passing an `admin` options object; `admin.actions` scopes the granted `Admin*` / `List*` IAM. Without it, `auth.admin` is a compile error and no admin IAM is granted (unchanged default). Group names on the admin methods narrow via `GroupOf<O>`.
8+
9+
```ts
10+
const auth = new AuthCognito(scope, 'auth', { groups: ['admins'], admin: { actions: ['groups'] } });
11+
await auth.admin.addUserToGroup('alice', 'admins');
12+
```
13+
14+
The `AuthCognito` class generic is now a `const` type parameter, so inline options literals narrow without `as const`.
15+
16+
BREAKING CHANGE: `const O` narrows the params of `requireRole`, `updateUserAttribute`, and `updateMFAPreference` for inline-literal options. Callers passing widened `string` variables to these now need a cast or literal arguments.

packages/bb-auth-cognito/API.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,45 @@ import type { ChildLogger } from '@aws-blocks/bb-logger';
1212
import { Scope } from '@aws-blocks/core';
1313
import type { ScopeParent } from '@aws-blocks/core';
1414

15+
// @public
16+
export interface AdminCreateInit {
17+
attributes?: Record<string, string>;
18+
suppressInvite?: boolean;
19+
temporaryPassword?: string;
20+
}
21+
22+
// @public
23+
export type AdminDisabled = {
24+
readonly __adminNotEnabled: 'construct AuthCognito with { admin: {} }';
25+
};
26+
27+
// @public
28+
export type AdminGetterOf<O extends AuthCognitoOptions> = O extends {
29+
admin: object;
30+
} ? AdminSurface<O> : AdminDisabled;
31+
32+
// @public
33+
export interface AdminOptions {
34+
actions?: readonly ('groups' | 'lifecycle')[];
35+
}
36+
37+
// @public
38+
export type AdminSurface<O extends AuthCognitoOptions = AuthCognitoOptions> = GroupAdmin<O> & LifecycleAdmin<O>;
39+
40+
// @public
41+
export interface AdminUser {
42+
// (undocumented)
43+
attributes: Record<string, string>;
44+
// (undocumented)
45+
enabled: boolean;
46+
// (undocumented)
47+
groups?: string[];
48+
// (undocumented)
49+
username: string;
50+
// (undocumented)
51+
userSub: string;
52+
}
53+
1554
// Warning: (ae-incompatible-release-tags) The symbol "AttrOf" is marked as @public, but its signature references "CustomAttrNames" which is marked as @internal
1655
//
1756
// @public
@@ -20,8 +59,9 @@ export type AttrOf<O extends AuthCognitoOptions> = O extends {
2059
} ? StandardUserAttributeKey | CustomAttrNames<O> | `custom:${CustomAttrNames<O>}` : string;
2160

2261
// @public
23-
export class AuthCognito<O extends AuthCognitoMockOptions = AuthCognitoMockOptions> extends Scope implements BlocksAuth {
62+
export class AuthCognito<const O extends AuthCognitoMockOptions = AuthCognitoMockOptions> extends Scope implements BlocksAuth {
2463
constructor(scope: ScopeParent, id: string, options?: O);
64+
get admin(): AdminGetterOf<O>;
2565
autoSignIn(context: BlocksContext): Promise<SignInResult<O>>;
2666
checkAuth(context: BlocksContext): Promise<boolean>;
2767
completePasskeyRegistration(context: BlocksContext, credential: string): Promise<CompletePasskeyRegistrationResult>;
@@ -114,6 +154,7 @@ export interface AuthCognitoMockOptions extends AuthCognitoOptions {
114154

115155
// @public
116156
export interface AuthCognitoOptions {
157+
admin?: AdminOptions;
117158
authFlowType?: AuthFlowType;
118159
crossDomain?: boolean;
119160
deviceTracking?: {
@@ -270,6 +311,18 @@ export interface FetchAuthSessionOptions {
270311
forceRefresh?: boolean;
271312
}
272313

314+
// @public
315+
export interface GroupAdmin<O extends AuthCognitoOptions = AuthCognitoOptions> {
316+
// (undocumented)
317+
addUserToGroup(username: string, group: GroupOf<O>): Promise<void>;
318+
// (undocumented)
319+
listGroupsForUser(username: string): Promise<GroupOf<O>[]>;
320+
// (undocumented)
321+
listUsersInGroup(group: GroupOf<O>): Promise<AdminUser[]>;
322+
// (undocumented)
323+
removeUserFromGroup(username: string, group: GroupOf<O>): Promise<void>;
324+
}
325+
273326
// @public
274327
export type GroupOf<O extends AuthCognitoOptions> = O extends {
275328
groups: readonly [unknown, ...unknown[]];
@@ -292,6 +345,28 @@ export interface JWT {
292345
toString(): string;
293346
}
294347

348+
// @public
349+
export interface LifecycleAdmin<O extends AuthCognitoOptions = AuthCognitoOptions> {
350+
// (undocumented)
351+
createUser(username: string, init?: AdminCreateInit): Promise<AdminUser>;
352+
// (undocumented)
353+
deleteUser(username: string): Promise<void>;
354+
// (undocumented)
355+
disableUser(username: string): Promise<void>;
356+
// (undocumented)
357+
enableUser(username: string): Promise<void>;
358+
// (undocumented)
359+
getUser(username: string): Promise<AdminUser | null>;
360+
// (undocumented)
361+
resetUserPassword(username: string): Promise<void>;
362+
// (undocumented)
363+
revokeUserSessions(username: string): Promise<void>;
364+
// (undocumented)
365+
scan(): AsyncIterable<AdminUser>;
366+
// (undocumented)
367+
setUserPassword(username: string, password: string, permanent: boolean): Promise<void>;
368+
}
369+
295370
// @public
296371
export function makeExternalUserPoolRef(userPoolId: string, clientId?: string): ExternalUserPoolRef;
297372

@@ -376,6 +451,7 @@ export interface SessionRecord {
376451
export class SessionStore {
377452
constructor(scope: ScopeParent, id?: string);
378453
createSession(record: SessionRecord): Promise<string>;
454+
deleteByUsername(username: string): Promise<number>;
379455
deleteSession(sessionId: string): Promise<void>;
380456
lookupSession(sessionId: string): Promise<SessionRecord | null>;
381457
// (undocumented)

0 commit comments

Comments
 (0)