Skip to content

Commit 1520c55

Browse files
feat: api: paginate GET /proxies
1 parent 74a0327 commit 1520c55

6 files changed

Lines changed: 138 additions & 118 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 117
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-33e46e6a0095c2ec39a51860ee4e133c5a21a80a90cbe9e52953c07e5e0295de.yml
3-
openapi_spec_hash: 4aa466b9af39768b65a44b68ae0d1f6e
4-
config_hash: ede72e4ae65cc5a6d6927938b3455c46
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-f3e52a8a9d9e37f8b527bdcce63b39cf8807d138cf3570c9954ba7f42ef02375.yml
3+
openapi_spec_hash: 2b787691eba1bb7bafb553528c09d5c0
4+
config_hash: e12afec516ced9520590c7a05af7a6f7

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Methods:
283283

284284
- <code title="post /proxies">client.proxies.<a href="./src/resources/proxies.ts">create</a>({ ...params }) -> ProxyCreateResponse</code>
285285
- <code title="get /proxies/{id}">client.proxies.<a href="./src/resources/proxies.ts">retrieve</a>(id) -> ProxyRetrieveResponse</code>
286-
- <code title="get /proxies">client.proxies.<a href="./src/resources/proxies.ts">list</a>() -> ProxyListResponse</code>
286+
- <code title="get /proxies">client.proxies.<a href="./src/resources/proxies.ts">list</a>({ ...params }) -> ProxyListResponsesOffsetPagination</code>
287287
- <code title="delete /proxies/{id}">client.proxies.<a href="./src/resources/proxies.ts">delete</a>(id) -> void</code>
288288
- <code title="post /proxies/{id}/check">client.proxies.<a href="./src/resources/proxies.ts">check</a>(id, { ...params }) -> ProxyCheckResponse</code>
289289

src/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ import {
110110
ProxyCheckResponse,
111111
ProxyCreateParams,
112112
ProxyCreateResponse,
113+
ProxyListParams,
113114
ProxyListResponse,
115+
ProxyListResponsesOffsetPagination,
114116
ProxyRetrieveResponse,
115117
} from './resources/proxies';
116118
import { Auth } from './resources/auth/auth';
@@ -1081,7 +1083,9 @@ export declare namespace Kernel {
10811083
type ProxyRetrieveResponse as ProxyRetrieveResponse,
10821084
type ProxyListResponse as ProxyListResponse,
10831085
type ProxyCheckResponse as ProxyCheckResponse,
1086+
type ProxyListResponsesOffsetPagination as ProxyListResponsesOffsetPagination,
10841087
type ProxyCreateParams as ProxyCreateParams,
1088+
type ProxyListParams as ProxyListParams,
10851089
type ProxyCheckParams as ProxyCheckParams,
10861090
};
10871091

src/resources/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,7 @@ export {
122122
type ProxyListResponse,
123123
type ProxyCheckResponse,
124124
type ProxyCreateParams,
125+
type ProxyListParams,
125126
type ProxyCheckParams,
127+
type ProxyListResponsesOffsetPagination,
126128
} from './proxies';

src/resources/proxies.ts

