-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauth.ts
More file actions
509 lines (440 loc) · 11.7 KB
/
auth.ts
File metadata and controls
509 lines (440 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../../core/resource';
import * as InvocationsAPI from './invocations';
import {
InvocationCreateParams,
InvocationDiscoverParams,
InvocationExchangeParams,
InvocationExchangeResponse,
InvocationSubmitParams,
Invocations,
} from './invocations';
import { APIPromise } from '../../../core/api-promise';
import { OffsetPagination, type OffsetPaginationParams, PagePromise } from '../../../core/pagination';
import { buildHeaders } from '../../../internal/headers';
import { RequestOptions } from '../../../internal/request-options';
import { path } from '../../../internal/utils/path';
export class Auth extends APIResource {
invocations: InvocationsAPI.Invocations = new InvocationsAPI.Invocations(this._client);
/**
* Creates a new auth agent for the specified domain and profile combination, or
* returns an existing one if it already exists. This is idempotent - calling with
* the same domain and profile will return the same agent. Does NOT start an
* invocation - use POST /agents/auth/invocations to start an auth flow.
*
* @example
* ```ts
* const authAgent = await client.agents.auth.create({
* profile_name: 'user-123',
* target_domain: 'netflix.com',
* });
* ```
*/
create(body: AuthCreateParams, options?: RequestOptions): APIPromise<AuthAgent> {
return this._client.post('/agents/auth', { body, ...options });
}
/**
* Retrieve an auth agent by its ID. Returns the current authentication status of
* the managed profile.
*
* @example
* ```ts
* const authAgent = await client.agents.auth.retrieve('id');
* ```
*/
retrieve(id: string, options?: RequestOptions): APIPromise<AuthAgent> {
return this._client.get(path`/agents/auth/${id}`, options);
}
/**
* List auth agents with optional filters for profile_name and target_domain.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const authAgent of client.agents.auth.list()) {
* // ...
* }
* ```
*/
list(
query: AuthListParams | null | undefined = {},
options?: RequestOptions,
): PagePromise<AuthAgentsOffsetPagination, AuthAgent> {
return this._client.getAPIList('/agents/auth', OffsetPagination<AuthAgent>, { query, ...options });
}
/**
* Deletes an auth agent and terminates its workflow. This will:
*
* - Soft delete the auth agent record
* - Gracefully terminate the agent's Temporal workflow
* - Cancel any in-progress invocations
*
* @example
* ```ts
* await client.agents.auth.delete('id');
* ```
*/
delete(id: string, options?: RequestOptions): APIPromise<void> {
return this._client.delete(path`/agents/auth/${id}`, {
...options,
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
});
}
/**
* Triggers automatic re-authentication for an auth agent using stored credentials.
* Requires the auth agent to have a linked credential, stored selectors, and
* login_url. Returns immediately with status indicating whether re-auth was
* started.
*
* @example
* ```ts
* const reauthResponse = await client.agents.auth.reauth(
* 'id',
* );
* ```
*/
reauth(id: string, options?: RequestOptions): APIPromise<ReauthResponse> {
return this._client.post(path`/agents/auth/${id}/reauth`, options);
}
}
export type AuthAgentsOffsetPagination = OffsetPagination<AuthAgent>;
/**
* Response from discover endpoint matching AuthBlueprint schema
*/
export interface AgentAuthDiscoverResponse {
/**
* Whether discovery succeeded
*/
success: boolean;
/**
* Error message if discovery failed
*/
error_message?: string;
/**
* Discovered form fields (present when success is true)
*/
fields?: Array<DiscoveredField>;
/**
* Whether user is already logged in
*/
logged_in?: boolean;
/**
* URL of the discovered login page
*/
login_url?: string;
/**
* Title of the login page
*/
page_title?: string;
}
/**
* Response from get invocation endpoint
*/
export interface AgentAuthInvocationResponse {
/**
* App name (org name at time of invocation creation)
*/
app_name: string;
/**
* When the handoff code expires
*/
expires_at: string;
/**
* Invocation status
*/
status: 'IN_PROGRESS' | 'SUCCESS' | 'EXPIRED' | 'CANCELED';
/**
* Target domain for authentication
*/
target_domain: string;
}
/**
* Response from submit endpoint matching SubmitResult schema
*/
export interface AgentAuthSubmitResponse {
/**
* Whether submission succeeded
*/
success: boolean;
/**
* Additional fields needed (e.g., OTP) - present when needs_additional_auth is
* true
*/
additional_fields?: Array<DiscoveredField>;
/**
* App name (only present when logged_in is true)
*/
app_name?: string;
/**
* Error message if submission failed
*/
error_message?: string;
/**
* Whether user is now logged in
*/
logged_in?: boolean;
/**
* Whether additional authentication fields are needed
*/
needs_additional_auth?: boolean;
/**
* Target domain (only present when logged_in is true)
*/
target_domain?: string;
}
/**
* An auth agent that manages authentication for a specific domain and profile
* combination
*/
export interface AuthAgent {
/**
* Unique identifier for the auth agent
*/
id: string;
/**
* Target domain for authentication
*/
domain: string;
/**
* Name of the profile associated with this auth agent
*/
profile_name: string;
/**
* Current authentication status of the managed profile
*/
status: 'AUTHENTICATED' | 'NEEDS_AUTH';
/**
* Whether automatic re-authentication is possible (has credential_id, selectors,
* and login_url)
*/
can_reauth?: boolean;
/**
* ID of the linked credential for automatic re-authentication
*/
credential_id?: string;
/**
* Name of the linked credential for automatic re-authentication
*/
credential_name?: string;
/**
* Whether this auth agent has stored selectors for deterministic re-authentication
*/
has_selectors?: boolean;
/**
* When the last authentication check was performed
*/
last_auth_check_at?: string;
}
/**
* Request to create or find an auth agent
*/
export interface AuthAgentCreateRequest {
/**
* Name of the profile to use for this auth agent
*/
profile_name: string;
/**
* Target domain for authentication
*/
target_domain: string;
/**
* Optional name of an existing credential to use for this auth agent. If provided,
* the credential will be linked to the agent and its values will be used to
* auto-fill the login form on invocation.
*/
credential_name?: string;
/**
* Optional login page URL. If provided, will be stored on the agent and used to
* skip discovery in future invocations.
*/
login_url?: string;
/**
* Optional proxy configuration
*/
proxy?: AuthAgentCreateRequest.Proxy;
}
export namespace AuthAgentCreateRequest {
/**
* Optional proxy configuration
*/
export interface Proxy {
/**
* ID of the proxy to use
*/
proxy_id?: string;
}
}
/**
* Request to create an invocation for an existing auth agent
*/
export interface AuthAgentInvocationCreateRequest {
/**
* ID of the auth agent to create an invocation for
*/
auth_agent_id: string;
/**
* If provided, saves the submitted credentials under this name upon successful
* login. The credential will be linked to the auth agent for automatic
* re-authentication.
*/
save_credential_as?: string;
}
/**
* Response when the agent is already authenticated.
*/
export type AuthAgentInvocationCreateResponse =
| AuthAgentInvocationCreateResponse.AuthAgentAlreadyAuthenticated
| AuthAgentInvocationCreateResponse.AuthAgentInvocationCreated;
export namespace AuthAgentInvocationCreateResponse {
/**
* Response when the agent is already authenticated.
*/
export interface AuthAgentAlreadyAuthenticated {
/**
* Indicates the agent is already authenticated and no invocation was created.
*/
status: 'already_authenticated';
}
/**
* Response when a new invocation was created.
*/
export interface AuthAgentInvocationCreated {
/**
* When the handoff code expires.
*/
expires_at: string;
/**
* One-time code for handoff.
*/
handoff_code: string;
/**
* URL to redirect user to.
*/
hosted_url: string;
/**
* Unique identifier for the invocation.
*/
invocation_id: string;
/**
* Indicates an invocation was created.
*/
status: 'invocation_created';
}
}
/**
* A discovered form field
*/
export interface DiscoveredField {
/**
* Field label
*/
label: string;
/**
* Field name
*/
name: string;
/**
* CSS selector for the field
*/
selector: string;
/**
* Field type
*/
type: 'text' | 'email' | 'password' | 'tel' | 'number' | 'url' | 'code';
/**
* Field placeholder
*/
placeholder?: string;
/**
* Whether field is required
*/
required?: boolean;
}
/**
* Response from triggering re-authentication
*/
export interface ReauthResponse {
/**
* Result of the re-authentication attempt
*/
status: 'reauth_started' | 'already_authenticated' | 'cannot_reauth';
/**
* ID of the re-auth invocation if one was created
*/
invocation_id?: string;
/**
* Human-readable description of the result
*/
message?: string;
}
export interface AuthCreateParams {
/**
* Name of the profile to use for this auth agent
*/
profile_name: string;
/**
* Target domain for authentication
*/
target_domain: string;
/**
* Optional name of an existing credential to use for this auth agent. If provided,
* the credential will be linked to the agent and its values will be used to
* auto-fill the login form on invocation.
*/
credential_name?: string;
/**
* Optional login page URL. If provided, will be stored on the agent and used to
* skip discovery in future invocations.
*/
login_url?: string;
/**
* Optional proxy configuration
*/
proxy?: AuthCreateParams.Proxy;
}
export namespace AuthCreateParams {
/**
* Optional proxy configuration
*/
export interface Proxy {
/**
* ID of the proxy to use
*/
proxy_id?: string;
}
}
export interface AuthListParams extends OffsetPaginationParams {
/**
* Filter by profile name
*/
profile_name?: string;
/**
* Filter by target domain
*/
target_domain?: string;
}
Auth.Invocations = Invocations;
export declare namespace Auth {
export {
type AgentAuthDiscoverResponse as AgentAuthDiscoverResponse,
type AgentAuthInvocationResponse as AgentAuthInvocationResponse,
type AgentAuthSubmitResponse as AgentAuthSubmitResponse,
type AuthAgent as AuthAgent,
type AuthAgentCreateRequest as AuthAgentCreateRequest,
type AuthAgentInvocationCreateRequest as AuthAgentInvocationCreateRequest,
type AuthAgentInvocationCreateResponse as AuthAgentInvocationCreateResponse,
type DiscoveredField as DiscoveredField,
type ReauthResponse as ReauthResponse,
type AuthAgentsOffsetPagination as AuthAgentsOffsetPagination,
type AuthCreateParams as AuthCreateParams,
type AuthListParams as AuthListParams,
};
export {
Invocations as Invocations,
type InvocationExchangeResponse as InvocationExchangeResponse,
type InvocationCreateParams as InvocationCreateParams,
type InvocationDiscoverParams as InvocationDiscoverParams,
type InvocationExchangeParams as InvocationExchangeParams,
type InvocationSubmitParams as InvocationSubmitParams,
};
}