cloudflare
Version:
The official TypeScript library for the Cloudflare API
172 lines • 6.63 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import * as ActionsAPI from "./actions.mjs";
import { Actions, BaseActions } from "./actions.mjs";
import * as BulkAPI from "./bulk.mjs";
import { BaseBulk, Bulk } from "./bulk.mjs";
import * as CancelReasonAPI from "./cancel-reason.mjs";
import { BaseCancelReason, CancelReason, } from "./cancel-reason.mjs";
import { CloudflareError } from "../../../core/error.mjs";
import { SinglePage } from "../../../core/pagination.mjs";
import { path } from "../../../internal/utils/path.mjs";
export var BaseSubscriptions = /* @__PURE__ */ (() => {
class BaseSubscriptions extends APIResource {
/**
* Creates an account or zone subscription.
*
* @example
* ```ts
* const subscription =
* await client.accounts.subscriptions.create({
* account_id: 'account_id',
* });
* ```
*/
create(params, options) {
const { account_id, zone_id, ...body } = params;
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.post(path `/${accountOrZone}/${accountOrZoneId}/subscriptions`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Updates an account subscription.
*
* @example
* ```ts
* const subscription =
* await client.accounts.subscriptions.update(
* '506e3185e9c882d175a2d0cb0093d9f2',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
update(subscriptionIdentifier, params, options) {
const { account_id, ...body } = params;
return this._client.put(path `/accounts/${account_id}/subscriptions/${subscriptionIdentifier}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Deletes an account's subscription.
*
* @example
* ```ts
* const subscription =
* await client.accounts.subscriptions.delete(
* '506e3185e9c882d175a2d0cb0093d9f2',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(subscriptionIdentifier, params, options) {
const { account_id } = params;
return this._client.delete(path `/accounts/${account_id}/subscriptions/${subscriptionIdentifier}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Cancels pending delayed downgrades for the specified subscriptions.
*
* @example
* ```ts
* const response =
* await client.accounts.subscriptions.cancelDowngrade({
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* });
* ```
*/
cancelDowngrade(params, options) {
const { account_id, ...body } = params;
return this._client.post(path `/accounts/${account_id}/subscriptions/cancel-downgrade`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists all of an account or zone's subscriptions.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const subscription of client.accounts.subscriptions.get(
* { account_id: 'account_id' },
* )) {
* // ...
* }
* ```
*/
get(params = {}, options) {
const { account_id, zone_id } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.getAPIList(path `/${accountOrZone}/${accountOrZoneId}/subscriptions`, (SinglePage), options);
}
/**
* Gets an account subscription by identifier.
*
* @example
* ```ts
* const subscription =
* await client.accounts.subscriptions.getByIdentifier(
* '506e3185e9c882d175a2d0cb0093d9f2',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
getByIdentifier(subscriptionIdentifier, params, options) {
const { account_id } = params;
return this._client.get(path `/accounts/${account_id}/subscriptions/${subscriptionIdentifier}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseSubscriptions._key = Object.freeze([
'accounts',
'subscriptions',
]);
return BaseSubscriptions;
})();
export var Subscriptions = /* @__PURE__ */ (() => {
class Subscriptions extends BaseSubscriptions {
constructor() {
super(...arguments);
this.cancelReason = new CancelReasonAPI.CancelReason(this._client);
this.actions = new ActionsAPI.Actions(this._client);
this.bulk = new BulkAPI.Bulk(this._client);
}
}
Subscriptions.CancelReason = CancelReason;
Subscriptions.BaseCancelReason = BaseCancelReason;
Subscriptions.Actions = Actions;
Subscriptions.BaseActions = BaseActions;
Subscriptions.Bulk = Bulk;
Subscriptions.BaseBulk = BaseBulk;
return Subscriptions;
})();
//# sourceMappingURL=subscriptions.mjs.map