cloudflare
Version:
The official TypeScript library for the Cloudflare API
137 lines • 5.39 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import * as CatchAllsAPI from "./catch-alls.mjs";
import { BaseCatchAlls, CatchAlls, } from "./catch-alls.mjs";
import { CloudflareError } from "../../../core/error.mjs";
import { V4PagePaginationArray, } from "../../../core/pagination.mjs";
import { path } from "../../../internal/utils/path.mjs";
export var BaseRules = /* @__PURE__ */ (() => {
class BaseRules extends APIResource {
/**
* Rules consist of a set of criteria for matching emails (such as an email being
* sent to a specific custom email address) plus a set of actions to take on the
* email (like forwarding it to a specific destination address). Forward actions
* require exactly one verified destination address.
*
* @example
* ```ts
* const emailRoutingRule =
* await client.emailRouting.rules.create({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* actions: [{ type: 'forward' }],
* matchers: [{ type: 'literal' }],
* });
* ```
*/
create(params, options) {
const { zone_id, ...body } = params;
return this._client.post(path `/zones/${zone_id}/email/routing/rules`, { body, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Update actions and matches, or enable/disable specific routing rules. Forward
* actions require exactly one verified destination address.
*
* @example
* ```ts
* const emailRoutingRule =
* await client.emailRouting.rules.update(
* 'a7e6fb77503c41d8a7f3113c6918f10c',
* {
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* actions: [{ type: 'forward' }],
* matchers: [{ type: 'literal' }],
* },
* );
* ```
*/
update(ruleIdentifier, params, options) {
const { zone_id, ...body } = params;
return this._client.put(path `/zones/${zone_id}/email/routing/rules/${ruleIdentifier}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists existing routing rules across all zones in the account or zone.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const accountRule of client.emailRouting.rules.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}/email/routing/rules`, (V4PagePaginationArray), { query, ...options });
}
/**
* Deletes a routing rule so matching incoming messages are no longer forwarded by
* it.
*
* @example
* ```ts
* const emailRoutingRule =
* await client.emailRouting.rules.delete(
* 'a7e6fb77503c41d8a7f3113c6918f10c',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(ruleIdentifier, params, options) {
const { zone_id } = params;
return this._client.delete(path `/zones/${zone_id}/email/routing/rules/${ruleIdentifier}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Get information for a specific routing rule already created.
*
* @example
* ```ts
* const emailRoutingRule =
* await client.emailRouting.rules.get(
* 'a7e6fb77503c41d8a7f3113c6918f10c',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(ruleIdentifier, params, options) {
const { zone_id } = params;
return this._client.get(path `/zones/${zone_id}/email/routing/rules/${ruleIdentifier}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseRules._key = Object.freeze([
'emailRouting',
'rules',
]);
return BaseRules;
})();
export var Rules = /* @__PURE__ */ (() => {
class Rules extends BaseRules {
constructor() {
super(...arguments);
this.catchAlls = new CatchAllsAPI.CatchAlls(this._client);
}
}
Rules.CatchAlls = CatchAlls;
Rules.BaseCatchAlls = BaseCatchAlls;
return Rules;
})();
//# sourceMappingURL=rules.mjs.map