Skip to content

Commit 999dfe5

Browse files
feat(api): add health check endpoint for proxies
1 parent 8380eb6 commit 999dfe5

File tree

6 files changed

+249
-4
lines changed

6 files changed

+249
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 89
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-2cf104c4b88159c6a50713b019188f83983748b9cacec598089cf9068dc5b1cd.yml
3-
openapi_spec_hash: 84ea30ae65ad7ebcc04d2f3907d1e73b
4-
config_hash: 179f33af31ece83563163d5b3d751d13
1+
configured_endpoints: 90
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-20fac779e9e13dc9421e467be31dbf274c39072ba0c01528ba451b48698d43c1.yml
3+
openapi_spec_hash: c3fc5784297ccc8f729326b62000d1f0
4+
config_hash: e47e015528251ee83e30367dbbb51044

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,15 @@ Types:
201201
- <code><a href="./src/resources/proxies.ts">ProxyCreateResponse</a></code>
202202
- <code><a href="./src/resources/proxies.ts">ProxyRetrieveResponse</a></code>
203203
- <code><a href="./src/resources/proxies.ts">ProxyListResponse</a></code>
204+
- <code><a href="./src/resources/proxies.ts">ProxyCheckResponse</a></code>
204205

205206
Methods:
206207

207208
- <code title="post /proxies">client.proxies.<a href="./src/resources/proxies.ts">create</a>({ ...params }) -> ProxyCreateResponse</code>
208209
- <code title="get /proxies/{id}">client.proxies.<a href="./src/resources/proxies.ts">retrieve</a>(id) -> ProxyRetrieveResponse</code>
209210
- <code title="get /proxies">client.proxies.<a href="./src/resources/proxies.ts">list</a>() -> ProxyListResponse</code>
210211
- <code title="delete /proxies/{id}">client.proxies.<a href="./src/resources/proxies.ts">delete</a>(id) -> void</code>
212+
- <code title="post /proxies/{id}/check">client.proxies.<a href="./src/resources/proxies.ts">check</a>(id) -> ProxyCheckResponse</code>
211213

212214
# Extensions
213215

src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {
7777
import { ProfileCreateParams, ProfileListResponse, Profiles } from './resources/profiles';
7878
import {
7979
Proxies,
80+
ProxyCheckResponse,
8081
ProxyCreateParams,
8182
ProxyCreateResponse,
8283
ProxyListResponse,
@@ -950,6 +951,7 @@ export declare namespace Kernel {
950951
type ProxyCreateResponse as ProxyCreateResponse,
951952
type ProxyRetrieveResponse as ProxyRetrieveResponse,
952953
type ProxyListResponse as ProxyListResponse,
954+
type ProxyCheckResponse as ProxyCheckResponse,
953955
type ProxyCreateParams as ProxyCreateParams,
954956
};
955957

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,6 @@ export {
8181
type ProxyCreateResponse,
8282
type ProxyRetrieveResponse,
8383
type ProxyListResponse,
84+
type ProxyCheckResponse,
8485
type ProxyCreateParams,
8586
} from './proxies';

src/resources/proxies.ts

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export class Proxies extends APIResource {
3737
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
3838
});
3939
}
40+
41+
/**
42+
* Run a health check on the proxy to verify it's working.
43+
*/
44+
check(id: string, options?: RequestOptions): APIPromise<ProxyCheckResponse> {
45+
return this._client.post(path`/proxies/${id}/check`, options);
46+
}
4047
}
4148