Lines changed: 120 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { APIResource } from '../core/resource';
44
import { APIPromise } from '../core/api-promise';
5+
import { OffsetPagination, type OffsetPaginationParams, PagePromise } from '../core/pagination';
56
import { buildHeaders } from '../internal/headers';
67
import { RequestOptions } from '../internal/request-options';
78
import { path } from '../internal/utils/path';
@@ -27,8 +28,11 @@ export class Proxies extends APIResource {
2728
/**
2829
* List proxies owned by the caller's organization.
2930
*/
30-
list(options?: RequestOptions): APIPromise<ProxyListResponse> {
31-
return this._client.get('/proxies', options);
31+
list(
32+
query: ProxyListParams | null | undefined = {},
33+
options?: RequestOptions,
34+
): PagePromise<ProxyListResponsesOffsetPagination, ProxyListResponse> {
35+
return this._client.getAPIList('/proxies', OffsetPagination<ProxyListResponse>, { query, ...options });
3236
}
3337

3438
/**
@@ -58,6 +62,8 @@ export class Proxies extends APIResource {
5862
}
5963
}
6064

65+
export type ProxyListResponsesOffsetPagination = OffsetPagination<ProxyListResponse>;
66+
6167
/**
6268
* Configuration for routing traffic through a proxy.
6369
*/
@@ -370,163 +376,159 @@ export namespace ProxyRetrieveResponse {
370376
}
371377
}
372378

373-
export type ProxyListResponse = Array<ProxyListResponse.ProxyListResponseItem>;
379+
/**
380+
* Configuration for routing traffic through a proxy.
381+
*/
382+
export interface ProxyListResponse {
383+
/**
384+
* Proxy type to use. In terms of quality for avoiding bot-detection, from best to
385+
* worst: `mobile` > `residential` > `isp` > `datacenter`.
386+
*/
387+
type: 'datacenter' | 'isp' | 'residential' | 'mobile' | 'custom';
388+
389+
id?: string;
390+
391+
/**
392+
* Hostnames that should bypass the parent proxy and connect directly.
393+
*/
394+
bypass_hosts?: Array<string>;
395+
396+
/**
397+
* Configuration specific to the selected proxy `type`.
398+
*/
399+
config?:
400+
| ProxyListResponse.DatacenterProxyConfig
401+
| ProxyListResponse.IspProxyConfig
402+
| ProxyListResponse.ResidentialProxyConfig
403+
| ProxyListResponse.MobileProxyConfig
404+
| ProxyListResponse.CustomProxyConfig;
405+
406+
/**
407+
* IP address that the proxy uses when making requests.
408+
*/
409+
ip_address?: string;
410+
411+
/**
412+
* Timestamp of the last health check performed on this proxy.
413+
*/
414+
last_checked?: string;
415+
416+
/**
417+
* Readable name of the proxy.
418+
*/
419+
name?: string;
420+
421+
/**
422+
* Protocol to use for the proxy connection.
423+
*/
424+
protocol?: 'http' | 'https';
425+
426+
/**
427+
* Current health status of the proxy.
428+
*/
429+
status?: 'available' | 'unavailable';
430+
}
374431

375432
export namespace ProxyListResponse {
376433
/**
377-
* Configuration for routing traffic through a proxy.
434+
* Configuration for a datacenter proxy.
378435
*/
379-
export interface ProxyListResponseItem {
436+
export interface DatacenterProxyConfig {
380437
/**
381-
* Proxy type to use. In terms of quality for avoiding bot-detection, from best to
382-
* worst: `mobile` > `residential` > `isp` > `datacenter`.
438+
* ISO 3166 country code. Defaults to US if not provided.
383439
*/
384-
type: 'datacenter' | 'isp' | 'residential' | 'mobile' | 'custom';
385-
386-
id?: string;
440+
country?: string;
441+
}
387442

443+
/**
444+
* Configuration for an ISP proxy.
445+
*/
446+
export interface IspProxyConfig {
388447
/**
389-
* Hostnames that should bypass the parent proxy and connect directly.
448+
* ISO 3166 country code. Defaults to US if not provided.
390449
*/
391-
bypass_hosts?: Array<string>;
450+
country?: string;
451+
}
392452

453+
/**
454+
* Configuration for residential proxies.
455+
*/
456+
export interface ResidentialProxyConfig {
393457
/**
394-
* Configuration specific to the selected proxy `type`.
458+
* Autonomous system number. See https://bgp.potaroo.net/cidr/autnums.html
395459
*/
396-
config?:
397-
| ProxyListResponseItem.DatacenterProxyConfig
398-
| ProxyListResponseItem.IspProxyConfig
399-
| ProxyListResponseItem.ResidentialProxyConfig
400-
| ProxyListResponseItem.MobileProxyConfig
401-
| ProxyListResponseItem.CustomProxyConfig;
460+
asn?: string;
402461

403462
/**
404-
* IP address that the proxy uses when making requests.
463+
* City name (no spaces, e.g. `sanfrancisco`). If provided, `country` must also be
464+
* provided.
405465
*/
406-
ip_address?: string;
466+
city?: string;
407467

408468
/**
409-
* Timestamp of the last health check performed on this proxy.
469+
* ISO 3166 country code.
410470
*/
411-
last_checked?: string;
471+
country?: string;
412472

413473
/**
414-
* Readable name of the proxy.
474+
* @deprecated Operating system of the residential device.
415475
*/
416-
name?: string;
476+
os?: 'windows' | 'macos' | 'android';
417477

418478
/**
419-
* Protocol to use for the proxy connection.
479+
* Two-letter state code.
420480
*/
421-
protocol?: 'http' | 'https';
481+
state?: string;
422482

423483
/**
424-
* Current health status of the proxy.
484+
* US ZIP code.
425485
*/
426-
status?: 'available' | 'unavailable';
486+
zip?: string;
427487
}
428488

429-
export namespace ProxyListResponseItem {
489+
/**
490+
* Configuration for mobile proxies.
491+
*/
492+
export interface MobileProxyConfig {
430493
/**
431-
* Configuration for a datacenter proxy.
494+
* Provider city alias. Mobile carrier routing can make observed geo vary.
432495
*/
433-
export interface DatacenterProxyConfig {
434-
/**
435-
* ISO 3166 country code. Defaults to US if not provided.
436-
*/
437-
country?: string;
438-
}
496+
city?: string;
439497

440498
/**
441-
* Configuration for an ISP proxy.
499+
* ISO 3166 country code
442500
*/
443-
export interface IspProxyConfig {
444-
/**
445-
* ISO 3166 country code. Defaults to US if not provided.
446-
*/
447-
country?: string;
448-
}
501+
country?: string;
449502

450503
/**
451-
* Configuration for residential proxies.
504+
* US-only state code. Mobile carrier routing can make observed geo vary.
452505
*/
453-
export interface ResidentialProxyConfig {
454-
/**
455-
* Autonomous system number. See https://bgp.potaroo.net/cidr/autnums.html
456-
*/
457-
asn?: string;
458-
459-
/**
460-
* City name (no spaces, e.g. `sanfrancisco`). If provided, `country` must also be
461-
* provided.
462-
*/
463-
city?: string;
464-
465-
/**
466-
* ISO 3166 country code.
467-
*/
468-
country?: string;
469-
470-
/**
471-
* @deprecated Operating system of the residential device.
472-
*/
473-
os?: 'windows' | 'macos' | 'android';
474-
475-
/**
476-
* Two-letter state code.
477-
*/
478-
state?: string;
479-
480-
/**
481-
* US ZIP code.
482-
*/
483-
zip?: string;
484-
}
506+
state?: string;
507+
}
485508

509+
/**
510+
* Configuration for a custom proxy (e.g., private proxy server).
511+
*/
512+
export interface CustomProxyConfig {
486513
/**
487-
* Configuration for mobile proxies.
514+
* Proxy host address or IP.
488515
*/
489-
export interface MobileProxyConfig {
490-
/**
491-
* Provider city alias. Mobile carrier routing can make observed geo vary.
492-
*/
493-
city?: string;
494-
495-
/**
496-
* ISO 3166 country code
497-
*/
498-
country?: string;
499-
500-
/**
501-
* US-only state code. Mobile carrier routing can make observed geo vary.
502-
*/
503-
state?: string;
504-
}
516+
host: string;
505517

506518
/**
507-
* Configuration for a custom proxy (e.g., private proxy server).
519+
* Proxy port.
508520
*/
509-
export interface CustomProxyConfig {
510-
/**
511-
* Proxy host address or IP.
512-
*/
513-
host: string;
514-
515-
/**
516-
* Proxy port.
517-
*/
518-
port: number;
521+
port: number;
519522

520-
/**
521-
* Whether the proxy has a password.
522-
*/
523-
has_password?: boolean;
523+
/**
524+
* Whether the proxy has a password.
525+
*/
526+
has_password?: boolean;
524527

525-
/**
526-
* Username for proxy authentication.
527-
*/
528-
username?: string;
529-
}
528+
/**
529+
* Username for proxy authentication.
530+
*/
531+
username?: string;
530532
}
531533
}
532534

@@ -822,6 +824,8 @@ export namespace ProxyCreateParams {
822824
}
823825
}
824826

827+
export interface ProxyListParams extends OffsetPaginationParams {}
828+
825829
export interface ProxyCheckParams {
826830
/**
827831
* An optional URL to test reachability against. If provided, the proxy check will
@@ -846,7 +850,9 @@ export declare namespace Proxies {
846850
type ProxyRetrieveResponse as ProxyRetrieveResponse,
847851
type ProxyListResponse as ProxyListResponse,
848852
type ProxyCheckResponse as ProxyCheckResponse,
853+
type ProxyListResponsesOffsetPagination as ProxyListResponsesOffsetPagination,
849854
type ProxyCreateParams as ProxyCreateParams,
855+
type ProxyListParams as ProxyListParams,
850856
type ProxyCheckParams as ProxyCheckParams,
851857
};
852858
}

tests/api-resources/proxies.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ describe('resource proxies', () => {
5555
expect(dataAndResponse.response).toBe(rawResponse);
5656
});
5757

58+
// Mock server tests are disabled
59+
test.skip('list: request options and params are passed correctly', async () => {
60+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
61+
await expect(
62+
client.proxies.list({ limit: 1, offset: 0 }, { path: '/_stainless_unknown_path' }),
63+
).rejects.toThrow(Kernel.NotFoundError);
64+
});
65+
5866
// Mock server tests are disabled
5967
test.skip('delete', async () => {
6068
const responsePromise = client.proxies.delete('id');

0 commit comments

Comments
 (0)