Skip to content

Commit f0ff0b7

Browse files
fix(api): Update zone subscription paths
1 parent f399656 commit f0ff0b7

File tree

6 files changed

+228
-6
lines changed

6 files changed

+228
-6
lines changed

.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: f3028048c6dc3559115fdd749755dee2
4+
config_hash: 8601d43fd5ccaf9e3d08f26748a5a63a

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:

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,
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Cloudflare from 'cloudflare';
4+
import { Response } from 'node-fetch';
5+
6+
const client = new Cloudflare({
7+
apiKey: '144c9defac04969c7bfad8efaa8ea194',
8+
apiEmail: '[email protected]',
9+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
10+
});
11+
12+
describe('resource subscriptions', () => {
13+
test('create: only required params', async () => {
14+
const responsePromise = client.zones.subscriptions.create({
15+
zone_id: '506e3185e9c882d175a2d0cb0093d9f2',
16+
});
17+
const rawResponse = await responsePromise.asResponse();
18+
expect(rawResponse).toBeInstanceOf(Response);
19+
const response = await responsePromise;
20+
expect(response).not.toBeInstanceOf(Response);
21+
const dataAndResponse = await responsePromise.withResponse();
22+
expect(dataAndResponse.data).toBe(response);
23+
expect(dataAndResponse.response).toBe(rawResponse);
24+
});
25+
26+
test('create: required and optional params', async () => {
27+
const response = await client.zones.subscriptions.create({
28+
zone_id: '506e3185e9c882d175a2d0cb0093d9f2',
29+
frequency: 'monthly',
30+
rate_plan: {
31+
id: 'free',
32+
currency: 'USD',
33+
externally_managed: false,
34+
is_contract: false,
35+
public_name: 'Business Plan',
36+
scope: 'zone',
37+
sets: ['string'],
38+
},
39+
});
40+
});
41+
42+
test('update: only required params', async () => {
43+
const responsePromise = client.zones.subscriptions.update({
44+
zone_id: '506e3185e9c882d175a2d0cb0093d9f2',
45+
});
46+
const rawResponse = await responsePromise.asResponse();
47+
expect(rawResponse).toBeInstanceOf(Response);
48+
const response = await responsePromise;
49+
expect(response).not.toBeInstanceOf(Response);
50+
const dataAndResponse = await responsePromise.withResponse();
51+
expect(dataAndResponse.data).toBe(response);
52+
expect(dataAndResponse.response).toBe(rawResponse);
53+
});
54+
55+
test('update: required and optional params', async () => {
56+
const response = await client.zones.subscriptions.update({
57+
zone_id: '506e3185e9c882d175a2d0cb0093d9f2',
58+
frequency: 'monthly',
59+
rate_plan: {
60+
id: 'free',
61+
currency: 'USD',
62+
externally_managed: false,
63+
is_contract: false,
64+
public_name: 'Business Plan',
65+
scope: 'zone',
66+
sets: ['string'],
67+
},
68+
});
69+
});
70+
71+
test('get: only required params', async () => {
72+
const responsePromise = client.zones.subscriptions.get({ zone_id: '506e3185e9c882d175a2d0cb0093d9f2' });
73+
const rawResponse = await responsePromise.asResponse();
74+
expect(rawResponse).toBeInstanceOf(Response);
75+
const response = await responsePromise;
76+
expect(response).not.toBeInstanceOf(Response);
77+
const dataAndResponse = await responsePromise.withResponse();
78+
expect(dataAndResponse.data).toBe(response);
79+
expect(dataAndResponse.response).toBe(rawResponse);
80+
});
81+
82+
test('get: required and optional params', async () => {
83+
const response = await client.zones.subscriptions.get({ zone_id: '506e3185e9c882d175a2d0cb0093d9f2' });
84+
});
85+
});

0 commit comments

Comments
 (0)