4249
/**
@@ -703,6 +710,226 @@ export namespace ProxyListResponse {
703710
}
704711
}
705712

713+
/**
714+
* Configuration for routing traffic through a proxy.
715+
*/
716+
export interface ProxyCheckResponse {
717+
/**
718+
* Proxy type to use. In terms of quality for avoiding bot-detection, from best to
719+
* worst: `mobile` > `residential` > `isp` > `datacenter`.
720+
*/
721+
type: 'datacenter' | 'isp' | 'residential' | 'mobile' | 'custom';
722+
723+
id?: string;
724+
725+
/**
726+
* Configuration specific to the selected proxy `type`.
727+
*/
728+
config?:
729+
| ProxyCheckResponse.DatacenterProxyConfig
730+
| ProxyCheckResponse.IspProxyConfig
731+
| ProxyCheckResponse.ResidentialProxyConfig
732+
| ProxyCheckResponse.MobileProxyConfig
733+
| ProxyCheckResponse.CustomProxyConfig;
734+
735+
/**
736+
* Timestamp of the last health check performed on this proxy.
737+
*/
738+
last_checked?: string;
739+
740+
/**
741+
* Readable name of the proxy.
742+
*/
743+
name?: string;
744+
745+
/**
746+
* Protocol to use for the proxy connection.
747+
*/
748+
protocol?: 'http' | 'https';
749+
750+
/**
751+
* Current health status of the proxy.
752+
*/
753+
status?: 'available' | 'unavailable';
754+
}
755+
756+
export namespace ProxyCheckResponse {
757+
/**
758+
* Configuration for a datacenter proxy.
759+
*/
760+
export interface DatacenterProxyConfig {
761+
/**
762+
* ISO 3166 country code. Defaults to US if not provided.
763+
*/
764+
country?: string;
765+
}
766+
767+
/**
768+
* Configuration for an ISP proxy.
769+
*/
770+
export interface IspProxyConfig {
771+
/**
772+
* ISO 3166 country code. Defaults to US if not provided.
773+
*/
774+
country?: string;
775+
}
776+
777+
/**
778+
* Configuration for residential proxies.
779+
*/
780+
export interface ResidentialProxyConfig {
781+
/**
782+
* Autonomous system number. See https://bgp.potaroo.net/cidr/autnums.html
783+
*/
784+
asn?: string;
785+
786+
/**
787+
* City name (no spaces, e.g. `sanfrancisco`). If provided, `country` must also be
788+
* provided.
789+
*/
790+
city?: string;
791+
792+
/**
793+
* ISO 3166 country code.
794+
*/
795+
country?: string;
796+
797+
/**
798+
* @deprecated Operating system of the residential device.
799+
*/
800+
os?: 'windows' | 'macos' | 'android';
801+
802+
/**
803+
* Two-letter state code.
804+
*/
805+
state?: string;
806+
807+
/**
808+
* US ZIP code.
809+
*/
810+
zip?: string;
811+
}
812+
813+
/**
814+
* Configuration for mobile proxies.
815+
*/
816+
export interface MobileProxyConfig {
817+
/**
818+
* Autonomous system number. See https://bgp.potaroo.net/cidr/autnums.html
819+
*/
820+
asn?: string;
821+
822+
/**
823+
* Mobile carrier.
824+
*/
825+
carrier?:
826+
| 'a1'
827+
| 'aircel'
828+
| 'airtel'
829+
| 'att'
830+
| 'celcom'
831+
| 'chinamobile'
832+
| 'claro'
833+
| 'comcast'
834+
| 'cox'
835+
| 'digi'
836+
| 'dt'
837+
| 'docomo'
838+
| 'dtac'
839+
| 'etisalat'
840+
| 'idea'
841+
| 'kyivstar'
842+
| 'meo'
843+
| 'megafon'
844+
| 'mtn'
845+
| 'mtnza'
846+
| 'mts'
847+
| 'optus'
848+
| 'orange'
849+
| 'qwest'
850+
| 'reliance_jio'
851+
| 'robi'
852+
| 'sprint'
853+
| 'telefonica'
854+
| 'telstra'
855+
| 'tmobile'
856+
| 'tigo'
857+
| 'tim'
858+
| 'verizon'
859+
| 'vimpelcom'
860+
| 'vodacomza'
861+
| 'vodafone'
862+
| 'vivo'
863+
| 'zain'
864+
| 'vivabo'
865+
| 'telenormyanmar'
866+
| 'kcelljsc'
867+
| 'swisscom'
868+
| 'singtel'
869+
| 'asiacell'
870+
| 'windit'
871+
| 'cellc'
872+
| 'ooredoo'
873+
| 'drei'
874+
| 'umobile'
875+
| 'cableone'
876+
| 'proximus'
877+
| 'tele2'
878+
| 'mobitel'
879+
| 'o2'
880+
| 'bouygues'
881+
| 'free'
882+
| 'sfr'
883+
| 'digicel';
884+
885+
/**
886+
* City name (no spaces, e.g. `sanfrancisco`). If provided, `country` must also be
887+
* provided.
888+
*/
889+
city?: string;
890+
891+
/**
892+
* ISO 3166 country code
893+
*/
894+
country?: string;
895+
896+
/**
897+
* Two-letter state code.
898+
*/
899+
state?: string;
900+
901+
/**
902+
* US ZIP code.
903+
*/
904+
zip?: string;
905+
}
906+
907+
/**
908+
* Configuration for a custom proxy (e.g., private proxy server).
909+
*/
910+
export interface CustomProxyConfig {
911+
/**
912+
* Proxy host address or IP.
913+
*/
914+
host: string;
915+
916+
/**
917+
* Proxy port.
918+
*/
919+
port: number;
920+
921+
/**
922+
* Whether the proxy has a password.
923+
*/
924+
has_password?: boolean;
925+
926+
/**
927+
* Username for proxy authentication.
928+
*/
929+
username?: string;
930+
}
931+
}
932+
706933
export interface ProxyCreateParams {
707934
/**
708935
* Proxy type to use. In terms of quality for avoiding bot-detection, from best to
@@ -913,6 +1140,7 @@ export declare namespace Proxies {
9131140
type ProxyCreateResponse as ProxyCreateResponse,
9141141
type ProxyRetrieveResponse as ProxyRetrieveResponse,
9151142
type ProxyListResponse as ProxyListResponse,
1143+
type ProxyCheckResponse as ProxyCheckResponse,
9161144
type ProxyCreateParams as ProxyCreateParams,
9171145
};
9181146
}

tests/api-resources/proxies.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,16 @@ describe('resource proxies', () => {
6565
expect(dataAndResponse.data).toBe(response);
6666
expect(dataAndResponse.response).toBe(rawResponse);
6767
});
68+
69+
// Prism tests are disabled
70+
test.skip('check', async () => {
71+
const responsePromise = client.proxies.check('id');
72+
const rawResponse = await responsePromise.asResponse();
73+
expect(rawResponse).toBeInstanceOf(Response);
74+
const response = await responsePromise;
75+
expect(response).not.toBeInstanceOf(Response);
76+
const dataAndResponse = await responsePromise.withResponse();
77+
expect(dataAndResponse.data).toBe(response);
78+
expect(dataAndResponse.response).toBe(rawResponse);
79+
});
6880
});

0 commit comments

Comments
 (0)