fix(ci): Update CI workflows, repository URL, and apply minor code formatting fixes
This commit is contained in:
@@ -39,13 +39,13 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',
|
||||
endpoint: string,
|
||||
data?: any,
|
||||
customHeaders?: Record<string, string>
|
||||
customHeaders?: Record<string, string>,
|
||||
): Promise<T> {
|
||||
try {
|
||||
const options: plugins.smartrequest.ISmartRequestOptions = {
|
||||
method,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.authToken}`,
|
||||
Authorization: `Bearer ${this.authToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
...customHeaders,
|
||||
},
|
||||
@@ -62,13 +62,16 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
}
|
||||
|
||||
logger.log('debug', `Making ${method} request to ${endpoint}`);
|
||||
const response = await plugins.smartrequest.request(`https://api.cloudflare.com/client/v4${endpoint}`, options);
|
||||
|
||||
const response = await plugins.smartrequest.request(
|
||||
`https://api.cloudflare.com/client/v4${endpoint}`,
|
||||
options,
|
||||
);
|
||||
|
||||
// Check if response is already an object (might happen with newer smartrequest versions)
|
||||
if (typeof response.body === 'object' && response.body !== null) {
|
||||
return response.body;
|
||||
}
|
||||
|
||||
|
||||
// Otherwise try to parse as JSON
|
||||
try {
|
||||
if (typeof response.body === 'string' && response.body.trim()) {
|
||||
@@ -80,13 +83,15 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
}
|
||||
} catch (parseError) {
|
||||
logger.log('warn', `Failed to parse response as JSON: ${parseError.message}`);
|
||||
|
||||
|
||||
// Create a fake response object to maintain expected structure
|
||||
return {
|
||||
result: [],
|
||||
success: true,
|
||||
errors: [],
|
||||
messages: [`Failed to parse: ${typeof response.body === 'string' ? response.body?.substring(0, 50) : typeof response.body}...`]
|
||||
messages: [
|
||||
`Failed to parse: ${typeof response.body === 'string' ? response.body?.substring(0, 50) : typeof response.body}...`,
|
||||
],
|
||||
} as T;
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -115,12 +120,12 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
listAccounts: async () => {
|
||||
try {
|
||||
const accounts: plugins.ICloudflareTypes['Account'][] = [];
|
||||
|
||||
|
||||
// Collect all accounts using async iterator
|
||||
for await (const account of this.apiAccount.accounts.list()) {
|
||||
accounts.push(account as interfaces.ICloudflareApiAccountObject);
|
||||
}
|
||||
|
||||
|
||||
logger.log('info', `Found ${accounts.length} accounts`);
|
||||
return accounts;
|
||||
} catch (error) {
|
||||
@@ -152,21 +157,24 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
*/
|
||||
getRecord: async (
|
||||
domainNameArg: string,
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType,
|
||||
): Promise<plugins.ICloudflareTypes['Record'] | undefined> => {
|
||||
try {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const recordArrayArg = await this.convenience.listRecords(domain.zoneName);
|
||||
|
||||
|
||||
if (!Array.isArray(recordArrayArg)) {
|
||||
logger.log('warn', `Expected records array for ${domainNameArg} but got ${typeof recordArrayArg}`);
|
||||
logger.log(
|
||||
'warn',
|
||||
`Expected records array for ${domainNameArg} but got ${typeof recordArrayArg}`,
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
const filteredResponse = recordArrayArg.filter((recordArg) => {
|
||||
return recordArg.type === typeArg && recordArg.name === domainNameArg;
|
||||
});
|
||||
|
||||
|
||||
return filteredResponse.length > 0 ? filteredResponse[0] : undefined;
|
||||
} catch (error) {
|
||||
logger.log('error', `Error getting record for ${domainNameArg}: ${error.message}`);
|
||||
@@ -180,7 +188,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
domainNameArg: string,
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType,
|
||||
contentArg: string,
|
||||
ttlArg = 1
|
||||
ttlArg = 1,
|
||||
): Promise<any> => {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const zoneId = await this.convenience.getZoneId(domain.zoneName);
|
||||
@@ -190,7 +198,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
name: domain.fullName,
|
||||
content: contentArg,
|
||||
ttl: ttlArg,
|
||||
})
|
||||
});
|
||||
return response;
|
||||
},
|
||||
/**
|
||||
@@ -200,7 +208,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
*/
|
||||
removeRecord: async (
|
||||
domainNameArg: string,
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType,
|
||||
): Promise<any> => {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const zoneId = await this.convenience.getZoneId(domain.zoneName);
|
||||
@@ -228,22 +236,28 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
logger.log('info', `Cleaning ${typeArg} records for ${domainNameArg}`);
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const zoneId = await this.convenience.getZoneId(domain.zoneName);
|
||||
|
||||
|
||||
// List all records in the zone for this domain
|
||||
const records = await this.convenience.listRecords(domain.zoneName);
|
||||
|
||||
|
||||
if (!Array.isArray(records)) {
|
||||
logger.log('warn', `Expected records array for ${domainNameArg} but got ${typeof records}`);
|
||||
logger.log(
|
||||
'warn',
|
||||
`Expected records array for ${domainNameArg} but got ${typeof records}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Only delete records matching the specified name and type
|
||||
const recordsToDelete = records.filter((recordArg) => {
|
||||
return recordArg.type === typeArg && recordArg.name === domainNameArg;
|
||||
});
|
||||
|
||||
logger.log('info', `Found ${recordsToDelete.length} ${typeArg} records to delete for ${domainNameArg}`);
|
||||
|
||||
|
||||
logger.log(
|
||||
'info',
|
||||
`Found ${recordsToDelete.length} ${typeArg} records to delete for ${domainNameArg}`,
|
||||
);
|
||||
|
||||
for (const recordToDelete of recordsToDelete) {
|
||||
try {
|
||||
// The official client might have different property locations
|
||||
@@ -253,7 +267,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
logger.log('warn', `Record ID not found for ${domainNameArg} record`);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
await this.apiAccount.dns.records.delete(recordId, {
|
||||
zone_id: zoneId,
|
||||
});
|
||||
@@ -263,7 +277,10 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.log('error', `Error cleaning ${typeArg} records for ${domainNameArg}: ${error.message}`);
|
||||
logger.log(
|
||||
'error',
|
||||
`Error cleaning ${typeArg} records for ${domainNameArg}: ${error.message}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -279,19 +296,22 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
domainNameArg: string,
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType,
|
||||
contentArg: string,
|
||||
ttlArg: number = 1
|
||||
ttlArg: number = 1,
|
||||
): Promise<plugins.ICloudflareTypes['Record']> => {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const zoneId = await this.convenience.getZoneId(domain.zoneName);
|
||||
|
||||
|
||||
// Find existing record
|
||||
const record = await this.convenience.getRecord(domainNameArg, typeArg);
|
||||
|
||||
|
||||
if (!record) {
|
||||
logger.log('warn', `Record ${domainNameArg} of type ${typeArg} not found for update, creating instead`);
|
||||
logger.log(
|
||||
'warn',
|
||||
`Record ${domainNameArg} of type ${typeArg} not found for update, creating instead`,
|
||||
);
|
||||
return this.convenience.createRecord(domainNameArg, typeArg, contentArg, ttlArg);
|
||||
}
|
||||
|
||||
|
||||
// Update the record - cast to any to access the id property
|
||||
const recordId = (record as any).id;
|
||||
const updatedRecord = await this.apiAccount.dns.records.edit(recordId, {
|
||||
@@ -299,9 +319,9 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
type: typeArg as any,
|
||||
name: domain.fullName,
|
||||
content: contentArg,
|
||||
ttl: ttlArg
|
||||
ttl: ttlArg,
|
||||
});
|
||||
|
||||
|
||||
return updatedRecord;
|
||||
},
|
||||
/**
|
||||
@@ -313,14 +333,14 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const zoneId = await this.convenience.getZoneId(domain.zoneName);
|
||||
const records: plugins.ICloudflareTypes['Record'][] = [];
|
||||
|
||||
|
||||
// Collect all records using async iterator
|
||||
for await (const record of this.apiAccount.dns.records.list({
|
||||
zone_id: zoneId,
|
||||
})) {
|
||||
records.push(record);
|
||||
}
|
||||
|
||||
|
||||
logger.log('info', `Found ${records.length} DNS records for ${domainNameArg}`);
|
||||
return records;
|
||||
} catch (error) {
|
||||
@@ -338,15 +358,18 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
if (domainName) {
|
||||
options.name = domainName;
|
||||
}
|
||||
|
||||
|
||||
const zones: plugins.ICloudflareTypes['Zone'][] = [];
|
||||
|
||||
|
||||
// Collect all zones using async iterator
|
||||
for await (const zone of this.apiAccount.zones.list(options)) {
|
||||
zones.push(zone);
|
||||
}
|
||||
|
||||
logger.log('info', `Found ${zones.length} zones${domainName ? ` matching ${domainName}` : ''}`);
|
||||
|
||||
logger.log(
|
||||
'info',
|
||||
`Found ${zones.length} zones${domainName ? ` matching ${domainName}` : ''}`,
|
||||
);
|
||||
return zones;
|
||||
} catch (error) {
|
||||
logger.log('error', `Failed to list zones: ${error.message}`);
|
||||
@@ -390,11 +413,11 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
|
||||
dnsChallenge.hostName,
|
||||
'TXT',
|
||||
dnsChallenge.challenge,
|
||||
120
|
||||
120,
|
||||
);
|
||||
},
|
||||
acmeRemoveDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
|
||||
await this.convenience.removeRecord(dnsChallenge.hostName, 'TXT');
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user