cloudflare
Version:
The official TypeScript library for the Cloudflare API
143 lines • 5.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rules = exports.BaseRules = 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 CatchAllsAPI = tslib_1.__importStar(require("./catch-alls.js"));
const catch_alls_1 = require("./catch-alls.js");
const error_1 = require("../../../core/error.js");
const pagination_1 = require("../../../core/pagination.js");
const path_1 = require("../../../internal/utils/path.js");
var BaseRules = /* @__PURE__ */ (() => {
class BaseRules extends resource_1.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((0, path_1.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((0, path_1.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 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}/email/routing/rules`, (pagination_1.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((0, path_1.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((0, path_1.path) `/zones/${zone_id}/email/routing/rules/${ruleIdentifier}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseRules._key = Object.freeze([
'emailRouting',
'rules',
]);
return BaseRules;
})();
exports.BaseRules = BaseRules;
var Rules = /* @__PURE__ */ (() => {
class Rules extends BaseRules {
constructor() {
super(...arguments);
this.catchAlls = new CatchAllsAPI.CatchAlls(this._client);
}
}
Rules.CatchAlls = catch_alls_1.CatchAlls;
Rules.BaseCatchAlls = catch_alls_1.BaseCatchAlls;
return Rules;
})();
exports.Rules = Rules;
//# sourceMappingURL=rules.js.map