Skip to content

Commit 460845e

Browse files
feat: Add auth connection event timeline endpoint
1 parent e193e2b commit 460845e

6 files changed

Lines changed: 157 additions & 4 deletions

File tree

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 123
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-ac06dd66a7a0da0dd6dd6cd98127652891b914e880dbaed90d7ab666b13af8a9.yml
3-
openapi_spec_hash: 1d35ae59d6570497f8b379ded59f0434
4-
config_hash: d52b040438a187c46050e0e8395b2f47
1+
configured_endpoints: 124
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-4fb45d71a99648425c84bdc8e5780920105cede4ee2d4eac67276d0609ac1e94.yml
3+
openapi_spec_hash: 1f04cb5b36e92db81dfa264c2a59c32a
4+
config_hash: fb167e754ebb3a14649463725891c9d0

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ Types:
265265
- <code><a href="./src/resources/auth/connections.ts">LoginResponse</a></code>
266266
- <code><a href="./src/resources/auth/connections.ts">ManagedAuth</a></code>
267267
- <code><a href="./src/resources/auth/connections.ts">ManagedAuthCreateRequest</a></code>
268+
- <code><a href="./src/resources/auth/connections.ts">ManagedAuthTimelineEvent</a></code>
268269
- <code><a href="./src/resources/auth/connections.ts">ManagedAuthUpdateRequest</a></code>
269270
- <code><a href="./src/resources/auth/connections.ts">SubmitFieldsRequest</a></code>
270271
- <code><a href="./src/resources/auth/connections.ts">SubmitFieldsResponse</a></code>
@@ -280,6 +281,7 @@ Methods:
280281
- <code title="get /auth/connections/{id}/events">client.auth.connections.<a href="./src/resources/auth/connections.ts">follow</a>(id) -> ConnectionFollowResponse</code>
281282
- <code title="post /auth/connections/{id}/login">client.auth.connections.<a href="./src/resources/auth/connections.ts">login</a>(id, { ...params }) -> LoginResponse</code>
282283
- <code title="post /auth/connections/{id}/submit">client.auth.connections.<a href="./src/resources/auth/connections.ts">submit</a>(id, { ...params }) -> SubmitFieldsResponse</code>
284+
- <code title="get /auth/connections/{id}/timeline">client.auth.connections.<a href="./src/resources/auth/connections.ts">timeline</a>(id, { ...params }) -> ManagedAuthTimelineEventsOffsetPagination</code>
283285

284286
# Proxies
285287

src/resources/auth/auth.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import {
88
ConnectionListParams,
99
ConnectionLoginParams,
1010
ConnectionSubmitParams,
11+
ConnectionTimelineParams,
1112
ConnectionUpdateParams,
1213
Connections,
1314
LoginResponse,
1415
ManagedAuth,
1516
ManagedAuthCreateRequest,
17+
ManagedAuthTimelineEvent,
18+
ManagedAuthTimelineEventsOffsetPagination,
1619
ManagedAuthUpdateRequest,
1720
ManagedAuthsOffsetPagination,
1821
SubmitFieldsRequest,
@@ -31,15 +34,18 @@ export declare namespace Auth {
3134
type LoginResponse as LoginResponse,
3235
type ManagedAuth as ManagedAuth,
3336
type ManagedAuthCreateRequest as ManagedAuthCreateRequest,
37+
type ManagedAuthTimelineEvent as ManagedAuthTimelineEvent,
3438
type ManagedAuthUpdateRequest as ManagedAuthUpdateRequest,
3539
type SubmitFieldsRequest as SubmitFieldsRequest,
3640
type SubmitFieldsResponse as SubmitFieldsResponse,
3741
type ConnectionFollowResponse as ConnectionFollowResponse,
3842
type ManagedAuthsOffsetPagination as ManagedAuthsOffsetPagination,
43+
type ManagedAuthTimelineEventsOffsetPagination as ManagedAuthTimelineEventsOffsetPagination,
3944
type ConnectionCreateParams as ConnectionCreateParams,
4045
type ConnectionUpdateParams as ConnectionUpdateParams,
4146
type ConnectionListParams as ConnectionListParams,
4247
type ConnectionLoginParams as ConnectionLoginParams,
4348
type ConnectionSubmitParams as ConnectionSubmitParams,
49+
type ConnectionTimelineParams as ConnectionTimelineParams,
4450
};
4551
}

