BREAKING CHANGE(core): Introduce RecordManager and ConvenientDnsProvider; rename list/get methods for consistent API and deprecate convenience namespace
This commit is contained in:
@@ -12,11 +12,11 @@ export class ZoneManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all zones, optionally filtered by name
|
||||
* Lists all zones, optionally filtered by name
|
||||
* @param zoneName Optional zone name to filter by
|
||||
* @returns Array of CloudflareZone instances
|
||||
*/
|
||||
public async getZones(zoneName?: string): Promise<CloudflareZone[]> {
|
||||
public async listZones(zoneName?: string): Promise<CloudflareZone[]> {
|
||||
try {
|
||||
const options: any = { per_page: 50 };
|
||||
|
||||
@@ -37,13 +37,33 @@ export class ZoneManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the zone ID for a domain name
|
||||
* @param domainName Domain name to get the zone ID for
|
||||
* @returns Zone ID string
|
||||
* @throws Error if domain is not found in this account
|
||||
*/
|
||||
public async getZoneId(domainName: string): Promise<string> {
|
||||
const domain = new plugins.smartstring.Domain(domainName);
|
||||
const zoneArray = await this.listZones(domain.zoneName);
|
||||
const filteredResponse = zoneArray.filter((zoneArg) => {
|
||||
return zoneArg.name === domainName;
|
||||
});
|
||||
if (filteredResponse.length >= 1) {
|
||||
return filteredResponse[0].id;
|
||||
} else {
|
||||
logger.log('error', `the domain ${domainName} does not appear to be in this account!`);
|
||||
throw new Error(`the domain ${domainName} does not appear to be in this account!`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single zone by name
|
||||
* @param zoneName Zone name to find
|
||||
* @returns CloudflareZone instance or undefined if not found
|
||||
*/
|
||||
public async getZoneByName(zoneName: string): Promise<CloudflareZone | undefined> {
|
||||
const zones = await this.getZones(zoneName);
|
||||
const zones = await this.listZones(zoneName);
|
||||
return zones.find((zone) => zone.name === zoneName);
|
||||
}
|
||||
|
||||
@@ -130,7 +150,7 @@ export class ZoneManager {
|
||||
* @returns True if the zone exists
|
||||
*/
|
||||
public async zoneExists(zoneName: string): Promise<boolean> {
|
||||
const zones = await this.getZones(zoneName);
|
||||
const zones = await this.listZones(zoneName);
|
||||
return zones.some((zone) => zone.name === zoneName);
|
||||
}
|
||||
|
||||
@@ -180,4 +200,18 @@ export class ZoneManager {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purges all cached files for a zone
|
||||
* @param domainName Domain name to purge cache for
|
||||
*/
|
||||
public async purgeZone(domainName: string): Promise<void> {
|
||||
const domain = new plugins.smartstring.Domain(domainName);
|
||||
const zoneId = await this.getZoneId(domain.zoneName);
|
||||
await this.cfAccount.apiAccount.cache.purge({
|
||||
zone_id: zoneId,
|
||||
purge_everything: true,
|
||||
});
|
||||
logger.log('info', `Purged cache for zone ${domainName}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user