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