cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v5.2.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/resources/accounts/subscriptions.ts

171lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3import { APIResource } from '../../resource';
4import * as Core from '../../core';
5import * as Shared from '../shared';
6import { SubscriptionsSinglePage } from '../shared';
7
8export class Subscriptions extends APIResource {
9 /**
10 * Creates an account subscription.
11 *
12 * @example
13 * ```ts
14 * const subscription =
15 * await client.accounts.subscriptions.create({
16 * account_id: '023e105f4ecef8ad9ca31a8372d0c353',
17 * });
18 * ```
19 */
20 create(
21 params: SubscriptionCreateParams,
22 options?: Core.RequestOptions,
23 ): Core.APIPromise<Shared.Subscription> {
24 const { account_id, ...body } = params;
25 return (
26 this._client.post(`/accounts/${account_id}/subscriptions`, { body, ...options }) as Core.APIPromise<{
27 result: Shared.Subscription;
28 }>
29 )._thenUnwrap((obj) => obj.result);
30 }
31
32 /**
33 * Updates an account subscription.
34 *
35 * @example
36 * ```ts
37 * const subscription =
38 * await client.accounts.subscriptions.update(
39 * '506e3185e9c882d175a2d0cb0093d9f2',
40 * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
41 * );
42 * ```
43 */
44 update(
45 subscriptionIdentifier: string,
46 params: SubscriptionUpdateParams,
47 options?: Core.RequestOptions,
48 ): Core.APIPromise<Shared.Subscription> {
49 const { account_id, ...body } = params;
50 return (
51 this._client.put(`/accounts/${account_id}/subscriptions/${subscriptionIdentifier}`, {
52 body,
53 ...options,
54 }) as Core.APIPromise<{ result: Shared.Subscription }>
55 )._thenUnwrap((obj) => obj.result);
56 }
57
58 /**
59 * Deletes an account's subscription.
60 *
61 * @example
62 * ```ts
63 * const subscription =
64 * await client.accounts.subscriptions.delete(
65 * '506e3185e9c882d175a2d0cb0093d9f2',
66 * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
67 * );
68 * ```
69 */
70 delete(
71 subscriptionIdentifier: string,
72 params: SubscriptionDeleteParams,
73 options?: Core.RequestOptions,
74 ): Core.APIPromise<SubscriptionDeleteResponse> {
75 const { account_id } = params;
76 return (
77 this._client.delete(
78 `/accounts/${account_id}/subscriptions/${subscriptionIdentifier}`,
79 options,
80 ) as Core.APIPromise<{ result: SubscriptionDeleteResponse }>
81 )._thenUnwrap((obj) => obj.result);
82 }
83
84 /**
85 * Lists all of an account's subscriptions.
86 *
87 * @example
88 * ```ts
89 * // Automatically fetches more pages as needed.
90 * for await (const subscription of client.accounts.subscriptions.get(
91 * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
92 * )) {
93 * // ...
94 * }
95 * ```
96 */
97 get(
98 params: SubscriptionGetParams,
99 options?: Core.RequestOptions,
100 ): Core.PagePromise<SubscriptionsSinglePage, Shared.Subscription> {
101 const { account_id } = params;
102 return this._client.getAPIList(`/accounts/${account_id}/subscriptions`, SubscriptionsSinglePage, options);
103 }
104}
105
106export interface SubscriptionDeleteResponse {
107 /**
108 * Subscription identifier tag.
109 */
110 subscription_id?: string;
111}
112
113export interface SubscriptionCreateParams {
114 /**
115 * Path param: Identifier
116 */
117 account_id: string;
118
119 /**
120 * Body param: How often the subscription is renewed automatically.
121 */
122 frequency?: 'weekly' | 'monthly' | 'quarterly' | 'yearly';
123
124 /**
125 * Body param: The rate plan applied to the subscription.
126 */
127 rate_plan?: Shared.RatePlanParam;
128}
129
130export interface SubscriptionUpdateParams {
131 /**
132 * Path param: Identifier
133 */
134 account_id: string;
135
136 /**
137 * Body param: How often the subscription is renewed automatically.
138 */
139 frequency?: 'weekly' | 'monthly' | 'quarterly' | 'yearly';
140
141 /**
142 * Body param: The rate plan applied to the subscription.
143 */
144 rate_plan?: Shared.RatePlanParam;
145}
146
147export interface SubscriptionDeleteParams {
148 /**
149 * Identifier
150 */
151 account_id: string;
152}
153
154export interface SubscriptionGetParams {
155 /**
156 * Identifier
157 */
158 account_id: string;
159}
160
161export declare namespace Subscriptions {
162 export {
163 type SubscriptionDeleteResponse as SubscriptionDeleteResponse,
164 type SubscriptionCreateParams as SubscriptionCreateParams,
165 type SubscriptionUpdateParams as SubscriptionUpdateParams,
166 type SubscriptionDeleteParams as SubscriptionDeleteParams,
167 type SubscriptionGetParams as SubscriptionGetParams,
168 };
169}
170
171export { SubscriptionsSinglePage };
172