cloudflare
Version:
The official TypeScript library for the Cloudflare API
185 lines • 7.17 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import { CloudflareError } from "../../core/error.mjs";
import { V4PagePaginationArray } from "../../core/pagination.mjs";
import { buildHeaders } from "../../internal/headers.mjs";
import { path } from "../../internal/utils/path.mjs";
export var BaseAssets = /* @__PURE__ */ (() => {
class BaseAssets extends APIResource {
/**
* Creates a custom asset for an account or zone.
*
* @example
* ```ts
* const asset = await client.customPages.assets.create({
* description: 'Custom 500 error page',
* name: 'my_custom_error_page',
* url: 'https://example.com/error.html',
* 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}/custom_pages/assets`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Updates a custom asset for an account or zone.
*
* @example
* ```ts
* const asset = await client.customPages.assets.update(
* 'my_custom_error_page',
* {
* description: 'Custom 500 error page',
* url: 'https://example.com/error.html',
* account_id: 'account_id',
* },
* );
* ```
*/
update(assetName, 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.put(path `/${accountOrZone}/${accountOrZoneId}/custom_pages/assets/${assetName}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists custom assets for an account or zone.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const assetListResponse of client.customPages.assets.list(
* { account_id: 'account_id' },
* )) {
* // ...
* }
* ```
*/
list(params = {}, options) {
const { account_id, zone_id, ...query } = 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}/custom_pages/assets`, (V4PagePaginationArray), { query, ...options });
}
/**
* Deletes a custom asset from an account or zone.
*
* @example
* ```ts
* await client.customPages.assets.delete(
* 'my_custom_error_page',
* { account_id: 'account_id' },
* );
* ```
*/
delete(assetName, 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.delete(path `/${accountOrZone}/${accountOrZoneId}/custom_pages/assets/${assetName}`, {
...options,
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
});
}
/**
* Returns a custom asset for an account or zone.
*
* @example
* ```ts
* const asset = await client.customPages.assets.get(
* 'my_custom_error_page',
* { account_id: 'account_id' },
* );
* ```
*/
get(assetName, 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.get(path `/${accountOrZone}/${accountOrZoneId}/custom_pages/assets/${assetName}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseAssets._key = Object.freeze([
'customPages',
'assets',
]);
return BaseAssets;
})();
export class Assets extends BaseAssets {
}
//# sourceMappingURL=assets.mjs.map