cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f2248f5a5a91b8b2a6f36f2ce9cf7eb438ed5e67

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/accounts/subscriptions.ts

177lines · 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<SubscriptionCreateResponse> {
24 const { account_id, ...body } = params;
25 return (
26 this._client.post(`/accounts/${account_id}/subscriptions`, { body, ...options }) as Core.APIPromise<{
27 result: SubscriptionCreateResponse;
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<SubscriptionUpdateResponse> {
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: SubscriptionUpdateResponse }>
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 type SubscriptionCreateResponse = unknown | string | null;
107
108export type SubscriptionUpdateResponse = unknown | string | null;
109
110export interface SubscriptionDeleteResponse {
111 /**
112 * Subscription identifier tag.
113 */
114 subscription_id?: string;
115}
116
117export interface SubscriptionCreateParams {
118 /**
119 * Path param: Identifier
120 */
121 account_id: string;
122
123 /**
124 * Body param: How often the subscription is renewed automatically.
125 */
126 frequency?: 'weekly' | 'monthly' | 'quarterly' | 'yearly';
127
128 /**
129 * Body param: The rate plan applied to the subscription.
130 */
131 rate_plan?: Shared.RatePlanParam;
132}
133
134export interface SubscriptionUpdateParams {
135 /**
136 * Path param: Identifier
137 */
138 account_id: string;
139
140 /**
141 * Body param: How often the subscription is renewed automatically.
142 */
143 frequency?: 'weekly' | 'monthly' | 'quarterly' | 'yearly';
144
145 /**
146 * Body param: The rate plan applied to the subscription.
147 */
148 rate_plan?: Shared.RatePlanParam;
149}
150
151export interface SubscriptionDeleteParams {
152 /**
153 * Identifier
154 */
155 account_id: string;
156}
157
158export interface SubscriptionGetParams {
159 /**
160 * Identifier
161 */
162 account_id: string;
163}
164
165export declare namespace Subscriptions {
166 export {
167 type SubscriptionCreateResponse as SubscriptionCreateResponse,
168 type SubscriptionUpdateResponse as SubscriptionUpdateResponse,
169 type SubscriptionDeleteResponse as SubscriptionDeleteResponse,
170 type SubscriptionCreateParams as SubscriptionCreateParams,
171 type SubscriptionUpdateParams as SubscriptionUpdateParams,
172 type SubscriptionDeleteParams as SubscriptionDeleteParams,
173 type SubscriptionGetParams as SubscriptionGetParams,
174 };
175}
176
177export { SubscriptionsSinglePage };
178