src/resources/auth/connections.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,39 @@ export class Connections extends APIResource {
152152
): APIPromise<SubmitFieldsResponse> {
153153
return this._client.post(path`/auth/connections/${id}/submit`, { body, ...options });
154154
}
155+
156+
/**
157+
* Returns a chronological timeline of events for an auth connection — login
158+
* attempts, automatic re-auth attempts, and health checks. Events are returned
159+
* newest-first.
160+
*
161+
* @example
162+
* ```ts
163+
* // Automatically fetches more pages as needed.
164+
* for await (const managedAuthTimelineEvent of client.auth.connections.timeline(
165+
* 'id',
166+
* )) {
167+
* // ...
168+
* }
169+
* ```
170+
*/
171+
timeline(
172+
id: string,
173+
query: ConnectionTimelineParams | null | undefined = {},
174+
options?: RequestOptions,
175+
): PagePromise<ManagedAuthTimelineEventsOffsetPagination, ManagedAuthTimelineEvent> {
176+
return this._client.getAPIList(
177+
path`/auth/connections/${id}/timeline`,
178+
OffsetPagination<ManagedAuthTimelineEvent>,
179+
{ query, ...options },
180+
);
181+
}
155182
}
156183

157184
export type ManagedAuthsOffsetPagination = OffsetPagination<ManagedAuth>;
158185

186+
export type ManagedAuthTimelineEventsOffsetPagination = OffsetPagination<ManagedAuthTimelineEvent>;
187+
159188
/**
160189
* Response from starting a login flow
161190
*/
@@ -764,6 +793,81 @@ export namespace ManagedAuthCreateRequest {
764793
}
765794
}
766795

796+
/**
797+
* A single event in an auth connection's history — a login attempt, an automatic
798+
* re-auth attempt, or a health check.
799+
*/
800+
export interface ManagedAuthTimelineEvent {
801+
/**
802+
* Identifier of the underlying login/reauth session or health check.
803+
*/
804+
id: string;
805+
806+
/**
807+
* Outcome of the event. For login/reauth events this is the flow status
808+
* (IN_PROGRESS, SUCCESS, EXPIRED, CANCELED, FAILED). For health_check events it is
809+
* the observed session state (AUTHENTICATED, NEEDS_AUTH).
810+
*/
811+
status: 'IN_PROGRESS' | 'SUCCESS' | 'EXPIRED' | 'CANCELED' | 'FAILED' | 'AUTHENTICATED' | 'NEEDS_AUTH';
812+
813+
/**
814+
* When the event occurred.
815+
*/
816+
timestamp: string;
817+
818+
/**
819+
* The kind of event. "login" and "reauth" are authentication attempts;
820+
* "health_check" is a periodic session-validity check.
821+
*/
822+
type: 'login' | 'reauth' | 'health_check';
823+
824+
/**
825+
* Machine-readable error code. Present when a login/reauth event failed.
826+
*/
827+
error_code?: string;
828+
829+
/**
830+
* Human-readable error message. Present when a login/reauth event failed.
831+
*/
832+
error_message?: string;
833+
834+
/**
835+
* The session state observed before this event. Present for health_check events
836+
* that recorded a prior state.
837+
*/
838+
previous_status?: 'AUTHENTICATED' | 'NEEDS_AUTH';
839+
840+
/**
841+
* Replay recording ID for the event's browser session, if session recording was
842+
* enabled.
843+
*/
844+
replay_id?: string;
845+
846+
/**
847+
* The step the flow reached. Present for login/reauth events.
848+
*/
849+
step?:
850+
| 'INITIALIZED'
851+
| 'DISCOVERING'
852+
| 'AWAITING_INPUT'
853+
| 'AWAITING_EXTERNAL_ACTION'
854+
| 'AWAITING_HUMAN_INTERVENTION'
855+
| 'SUBMITTING'
856+
| 'COMPLETED'
857+
| 'EXPIRED';
858+
859+
/**
860+
* When the event was last updated. Present for login/reauth events.
861+
*/
862+
updated_at?: string;
863+
864+
/**
865+
* Visible error message from the website (e.g., 'Incorrect password'). Present
866+
* when the website displayed an error during the attempt.
867+
*/
868+
website_error?: string;
869+
}
870+
767871
/**
768872
* Request to update an auth connection's configuration
769873
*/
@@ -1466,20 +1570,30 @@ export interface ConnectionSubmitParams {
14661570
sso_provider?: string;
14671571
}
14681572

