UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

178 lines • 7.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Subscriptions = exports.BaseSubscriptions = void 0; const tslib_1 = require("../../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../core/resource.js"); const ActionsAPI = tslib_1.__importStar(require("./actions.js")); const actions_1 = require("./actions.js"); const BulkAPI = tslib_1.__importStar(require("./bulk.js")); const bulk_1 = require("./bulk.js"); const CancelReasonAPI = tslib_1.__importStar(require("./cancel-reason.js")); const cancel_reason_1 = require("./cancel-reason.js"); const error_1 = require("../../../core/error.js"); const pagination_1 = require("../../../core/pagination.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseSubscriptions = /* @__PURE__ */ (() => { class BaseSubscriptions extends resource_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.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((0, path_1.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((0, path_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/subscriptions`, (pagination_1.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((0, path_1.path) `/accounts/${account_id}/subscriptions/${subscriptionIdentifier}`, options)._thenUnwrap((obj) => obj.result); } } BaseSubscriptions._key = Object.freeze([ 'accounts', 'subscriptions', ]); return BaseSubscriptions; })(); exports.BaseSubscriptions = BaseSubscriptions; 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 = cancel_reason_1.CancelReason; Subscriptions.BaseCancelReason = cancel_reason_1.BaseCancelReason; Subscriptions.Actions = actions_1.Actions; Subscriptions.BaseActions = actions_1.BaseActions; Subscriptions.Bulk = bulk_1.Bulk; Subscriptions.BaseBulk = bulk_1.BaseBulk; return Subscriptions; })(); exports.Subscriptions = Subscriptions; //# sourceMappingURL=subscriptions.js.map