cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v7

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/accounts/subscriptions.ts

181lines · modecode

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