Skip to content

Commit 980edbf

Browse files
authored
Merge pull request #2649 from cloudflare/release-please--branches--main--changes--next--components--cloudflare
release: 4.4.1
2 parents 26c2dc7 + 7994b93 commit 980edbf

File tree

13 files changed

+295
-13
lines changed

13 files changed

+295
-13
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "4.4.0"
2+
".": "4.4.1"
33
}

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 1749
1+
configured_endpoints: 1752
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-b15b44e0efd207de48e7e74e742b0b4b190c74f12a941a1a0ef59a51656a5224.yml
33
openapi_spec_hash: 83243c9ee06f88d0fa91e9b185d8a42e
4-
config_hash: d0ab46f06dbe6f6e33d86a3ede15ac44
4+
config_hash: 8601d43fd5ccaf9e3d08f26748a5a63a

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 4.4.1 (2025-06-16)
4+
5+
Full Changelog: [v4.4.0...v4.4.1](https://github.com/cloudflare/cloudflare-typescript/compare/v4.4.0...v4.4.1)
6+
7+
### Features
8+
9+
* **client:** add support for endpoint-specific base URLs ([f399656](https://github.com/cloudflare/cloudflare-typescript/commit/f3996568d1d92a7f92956aa52c1e7d167e7afa59))
10+
11+
12+
### Bug Fixes
13+
14+
* **api:** Update zone subscription paths ([f0ff0b7](https://github.com/cloudflare/cloudflare-typescript/commit/f0ff0b7456757c5c176a4c51b792e44ddb823285))
15+
316
## 4.4.0 (2025-06-16)
417

518
Full Changelog: [v4.3.0...v4.4.0](https://github.com/cloudflare/cloudflare-typescript/compare/v4.3.0...v4.4.0)

api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ Methods:
392392

393393
## Subscriptions
394394

395+
Methods:
396+
397+
- <code title="post /zones/{zone_id}/subscription">client.zones.subscriptions.<a href="./src/resources/zones/subscriptions.ts">create</a>({ ...params }) -> Subscription</code>
398+
- <code title="put /zones/{zone_id}/subscription">client.zones.subscriptions.<a href="./src/resources/zones/subscriptions.ts">update</a>({ ...params }) -> Subscription</code>
399+
- <code title="get /zones/{zone_id}/subscription">client.zones.subscriptions.<a href="./src/resources/zones/subscriptions.ts">get</a>({ ...params }) -> Subscription</code>
400+
395401
## Plans
396402

397403
Types:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloudflare",
3-
"version": "4.4.0",
3+
"version": "4.4.1",
44
"description": "The official TypeScript library for the Cloudflare API",
55
"author": "Cloudflare <[email protected]>",
66
"types": "dist/index.d.ts",

src/core.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export class APIPromise<T> extends Promise<T> {
171171
export abstract class APIClient {
172172
baseURL: string;
173173
apiVersion: string;
174+
#baseURLOverridden: boolean;
174175
maxRetries: number;
175176
timeout: number;
176177
httpAgent: Agent | undefined;
@@ -181,20 +182,23 @@ export abstract class APIClient {
181182
constructor({
182183
baseURL,
183184
apiVersion,
185+
baseURLOverridden,
184186
maxRetries = 2,
185187
timeout = 60000, // 1 minute
186188
httpAgent,
187189
fetch: overriddenFetch,
188190
}: {
189191
baseURL: string;
190192
apiVersion: string;
193+
baseURLOverridden: boolean;
191194
maxRetries?: number | undefined;
192195
timeout: number | undefined;
193196
httpAgent: Agent | undefined;
194197
fetch: Fetch | undefined;
195198
}) {
196199
this.baseURL = baseURL;
197200
this.apiVersion = apiVersion;
201+
this.#baseURLOverridden = baseURLOverridden;
198202
this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
199203
this.timeout = validatePositiveInteger('timeout', timeout);
200204
this.httpAgent = httpAgent;
@@ -305,7 +309,7 @@ export abstract class APIClient {
305309
{ retryCount = 0 }: { retryCount?: number } = {},
306310
): { req: RequestInit; url: string; timeout: number } {
307311
const options = { ...inputOptions };
308-
const { method, path, query, headers: headers = {} } = options;
312+
const { method, path, query, defaultBaseURL, headers: headers = {} } = options;
309313

310314
const body =
311315
ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
@@ -315,7 +319,7 @@ export abstract class APIClient {
315319
: null;
316320
const contentLength = this.calculateContentLength(body);
317321

318-
const url = this.buildURL(path!, query);
322+
const url = this.buildURL(path!, query, defaultBaseURL);
319323
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
320324
options.timeout = options.timeout ?? this.timeout;
321325
const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
@@ -508,11 +512,12 @@ export abstract class APIClient {
508512
return new PagePromise<PageClass, Item>(this, request, Page);
509513
}
510514

511-
buildURL<Req>(path: string, query: Req | null | undefined): string {
515+
buildURL<Req>(path: string, query: Req | null | undefined, defaultBaseURL?: string | undefined): string {
516+
const baseURL = (!this.#baseURLOverridden && defaultBaseURL) || this.baseURL;
512517
const url =
513518
isAbsoluteURL(path) ?
514519
new URL(path)
515-
: new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
520+
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
516521

517522
const defaultQuery = this.defaultQuery();
518523
if (!isEmptyObj(defaultQuery)) {
@@ -801,6 +806,7 @@ export type RequestOptions<
801806
query?: Req | undefined;
802807
body?: Req | null | undefined;
803808
headers?: Headers | undefined;
809+
defaultBaseURL?: string | undefined;
804810

805811
maxRetries?: number;
806812
stream?: boolean | undefined;
@@ -824,6 +830,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
824830
query: true,
825831
body: true,
826832
headers: true,
833+
defaultBaseURL: true,
827834

828835
maxRetries: true,
829836
stream: true,

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ export class Cloudflare extends Core.APIClient {
246246
super({
247247
baseURL: options.baseURL!,
248248
apiVersion: options.apiVersion!,
249+
baseURLOverridden: baseURL ? baseURL !== 'https://api.cloudflare.com/client/v4' : false,
249250
timeout: options.timeout ?? 60000 /* 1 minute */,
250251
httpAgent: options.httpAgent,
251252
maxRetries: options.maxRetries,
@@ -356,6 +357,13 @@ export class Cloudflare extends Core.APIClient {
356357
pipelines: API.Pipelines = new API.Pipelines(this);
357358
schemaValidation: API.SchemaValidation = new API.SchemaValidation(this);
358359

360+
/**
361+
* Check whether the base URL is set to its default.
362+
*/
363+
#baseURLOverridden(): boolean {
364+
return this.baseURL !== 'https://api.cloudflare.com/client/v4';
365+
}
366+
359367
protected override defaultQuery(): Core.DefaultQuery | undefined {
360368
return this._options.defaultQuery;
361369
}

src/resources/zones/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,10 @@ export {
9191
type SettingEditParams,
9292
type SettingGetParams,
9393
} from './settings';
94-
export { Subscriptions } from './subscriptions';
94+
export {
95+
Subscriptions,
96+
type SubscriptionCreateParams,
97+
type SubscriptionUpdateParams,
98+
type SubscriptionGetParams,
99+
} from './subscriptions';
95100
export { Zones } from './zones';

src/resources/zones/subscriptions.ts

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,121 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
import { APIResource } from '../../resource';
4+
import * as Core from '../../core';
5+
import * as Shared from '../shared';
46

5-
export class Subscriptions extends APIResource {}
7+
export class Subscriptions extends APIResource {
8+
/**
9+
* Create a zone subscription, either plan or add-ons.
10+
*
11+
* @example
12+
* ```ts
13+
* const subscription =
14+
* await client.zones.subscriptions.create({
15+
* zone_id: '506e3185e9c882d175a2d0cb0093d9f2',
16+
* });
17+
* ```
18+
*/
19+
create(
20+
params: SubscriptionCreateParams,
21+
options?: Core.RequestOptions,
22+
): Core.APIPromise<Shared.Subscription> {
23+
const { zone_id, ...body } = params;
24+
return (
25+
this._client.post(`/zones/${zone_id}/subscription`, { body, ...options }) as Core.APIPromise<{
26+
result: Shared.Subscription;
27+
}>
28+
)._thenUnwrap((obj) => obj.result);
29+
}
30+
31+
/**
32+
* Updates zone subscriptions, either plan or add-ons.
33+
*
34+
* @example
35+
* ```ts
36+
* const subscription =
37+
* await client.zones.subscriptions.update({
38+
* zone_id: '506e3185e9c882d175a2d0cb0093d9f2',
39+
* });
40+
* ```
41+
*/
42+
update(
43+
params: SubscriptionUpdateParams,
44+
options?: Core.RequestOptions,
45+
): Core.APIPromise<Shared.Subscription> {
46+
const { zone_id, ...body } = params;
47+
return (
48+
this._client.put(`/zones/${zone_id}/subscription`, { body, ...options }) as Core.APIPromise<{
49+
result: Shared.Subscription;
50+
}>
51+
)._thenUnwrap((obj) => obj.result);
52+
}
53+
54+
/**
55+
* Lists zone subscription details.
56+
*
57+
* @example
58+
* ```ts
59+
* const subscription = await client.zones.subscriptions.get({
60+
* zone_id: '506e3185e9c882d175a2d0cb0093d9f2',
61+
* });
62+
* ```
63+
*/
64+
get(params: SubscriptionGetParams, options?: Core.RequestOptions): Core.APIPromise<Shared.Subscription> {
65+
const { zone_id } = params;
66+
return (
67+
this._client.get(`/zones/${zone_id}/subscription`, options) as Core.APIPromise<{
68+
result: Shared.Subscription;
69+
}>
70+
)._thenUnwrap((obj) => obj.result);
71+
}
72+
}
73+
74+
export interface SubscriptionCreateParams {
75+
/**
76+
* Path param: Subscription identifier tag.
77+
*/
78+
zone_id: string;
79+
80+
/**
81+
* Body param: How often the subscription is renewed automatically.
82+
*/
83+
frequency?: 'weekly' | 'monthly' | 'quarterly' | 'yearly';
84+
85+
/**
86+
* Body param: The rate plan applied to the subscription.
87+
*/
88+
rate_plan?: Shared.RatePlanParam;
89+
}
90+
91+
export interface SubscriptionUpdateParams {
92+
/**
93+
* Path param: Subscription identifier tag.
94+
*/
95+
zone_id: string;
96+
97+
/**
98+
* Body param: How often the subscription is renewed automatically.
99+
*/
100+
frequency?: 'weekly' | 'monthly' | 'quarterly' | 'yearly';
101+
102+
/**
103+
* Body param: The rate plan applied to the subscription.
104+
*/
105+
rate_plan?: Shared.RatePlanParam;
106+
}
107+
108+
export interface SubscriptionGetParams {
109+
/**
110+
* Subscription identifier tag.
111+
*/
112+
zone_id: string;
113+
}
114+
115+
export declare namespace Subscriptions {
116+
export {
117+
type SubscriptionCreateParams as SubscriptionCreateParams,
118+
type SubscriptionUpdateParams as SubscriptionUpdateParams,
119+
type SubscriptionGetParams as SubscriptionGetParams,
120+
};
121+
}

src/resources/zones/zones.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ import {
9494
ZeroRTT,
9595
} from './settings';
9696
import * as SubscriptionsAPI from './subscriptions';
97-
import { Subscriptions } from './subscriptions';
97+
import {
98+
SubscriptionCreateParams,
99+
SubscriptionGetParams,
100+
SubscriptionUpdateParams,
101+
Subscriptions,
102+
} from './subscriptions';
98103
import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination';
99104

100105
export class Zones extends APIResource {
@@ -745,7 +750,12 @@ export declare namespace Zones {
745750
type HoldGetParams as HoldGetParams,
746751
};
747752

748-
export { Subscriptions as Subscriptions };
753+
export {
754+
Subscriptions as Subscriptions,
755+
type SubscriptionCreateParams as SubscriptionCreateParams,
756+
type SubscriptionUpdateParams as SubscriptionUpdateParams,
757+
type SubscriptionGetParams as SubscriptionGetParams,
758+
};
749759

750760
export {
751761
Plans as Plans,

0 commit comments

Comments
 (0)