cloudflare 4.4.0 → 4.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/core.ts CHANGED
@@ -171,6 +171,7 @@ export class APIPromise<T> extends Promise<T> {
171
171
  export abstract class APIClient {
172
172
  baseURL: string;
173
173
  apiVersion: string;
174
+ #baseURLOverridden: boolean;
174
175
  maxRetries: number;
175
176
  timeout: number;
176
177
  httpAgent: Agent | undefined;
@@ -181,6 +182,7 @@ export abstract class APIClient {
181
182
  constructor({
182
183
  baseURL,
183
184
  apiVersion,
185
+ baseURLOverridden,
184
186
  maxRetries = 2,
185
187
  timeout = 60000, // 1 minute
186
188
  httpAgent,
@@ -188,6 +190,7 @@ export abstract class APIClient {
188
190
  }: {
189
191
  baseURL: string;
190
192
  apiVersion: string;
193
+ baseURLOverridden: boolean;
191
194
  maxRetries?: number | undefined;
192
195
  timeout: number | undefined;
193
196
  httpAgent: Agent | undefined;
@@ -195,6 +198,7 @@ export abstract class APIClient {
195
198
  }) {
196
199
  this.baseURL = baseURL;
197
200
  this.apiVersion = apiVersion;
201
+ this.#baseURLOverridden = baseURLOverridden;
198
202
  this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
199
203
  this.timeout = validatePositiveInteger('timeout', timeout);
200
204
  this.httpAgent = httpAgent;
@@ -305,7 +309,7 @@ export abstract class APIClient {
305
309
  { retryCount = 0 }: { retryCount?: number } = {},
306
310
  ): { req: RequestInit; url: string; timeout: number } {
307
311
  const options = { ...inputOptions };
308
- const { method, path, query, headers: headers = {} } = options;
312
+ const { method, path, query, defaultBaseURL, headers: headers = {} } = options;
309
313
 
310
314
  const body =
311
315
  ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
@@ -315,7 +319,7 @@ export abstract class APIClient {
315
319
  : null;
316
320
  const contentLength = this.calculateContentLength(body);
317
321
 
318
- const url = this.buildURL(path!, query);
322
+ const url = this.buildURL(path!, query, defaultBaseURL);
319
323
  if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
320
324
  options.timeout = options.timeout ?? this.timeout;
321
325
  const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
@@ -508,11 +512,12 @@ export abstract class APIClient {
508
512
  return new PagePromise<PageClass, Item>(this, request, Page);
509
513
  }
510
514
 
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;
512
517
  const url =
513
518
  isAbsoluteURL(path) ?
514
519
  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));
516
521
 
517
522
  const defaultQuery = this.defaultQuery();
518
523
  if (!isEmptyObj(defaultQuery)) {
@@ -801,6 +806,7 @@ export type RequestOptions<
801
806
  query?: Req | undefined;
802
807
  body?: Req | null | undefined;
803
808
  headers?: Headers | undefined;
809
+ defaultBaseURL?: string | undefined;
804
810
 
805
811
  maxRetries?: number;
806
812
  stream?: boolean | undefined;
@@ -824,6 +830,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
824
830
  query: true,
825
831
  body: true,
826
832
  headers: true,
833
+ defaultBaseURL: true,
827
834
 
828
835
  maxRetries: true,
829
836
  stream: true,
package/src/index.ts CHANGED
@@ -246,6 +246,7 @@ export class Cloudflare extends Core.APIClient {
246
246
  super({
247
247
  baseURL: options.baseURL!,
248
248
  apiVersion: options.apiVersion!,
249
+ baseURLOverridden: baseURL ? baseURL !== 'https://api.cloudflare.com/client/v4' : false,
249
250
  timeout: options.timeout ?? 60000 /* 1 minute */,
250
251
  httpAgent: options.httpAgent,
251
252
  maxRetries: options.maxRetries,
@@ -356,6 +357,13 @@ export class Cloudflare extends Core.APIClient {
356
357
  pipelines: API.Pipelines = new API.Pipelines(this);
357
358
  schemaValidation: API.SchemaValidation = new API.SchemaValidation(this);
358
359
 
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
+
359
367
  protected override defaultQuery(): Core.DefaultQuery | undefined {
360
368
  return this._options.defaultQuery;
361
369
  }
@@ -91,5 +91,10 @@ export {
91
91
  type SettingEditParams,
92
92
  type SettingGetParams,
93
93
  } from './settings';
94
- export { Subscriptions } from './subscriptions';
94
+ export {
95
+ Subscriptions,
96
+ type SubscriptionCreateParams,
97
+ type SubscriptionUpdateParams,
98
+ type SubscriptionGetParams,
99
+ } from './subscriptions';
95
100
  export { Zones } from './zones';
@@ -1,5 +1,121 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  import { APIResource } from '../../resource';
4
+ import * as Core from '../../core';
5
+ import * as Shared from '../shared';
4
6
 
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
+ }
@@ -94,7 +94,12 @@ import {
94
94
  ZeroRTT,
95
95
  } from './settings';
96
96
  import * as SubscriptionsAPI from './subscriptions';
97
- import { Subscriptions } from './subscriptions';
97
+ import {
98
+ SubscriptionCreateParams,
99
+ SubscriptionGetParams,
100
+ SubscriptionUpdateParams,
101
+ Subscriptions,
102
+ } from './subscriptions';
98
103
  import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination';
99
104
 
100
105
  export class Zones extends APIResource {
@@ -745,7 +750,12 @@ export declare namespace Zones {
745
750
  type HoldGetParams as HoldGetParams,
746
751
  };
747
752
 
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
+ };
749
759
 
750
760
  export {
751
761
  Plans as Plans,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '4.4.0'; // x-release-please-version
1
+ export const VERSION = '4.4.1'; // x-release-please-version
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "4.4.0";
1
+ export declare const VERSION = "4.4.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '4.4.0'; // x-release-please-version
4
+ exports.VERSION = '4.4.1'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '4.4.0'; // x-release-please-version
1
+ export const VERSION = '4.4.1'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map