1573+
export interface ConnectionTimelineParams extends OffsetPaginationParams {
1574+
/**
1575+
* Filter the timeline to a single event type.
1576+
*/
1577+
type?: 'login' | 'reauth' | 'health_check';
1578+
}
1579+
14691580
export declare namespace Connections {
14701581
export {
14711582
type LoginResponse as LoginResponse,
14721583
type ManagedAuth as ManagedAuth,
14731584
type ManagedAuthCreateRequest as ManagedAuthCreateRequest,
1585+
type ManagedAuthTimelineEvent as ManagedAuthTimelineEvent,
14741586
type ManagedAuthUpdateRequest as ManagedAuthUpdateRequest,
14751587
type SubmitFieldsRequest as SubmitFieldsRequest,
14761588
type SubmitFieldsResponse as SubmitFieldsResponse,
14771589
type ConnectionFollowResponse as ConnectionFollowResponse,
14781590
type ManagedAuthsOffsetPagination as ManagedAuthsOffsetPagination,
1591+
type ManagedAuthTimelineEventsOffsetPagination as ManagedAuthTimelineEventsOffsetPagination,
14791592
type ConnectionCreateParams as ConnectionCreateParams,
14801593
type ConnectionUpdateParams as ConnectionUpdateParams,
14811594
type ConnectionListParams as ConnectionListParams,
14821595
type ConnectionLoginParams as ConnectionLoginParams,
14831596
type ConnectionSubmitParams as ConnectionSubmitParams,
1597+
type ConnectionTimelineParams as ConnectionTimelineParams,
14841598
};
14851599
}

src/resources/auth/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export {
66
type LoginResponse,
77
type ManagedAuth,
88
type ManagedAuthCreateRequest,
9+
type ManagedAuthTimelineEvent,
910
type ManagedAuthUpdateRequest,
1011
type SubmitFieldsRequest,
1112
type SubmitFieldsResponse,
@@ -15,5 +16,7 @@ export {
1516
type ConnectionListParams,
1617
type ConnectionLoginParams,
1718
type ConnectionSubmitParams,
19+
type ConnectionTimelineParams,
1820
type ManagedAuthsOffsetPagination,
21+
type ManagedAuthTimelineEventsOffsetPagination,
1922
} from './connections';

tests/api-resources/auth/connections.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,32 @@ describe('resource connections', () => {
160160
expect(dataAndResponse.data).toBe(response);
161161
expect(dataAndResponse.response).toBe(rawResponse);
162162
});
163+
164+
// Mock server tests are disabled
165+
test.skip('timeline', async () => {
166+
const responsePromise = client.auth.connections.timeline('id');
167+
const rawResponse = await responsePromise.asResponse();
168+
expect(rawResponse).toBeInstanceOf(Response);
169+
const response = await responsePromise;
170+
expect(response).not.toBeInstanceOf(Response);
171+
const dataAndResponse = await responsePromise.withResponse();
172+
expect(dataAndResponse.data).toBe(response);
173+
expect(dataAndResponse.response).toBe(rawResponse);
174+
});
175+
176+
// Mock server tests are disabled
177+
test.skip('timeline: request options and params are passed correctly', async () => {
178+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
179+
await expect(
180+
client.auth.connections.timeline(
181+
'id',
182+
{
183+
limit: 100,
184+
offset: 0,
185+
type: 'login',
186+
},
187+
{ path: '/_stainless_unknown_path' },
188+
),
189+
).rejects.toThrow(Kernel.NotFoundError);
190+
});
163191
});

0 commit comments

Comments
 (0)