quality / changes (push) Successful in 9s
quality / commitlint (push) Skipped
quality / docker-check (push) Skipped
CD / update-wiki (push) Successful in 6s
quality / web (push) Successful in 1m4s
quality / api (push) Successful in 54s
CD / quality (push) Successful in 2m17s
CD / publish (push) Successful in 2m21s
Worker сам ходит на origin по Cron Trigger; CFDM кладёт цели в KV и забирает результаты без POST /probe. Co-authored-by: Cursor <[email protected]>
138 lines
3.8 KiB
TypeScript
138 lines
3.8 KiB
TypeScript
import type {
|
|
CfDnsRecord,
|
|
CfHealthCheck,
|
|
CfZone,
|
|
CreateDnsRecordPayload,
|
|
PatchDnsRecordPayload,
|
|
} from "@cfdm/shared";
|
|
import { createDnsAdapter } from "./cloudflare/dns-service.js";
|
|
import { createHealthCheckAdapter, type CfHealthCheckPayload } from "./cloudflare/healthcheck-service.js";
|
|
import { createKvAdapter } from "./cloudflare/kv-service.js";
|
|
import { createWorkersAdapter } from "./cloudflare/workers-service.js";
|
|
import { createZoneAdapter } from "./cloudflare/zone-service.js";
|
|
|
|
export type { CfHealthCheckPayload };
|
|
|
|
export class CloudflareClient {
|
|
private readonly zones;
|
|
private readonly dns;
|
|
private readonly healthchecks;
|
|
private readonly kv;
|
|
private readonly workers;
|
|
private readonly token;
|
|
|
|
constructor(token: string) {
|
|
this.token = token.trim();
|
|
this.zones = createZoneAdapter(token);
|
|
this.dns = createDnsAdapter(token);
|
|
this.healthchecks = createHealthCheckAdapter(token);
|
|
this.kv = createKvAdapter(token);
|
|
this.workers = createWorkersAdapter(token);
|
|
}
|
|
|
|
get isConfigured(): boolean {
|
|
return this.token.length > 0;
|
|
}
|
|
|
|
listZones(): Promise<CfZone[]> {
|
|
return this.zones.listZones();
|
|
}
|
|
|
|
getZone(zoneId: string): Promise<CfZone> {
|
|
return this.zones.getZone(zoneId);
|
|
}
|
|
|
|
listDnsRecords(zoneId: string): Promise<CfDnsRecord[]> {
|
|
return this.dns.listDnsRecords(zoneId);
|
|
}
|
|
|
|
createDnsRecord(zoneId: string, payload: CreateDnsRecordPayload): Promise<CfDnsRecord> {
|
|
return this.dns.createDnsRecord(zoneId, payload);
|
|
}
|
|
|
|
updateDnsRecord(
|
|
zoneId: string,
|
|
recordId: string,
|
|
payload: CreateDnsRecordPayload,
|
|
): Promise<CfDnsRecord> {
|
|
return this.dns.updateDnsRecord(zoneId, recordId, payload);
|
|
}
|
|
|
|
patchDnsRecord(
|
|
zoneId: string,
|
|
recordId: string,
|
|
payload: PatchDnsRecordPayload,
|
|
): Promise<CfDnsRecord> {
|
|
return this.dns.patchDnsRecord(zoneId, recordId, payload);
|
|
}
|
|
|
|
deleteDnsRecord(zoneId: string, recordId: string): Promise<void> {
|
|
return this.dns.deleteDnsRecord(zoneId, recordId);
|
|
}
|
|
|
|
listHealthChecks(zoneId: string): Promise<CfHealthCheck[]> {
|
|
return this.healthchecks.listHealthChecks(zoneId);
|
|
}
|
|
|
|
getHealthCheck(zoneId: string, id: string): Promise<CfHealthCheck> {
|
|
return this.healthchecks.getHealthCheck(zoneId, id);
|
|
}
|
|
|
|
createHealthCheck(zoneId: string, payload: CfHealthCheckPayload): Promise<CfHealthCheck> {
|
|
return this.healthchecks.createHealthCheck(zoneId, payload);
|
|
}
|
|
|
|
updateHealthCheck(
|
|
zoneId: string,
|
|
id: string,
|
|
payload: CfHealthCheckPayload,
|
|
): Promise<CfHealthCheck> {
|
|
return this.healthchecks.updateHealthCheck(zoneId, id, payload);
|
|
}
|
|
|
|
deleteHealthCheck(zoneId: string, id: string): Promise<void> {
|
|
return this.healthchecks.deleteHealthCheck(zoneId, id);
|
|
}
|
|
|
|
listAccounts() {
|
|
return this.workers.listAccounts();
|
|
}
|
|
|
|
listKvNamespaces(accountId: string) {
|
|
return this.kv.listNamespaces(accountId);
|
|
}
|
|
|
|
createKvNamespace(accountId: string, title: string) {
|
|
return this.kv.createNamespace(accountId, title);
|
|
}
|
|
|
|
kvGet(accountId: string, namespaceId: string, key: string) {
|
|
return this.kv.getValue(accountId, namespaceId, key);
|
|
}
|
|
|
|
kvPut(accountId: string, namespaceId: string, key: string, value: string) {
|
|
return this.kv.putValue(accountId, namespaceId, key, value);
|
|
}
|
|
|
|
putWorkerScript(opts: {
|
|
accountId: string;
|
|
scriptName: string;
|
|
source: string;
|
|
kvNamespaceId: string;
|
|
}) {
|
|
return this.workers.putScript(opts);
|
|
}
|
|
|
|
putWorkerSchedules(accountId: string, scriptName: string, crons: string[]) {
|
|
return this.workers.putSchedules(accountId, scriptName, crons);
|
|
}
|
|
|
|
enableWorkersDev(accountId: string, scriptName: string) {
|
|
return this.workers.enableWorkersDev(accountId, scriptName);
|
|
}
|
|
|
|
getWorkersSubdomain(accountId: string) {
|
|
return this.workers.getWorkersSubdomain(accountId);
|
|
}
|
|
}
|