cloudflare
Version:
The official TypeScript library for the Cloudflare API
169 lines • 6.49 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 { SinglePage } from "../../core/pagination.mjs";
import { path } from "../../internal/utils/path.mjs";
export var BaseJobs = /* @__PURE__ */ (() => {
class BaseJobs extends APIResource {
/**
* Creates a new Logpush job for an account or zone.
*
* @example
* ```ts
* const logpushJob = await client.logpush.jobs.create({
* destination_conf: 's3://mybucket/logs?region=us-west-2',
* 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}/logpush/jobs`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Updates a Logpush job.
*
* @example
* ```ts
* const logpushJob = await client.logpush.jobs.update(1, {
* account_id: 'account_id',
* });
* ```
*/
update(jobID, 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}/logpush/jobs/${jobID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists Logpush jobs for an account or zone.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const logpushJob of client.logpush.jobs.list({
* account_id: 'account_id',
* })) {
* // ...
* }
* ```
*/
list(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}/logpush/jobs`, (SinglePage), options);
}
/**
* Deletes a Logpush job.
*
* @example
* ```ts
* const job = await client.logpush.jobs.delete(1, {
* account_id: 'account_id',
* });
* ```
*/
delete(jobID, 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}/logpush/jobs/${jobID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Gets the details of a Logpush job.
*
* @example
* ```ts
* const logpushJob = await client.logpush.jobs.get(1, {
* account_id: 'account_id',
* });
* ```
*/
get(jobID, 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}/logpush/jobs/${jobID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseJobs._key = Object.freeze(['logpush', 'jobs']);
return BaseJobs;
})();
export class Jobs extends BaseJobs {
}
//# sourceMappingURL=jobs.mjs.map