diff --git a/.stats.yml b/.stats.yml index 54ae329193..9c05255519 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 1281 +configured_endpoints: 1286 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-9a8e3aedb1193065fd84ae0b74a4a4c2d217ff2a821096f825a7798bbb921d76.yml diff --git a/api.md b/api.md index 14088f7a76..5216a7e507 100644 --- a/api.md +++ b/api.md @@ -3400,6 +3400,22 @@ Methods: - client.magicTransit.sites.wans.delete(siteId, wanId, { ...params }) -> WAN - client.magicTransit.sites.wans.get(siteId, wanId, { ...params }) -> WAN +## Connectors + +Types: + +- ConnectorUpdateResponse +- ConnectorListResponse +- ConnectorEditResponse +- ConnectorGetResponse + +Methods: + +- client.magicTransit.connectors.update(connectorId, { ...params }) -> ConnectorUpdateResponse +- client.magicTransit.connectors.list({ ...params }) -> ConnectorListResponsesSinglePage +- client.magicTransit.connectors.edit(connectorId, { ...params }) -> ConnectorEditResponse +- client.magicTransit.connectors.get(connectorId, { ...params }) -> ConnectorGetResponse + # MagicNetworkMonitoring ## Configs @@ -4536,6 +4552,7 @@ Methods: - client.zeroTrust.access.serviceTokens.update(uuid, { ...params }) -> ServiceToken - client.zeroTrust.access.serviceTokens.list({ ...params }) -> ServiceTokensSinglePage - client.zeroTrust.access.serviceTokens.delete(uuid, { ...params }) -> ServiceToken +- client.zeroTrust.access.serviceTokens.get(uuid, { ...params }) -> ServiceToken - client.zeroTrust.access.serviceTokens.refresh(identifier, uuid) -> ServiceToken - client.zeroTrust.access.serviceTokens.rotate(identifier, uuid) -> ServiceTokenRotateResponse diff --git a/src/resources/magic-transit/connectors.ts b/src/resources/magic-transit/connectors.ts new file mode 100644 index 0000000000..638027f693 --- /dev/null +++ b/src/resources/magic-transit/connectors.ts @@ -0,0 +1,280 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import * as Core from '../../core'; +import { APIResource } from '../../resource'; +import * as ConnectorsAPI from './connectors'; +import { SinglePage } from '../../pagination'; + +export class Connectors extends APIResource { + /** + * Replace Connector + */ + update( + connectorId: string, + params: ConnectorUpdateParams, + options?: Core.RequestOptions, + ): Core.APIPromise { + const { account_id, ...body } = params; + return ( + this._client.put(`/accounts/${account_id}/magic/connectors/${connectorId}`, { + body, + ...options, + }) as Core.APIPromise<{ result: ConnectorUpdateResponse }> + )._thenUnwrap((obj) => obj.result); + } + + /** + * List Connectors + */ + list( + params: ConnectorListParams, + options?: Core.RequestOptions, + ): Core.PagePromise { + const { account_id } = params; + return this._client.getAPIList( + `/accounts/${account_id}/magic/connectors`, + ConnectorListResponsesSinglePage, + options, + ); + } + + /** + * Update Connector + */ + edit( + connectorId: string, + params: ConnectorEditParams, + options?: Core.RequestOptions, + ): Core.APIPromise { + const { account_id, ...body } = params; + return ( + this._client.patch(`/accounts/${account_id}/magic/connectors/${connectorId}`, { + body, + ...options, + }) as Core.APIPromise<{ result: ConnectorEditResponse }> + )._thenUnwrap((obj) => obj.result); + } + + /** + * Fetch Connector + */ + get( + connectorId: string, + params: ConnectorGetParams, + options?: Core.RequestOptions, + ): Core.APIPromise { + const { account_id } = params; + return ( + this._client.get( + `/accounts/${account_id}/magic/connectors/${connectorId}`, + options, + ) as Core.APIPromise<{ result: ConnectorGetResponse }> + )._thenUnwrap((obj) => obj.result); + } +} + +export class ConnectorListResponsesSinglePage extends SinglePage {} + +export interface ConnectorUpdateResponse { + id: string; + + activated: boolean; + + interrupt_window_duration_hours: number; + + interrupt_window_hour_of_day: number; + + last_updated: string; + + notes: string; + + timezone: string; + + device?: ConnectorUpdateResponse.Device; + + last_heartbeat?: string; + + last_seen_version?: string; +} + +export namespace ConnectorUpdateResponse { + export interface Device { + id: string; + + serial_number?: string; + } +} + +export interface ConnectorListResponse { + id: string; + + activated: boolean; + + interrupt_window_duration_hours: number; + + interrupt_window_hour_of_day: number; + + last_updated: string; + + notes: string; + + timezone: string; + + device?: ConnectorListResponse.Device; + + last_heartbeat?: string; + + last_seen_version?: string; +} + +export namespace ConnectorListResponse { + export interface Device { + id: string; + + serial_number?: string; + } +} + +export interface ConnectorEditResponse { + id: string; + + activated: boolean; + + interrupt_window_duration_hours: number; + + interrupt_window_hour_of_day: number; + + last_updated: string; + + notes: string; + + timezone: string; + + device?: ConnectorEditResponse.Device; + + last_heartbeat?: string; + + last_seen_version?: string; +} + +export namespace ConnectorEditResponse { + export interface Device { + id: string; + + serial_number?: string; + } +} + +export interface ConnectorGetResponse { + id: string; + + activated: boolean; + + interrupt_window_duration_hours: number; + + interrupt_window_hour_of_day: number; + + last_updated: string; + + notes: string; + + timezone: string; + + device?: ConnectorGetResponse.Device; + + last_heartbeat?: string; + + last_seen_version?: string; +} + +export namespace ConnectorGetResponse { + export interface Device { + id: string; + + serial_number?: string; + } +} + +export interface ConnectorUpdateParams { + /** + * Path param: + */ + account_id: number; + + /** + * Body param: + */ + activated?: boolean; + + /** + * Body param: + */ + interrupt_window_duration_hours?: number; + + /** + * Body param: + */ + interrupt_window_hour_of_day?: number; + + /** + * Body param: + */ + notes?: string; + + /** + * Body param: + */ + timezone?: string; +} + +export interface ConnectorListParams { + account_id: number; +} + +export interface ConnectorEditParams { + /** + * Path param: + */ + account_id: number; + + /** + * Body param: + */ + activated?: boolean; + + /** + * Body param: + */ + interrupt_window_duration_hours?: number; + + /** + * Body param: + */ + interrupt_window_hour_of_day?: number; + + /** + * Body param: + */ + notes?: string; + + /** + * Body param: + */ + timezone?: string; +} + +export interface ConnectorGetParams { + account_id: number; +} + +export namespace Connectors { + export import ConnectorUpdateResponse = ConnectorsAPI.ConnectorUpdateResponse; + export import ConnectorListResponse = ConnectorsAPI.ConnectorListResponse; + export import ConnectorEditResponse = ConnectorsAPI.ConnectorEditResponse; + export import ConnectorGetResponse = ConnectorsAPI.ConnectorGetResponse; + export import ConnectorListResponsesSinglePage = ConnectorsAPI.ConnectorListResponsesSinglePage; + export import ConnectorUpdateParams = ConnectorsAPI.ConnectorUpdateParams; + export import ConnectorListParams = ConnectorsAPI.ConnectorListParams; + export import ConnectorEditParams = ConnectorsAPI.ConnectorEditParams; + export import ConnectorGetParams = ConnectorsAPI.ConnectorGetParams; +} diff --git a/src/resources/magic-transit/index.ts b/src/resources/magic-transit/index.ts index 41ebcbb761..1caa622a1e 100644 --- a/src/resources/magic-transit/index.ts +++ b/src/resources/magic-transit/index.ts @@ -9,6 +9,18 @@ export { CfInterconnectGetParams, CfInterconnects, } from './cf-interconnects'; +export { + ConnectorUpdateResponse, + ConnectorListResponse, + ConnectorEditResponse, + ConnectorGetResponse, + ConnectorUpdateParams, + ConnectorListParams, + ConnectorEditParams, + ConnectorGetParams, + ConnectorListResponsesSinglePage, + Connectors, +} from './connectors'; export { GRETunnelCreateResponse, GRETunnelUpdateResponse, diff --git a/src/resources/magic-transit/magic-transit.ts b/src/resources/magic-transit/magic-transit.ts index 3489ec3379..1d29fb2d2e 100644 --- a/src/resources/magic-transit/magic-transit.ts +++ b/src/resources/magic-transit/magic-transit.ts @@ -2,6 +2,7 @@ import { APIResource } from '../../resource'; import * as CfInterconnectsAPI from './cf-interconnects'; +import * as ConnectorsAPI from './connectors'; import * as GRETunnelsAPI from './gre-tunnels'; import * as IPSECTunnelsAPI from './ipsec-tunnels'; import * as RoutesAPI from './routes'; @@ -13,6 +14,7 @@ export class MagicTransit extends APIResource { ipsecTunnels: IPSECTunnelsAPI.IPSECTunnels = new IPSECTunnelsAPI.IPSECTunnels(this._client); routes: RoutesAPI.Routes = new RoutesAPI.Routes(this._client); sites: SitesAPI.Sites = new SitesAPI.Sites(this._client); + connectors: ConnectorsAPI.Connectors = new ConnectorsAPI.Connectors(this._client); } export interface HealthCheck { @@ -163,4 +165,14 @@ export namespace MagicTransit { export import SiteListParams = SitesAPI.SiteListParams; export import SiteDeleteParams = SitesAPI.SiteDeleteParams; export import SiteGetParams = SitesAPI.SiteGetParams; + export import Connectors = ConnectorsAPI.Connectors; + export import ConnectorUpdateResponse = ConnectorsAPI.ConnectorUpdateResponse; + export import ConnectorListResponse = ConnectorsAPI.ConnectorListResponse; + export import ConnectorEditResponse = ConnectorsAPI.ConnectorEditResponse; + export import ConnectorGetResponse = ConnectorsAPI.ConnectorGetResponse; + export import ConnectorListResponsesSinglePage = ConnectorsAPI.ConnectorListResponsesSinglePage; + export import ConnectorUpdateParams = ConnectorsAPI.ConnectorUpdateParams; + export import ConnectorListParams = ConnectorsAPI.ConnectorListParams; + export import ConnectorEditParams = ConnectorsAPI.ConnectorEditParams; + export import ConnectorGetParams = ConnectorsAPI.ConnectorGetParams; } diff --git a/src/resources/zero-trust/access/access.ts b/src/resources/zero-trust/access/access.ts index 21b968ae43..d45a705f08 100644 --- a/src/resources/zero-trust/access/access.ts +++ b/src/resources/zero-trust/access/access.ts @@ -781,6 +781,7 @@ export namespace Access { export import ServiceTokenUpdateParams = ServiceTokensAPI.ServiceTokenUpdateParams; export import ServiceTokenListParams = ServiceTokensAPI.ServiceTokenListParams; export import ServiceTokenDeleteParams = ServiceTokensAPI.ServiceTokenDeleteParams; + export import ServiceTokenGetParams = ServiceTokensAPI.ServiceTokenGetParams; export import Bookmarks = BookmarksAPI.Bookmarks; export import Bookmark = BookmarksAPI.Bookmark; export import BookmarkDeleteResponse = BookmarksAPI.BookmarkDeleteResponse; diff --git a/src/resources/zero-trust/access/index.ts b/src/resources/zero-trust/access/index.ts index a1740c63b5..c701f3e8c9 100644 --- a/src/resources/zero-trust/access/index.ts +++ b/src/resources/zero-trust/access/index.ts @@ -93,6 +93,7 @@ export { ServiceTokenUpdateParams, ServiceTokenListParams, ServiceTokenDeleteParams, + ServiceTokenGetParams, ServiceTokensSinglePage, ServiceTokens, } from './service-tokens'; diff --git a/src/resources/zero-trust/access/service-tokens.ts b/src/resources/zero-trust/access/service-tokens.ts index cd0725835e..6d1d0e7e30 100644 --- a/src/resources/zero-trust/access/service-tokens.ts +++ b/src/resources/zero-trust/access/service-tokens.ts @@ -156,6 +156,48 @@ export class ServiceTokens extends APIResource { )._thenUnwrap((obj) => obj.result); } + /** + * Fetches a single service token. + */ + get( + uuid: string, + params?: ServiceTokenGetParams, + options?: Core.RequestOptions, + ): Core.APIPromise; + get(uuid: string, options?: Core.RequestOptions): Core.APIPromise; + get( + uuid: string, + params: ServiceTokenGetParams | Core.RequestOptions = {}, + options?: Core.RequestOptions, + ): Core.APIPromise { + if (isRequestOptions(params)) { + return this.get(uuid, {}, params); + } + const { account_id, zone_id } = params; + if (!account_id && !zone_id) { + throw new CloudflareError('You must provide either account_id or zone_id.'); + } + if (account_id && zone_id) { + throw new CloudflareError('You cannot provide both account_id and zone_id.'); + } + const { accountOrZone, accountOrZoneId } = + account_id ? + { + accountOrZone: 'accounts', + accountOrZoneId: account_id, + } + : { + accountOrZone: 'zones', + accountOrZoneId: zone_id, + }; + return ( + this._client.get( + `/${accountOrZone}/${accountOrZoneId}/access/service_tokens/${uuid}`, + options, + ) as Core.APIPromise<{ result: ServiceToken }> + )._thenUnwrap((obj) => obj.result); + } + /** * Refreshes the expiration of a service token. */ @@ -362,6 +404,18 @@ export interface ServiceTokenDeleteParams { zone_id?: string; } +export interface ServiceTokenGetParams { + /** + * The Account ID to use for this endpoint. Mutually exclusive with the Zone ID. + */ + account_id?: string; + + /** + * The Zone ID to use for this endpoint. Mutually exclusive with the Account ID. + */ + zone_id?: string; +} + export namespace ServiceTokens { export import ServiceToken = ServiceTokensAPI.ServiceToken; export import ServiceTokenCreateResponse = ServiceTokensAPI.ServiceTokenCreateResponse; @@ -371,4 +425,5 @@ export namespace ServiceTokens { export import ServiceTokenUpdateParams = ServiceTokensAPI.ServiceTokenUpdateParams; export import ServiceTokenListParams = ServiceTokensAPI.ServiceTokenListParams; export import ServiceTokenDeleteParams = ServiceTokensAPI.ServiceTokenDeleteParams; + export import ServiceTokenGetParams = ServiceTokensAPI.ServiceTokenGetParams; } diff --git a/tests/api-resources/magic-transit/connectors.test.ts b/tests/api-resources/magic-transit/connectors.test.ts new file mode 100644 index 0000000000..031e0cb122 --- /dev/null +++ b/tests/api-resources/magic-transit/connectors.test.ts @@ -0,0 +1,86 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Cloudflare from 'cloudflare'; +import { Response } from 'node-fetch'; + +const cloudflare = new Cloudflare({ + apiKey: '144c9defac04969c7bfad8efaa8ea194', + apiEmail: 'user@example.com', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource connectors', () => { + test('update: only required params', async () => { + const responsePromise = cloudflare.magicTransit.connectors.update('string', { account_id: 0 }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('update: required and optional params', async () => { + const response = await cloudflare.magicTransit.connectors.update('string', { + account_id: 0, + activated: true, + interrupt_window_duration_hours: 0, + interrupt_window_hour_of_day: 0, + notes: 'string', + timezone: 'string', + }); + }); + + test('list: only required params', async () => { + const responsePromise = cloudflare.magicTransit.connectors.list({ account_id: 0 }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('list: required and optional params', async () => { + const response = await cloudflare.magicTransit.connectors.list({ account_id: 0 }); + }); + + test('edit: only required params', async () => { + const responsePromise = cloudflare.magicTransit.connectors.edit('string', { account_id: 0 }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('edit: required and optional params', async () => { + const response = await cloudflare.magicTransit.connectors.edit('string', { + account_id: 0, + activated: true, + interrupt_window_duration_hours: 0, + interrupt_window_hour_of_day: 0, + notes: 'string', + timezone: 'string', + }); + }); + + test('get: only required params', async () => { + const responsePromise = cloudflare.magicTransit.connectors.get('string', { account_id: 0 }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('get: required and optional params', async () => { + const response = await cloudflare.magicTransit.connectors.get('string', { account_id: 0 }); + }); +}); diff --git a/tests/api-resources/zero-trust/access/service-tokens.test.ts b/tests/api-resources/zero-trust/access/service-tokens.test.ts index f457976e73..cdaa6d5da8 100644 --- a/tests/api-resources/zero-trust/access/service-tokens.test.ts +++ b/tests/api-resources/zero-trust/access/service-tokens.test.ts @@ -76,6 +76,21 @@ describe('resource serviceTokens', () => { expect(dataAndResponse.response).toBe(rawResponse); }); + // TODO: investigate broken test + test.skip('get', async () => { + const responsePromise = cloudflare.zeroTrust.access.serviceTokens.get( + 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', + { account_id: 'string' }, + ); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + test('refresh', async () => { const responsePromise = cloudflare.zeroTrust.access.serviceTokens.refresh( '023e105f4ecef8ad9ca31a8372d0c353',