Skip to content

Commit 17e41e0

Browse files
feat: Add user API key methods (#1655)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 5e4813f commit 17e41e0

14 files changed

Lines changed: 380 additions & 0 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"object": "api_key",
3+
"id": "api_key_01EHZNVPK3SFK441A1RGBFSHRT",
4+
"owner": {
5+
"type": "user",
6+
"id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
7+
"organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT"
8+
},
9+
"name": "Production API Key",
10+
"obfuscated_value": "sk_...3456",
11+
"last_used_at": null,
12+
"expires_at": "2030-01-01T00:00:00.000Z",
13+
"permissions": ["posts:read", "posts:write"],
14+
"created_at": "2026-01-15T12:00:00.000Z",
15+
"updated_at": "2026-01-15T12:00:00.000Z",
16+
"value": "test_api_key_value"
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"data": [
3+
{
4+
"object": "api_key",
5+
"id": "api_key_01EHZNVPK3SFK441A1RGBFSHRT",
6+
"owner": {
7+
"type": "user",
8+
"id": "user_01EHZNVPK3SFK441A1RGBFSHRT",
9+
"organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT"
10+
},
11+
"name": "Production API Key",
12+
"obfuscated_value": "sk_...3456",
13+
"last_used_at": null,
14+
"expires_at": null,
15+
"permissions": ["posts:read", "posts:write"],
16+
"created_at": "2026-01-15T12:00:00.000Z",
17+
"updated_at": "2026-01-15T12:00:00.000Z"
18+
}
19+
],
20+
"list_metadata": {
21+
"before": null,
22+
"after": null
23+
}
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { PostOptions } from '../../common/interfaces';
2+
3+
export interface CreateUserApiKeyOptions {
4+
name: string;
5+
organizationId: string;
6+
permissions?: string[];
7+
expiresAt?: Date;
8+
}
9+
10+
export interface SerializedCreateUserApiKeyOptions {
11+
name: string;
12+
organization_id: string;
13+
permissions?: string[];
14+
expires_at?: string;
15+
}
16+
17+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
18+
export interface CreateUserApiKeyRequestOptions extends Pick<
19+
PostOptions,
20+
'idempotencyKey'
21+
> {}

src/user-management/interfaces/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export * from './authorization-url-options.interface';
1919
export * from './create-magic-auth-options.interface';
2020
export * from './create-organization-membership-options.interface';
2121
export * from './create-password-reset-options.interface';
22+
export * from './create-user-api-key-options.interface';
2223
export * from './create-user-options.interface';
2324
export * from './email-verification.interface';
2425
export * from './enroll-auth-factor.interface';
@@ -31,6 +32,7 @@ export * from './list-invitations-options.interface';
3132
export * from './list-organization-memberships-options.interface';
3233
export * from './list-sessions-options.interface';
3334
export * from './list-user-feature-flags-options.interface';
35+
export * from './list-user-api-keys-options.interface';
3436
export * from './list-users-options.interface';
3537
export * from './locale.interface';
3638
export * from './logout-url-options.interface';
@@ -50,4 +52,6 @@ export * from './update-organization-membership-options.interface';
5052
export * from './update-user-options.interface';
5153
export * from './update-user-password-options.interface';
5254
export * from './user.interface';
55+
export * from './user-api-key.interface';
56+
export * from './user-api-key-with-value.interface';
5357
export * from './verify-email-options.interface';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { PaginationOptions } from '../../common/interfaces/pagination-options.interface';
2+
3+
export interface ListUserApiKeysOptions extends PaginationOptions {
4+
organizationId?: string;
5+
}
6+
7+
export interface SerializedListUserApiKeysOptions extends PaginationOptions {
8+
organization_id?: string;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { SerializedUserApiKey, UserApiKey } from './user-api-key.interface';
2+
3+
export interface UserApiKeyWithValue extends UserApiKey {
4+
value: string;
5+
}
6+
7+
export interface SerializedUserApiKeyWithValue extends SerializedUserApiKey {
8+
value: string;
9+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export interface UserApiKey {
2+
object: 'api_key';
3+
id: string;
4+
owner: {
5+
type: 'user';
6+
id: string;
7+
organizationId: string;
8+
};
9+
name: string;
10+
obfuscatedValue: string;
11+
lastUsedAt: string | null;
12+
expiresAt: string | null;
13+
permissions: string[];
14+
createdAt: string;
15+
updatedAt: string;
16+
}
17+
18+
export interface SerializedUserApiKey {
19+
object: 'api_key';
20+
id: string;
21+
owner: {
22+
type: 'user';
23+
id: string;
24+
organization_id: string;
25+
};
26+
name: string;
27+
obfuscated_value: string;
28+
last_used_at: string | null;
29+
expires_at: string | null;
30+
permissions: string[];
31+
created_at: string;
32+
updated_at: string;
33+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {
2+
CreateUserApiKeyOptions,
3+
SerializedCreateUserApiKeyOptions,
4+
} from '../interfaces/create-user-api-key-options.interface';
5+
6+
export function serializeCreateUserApiKeyOptions(
7+
options: CreateUserApiKeyOptions,
8+
): SerializedCreateUserApiKeyOptions {
9+
return {
10+
name: options.name,
11+
organization_id: options.organizationId,
12+
permissions: options.permissions,
13+
expires_at: options.expiresAt?.toISOString(),
14+
};
15+
}

src/user-management/serializers/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ export * from './authentication-factor.serializer';
1212
export * from './authentication-response.serializer';
1313
export * from './create-magic-auth-options.serializer';
1414
export * from './create-password-reset-options.serializer';
15+
export * from './create-user-api-key-options.serializer';
1516
export * from './email-verification.serializer';
1617
export * from './enroll-auth-factor-options.serializer';
1718
export * from './invitation.serializer';
1819
export * from './list-sessions-options.serializer';
20+
export * from './list-user-api-keys-options.serializer';
1921
export * from './magic-auth.serializer';
2022
export * from './password-reset.serializer';
2123
export * from './reset-password-options.serializer';
@@ -25,3 +27,5 @@ export * from './send-radar-sms-challenge-options.serializer';
2527
export * from './update-user-options.serializer';
2628
export * from './update-user-password-options.serializer';
2729
export * from './user.serializer';
30+
export * from './user-api-key.serializer';
31+
export * from './user-api-key-with-value.serializer';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {
2+
ListUserApiKeysOptions,
3+
SerializedListUserApiKeysOptions,
4+
} from '../interfaces/list-user-api-keys-options.interface';
5+
6+
export function serializeListUserApiKeysOptions(
7+
options: ListUserApiKeysOptions,
8+
): SerializedListUserApiKeysOptions {
9+
return {
10+
limit: options.limit,
11+
before: options.before,
12+
after: options.after,
13+
order: options.order,
14+
organization_id: options.organizationId,
15+
};
16+
}

0 commit comments

Comments
 (0)