diff --git a/packages/models/src/config/behaviors/api.ts b/packages/models/src/config/behaviors/api.ts index 5331bfce..d0f587c5 100644 --- a/packages/models/src/config/behaviors/api.ts +++ b/packages/models/src/config/behaviors/api.ts @@ -9,7 +9,7 @@ import { addUrlTagToProvideReactCache } from "../../react/asyncResourceInvalidat import { apiArticleBehaviors } from "../../article/Article/behaviors/index.js"; import { apiContractBehaviors } from "../../contract/Contract/behaviors/index.js"; import { apiContractItemBehaviors } from "../../contract/ContractItem/behaviors/index.js"; -import { apiDnsZoneBehaviors } from "../../dns/Zone/behaviors/api.js"; +import { apiDnsZoneBehaviors } from "../../dns/DnsZone/behaviors/api.js"; class ApiSetupState { private _client: MittwaldAPIV2Client | undefined; diff --git a/packages/models/src/config/config.ts b/packages/models/src/config/config.ts index 9fd967f9..9fcb75ba 100644 --- a/packages/models/src/config/config.ts +++ b/packages/models/src/config/config.ts @@ -6,7 +6,7 @@ import { ContractBehaviors } from "../contract/Contract/behaviors/index.js"; import { AppInstallationBehaviors } from "../app/AppInstallation/behaviors/index.js"; import { ContractItemBehaviors } from "../contract/ContractItem/behaviors/index.js"; import { ArticleBehaviors } from "../article/Article/behaviors/index.js"; -import { DnsZoneBehaviors } from "../dns/Zone/behaviors/types.js"; +import { DnsZoneBehaviors } from "../dns/DnsZone/behaviors/types.js"; interface Config { defaultPaginationLimit: number; diff --git a/packages/models/src/dns/DnsRecordSet/DnsRecordSet.ts b/packages/models/src/dns/DnsRecordSet/DnsRecordSet.ts new file mode 100644 index 00000000..88f1c3b5 --- /dev/null +++ b/packages/models/src/dns/DnsRecordSet/DnsRecordSet.ts @@ -0,0 +1,11 @@ +import { DataModel } from "../../base/index.js"; +import { DnsRecordSetData } from "./types.js"; +import { DnsZone, DnsZoneCommon } from "../DnsZone/index.js"; + +export class DnsRecordSet extends DataModel { + public readonly zone: DnsZone; + public constructor(zone: DnsZoneCommon, data: DnsRecordSetData) { + super(data); + this.zone = zone; + } +} diff --git a/packages/models/src/dns/DnsRecordSet/index.ts b/packages/models/src/dns/DnsRecordSet/index.ts new file mode 100644 index 00000000..1824f36b --- /dev/null +++ b/packages/models/src/dns/DnsRecordSet/index.ts @@ -0,0 +1,2 @@ +export * from "./DnsRecordSet.js"; +export * from "./types.js"; diff --git a/packages/models/src/dns/DnsRecordSet/types.ts b/packages/models/src/dns/DnsRecordSet/types.ts new file mode 100644 index 00000000..684a5dee --- /dev/null +++ b/packages/models/src/dns/DnsRecordSet/types.ts @@ -0,0 +1,18 @@ +import { MittwaldAPIV2 } from "@mittwald/api-client"; + +export type CNameRecordData = MittwaldAPIV2.Components.Schemas.DnsRecordCNAME; +export type CombinedARecordData = + MittwaldAPIV2.Components.Schemas.DnsRecordCombinedA; +export type MXRecordData = MittwaldAPIV2.Components.Schemas.DnsRecordMX; +export type SRVRecordData = MittwaldAPIV2.Components.Schemas.DnsRecordSRV; +export type TXTRecordData = MittwaldAPIV2.Components.Schemas.DnsRecordTXT; + +export type RecordSettings = MittwaldAPIV2.Components.Schemas.DnsRecordSettings; + +export type DnsRecordSetData = { + cname: CNameRecordData; + combinedARecords: CombinedARecordData; + mx: MXRecordData; + srv: SRVRecordData; + txt: TXTRecordData; +}; diff --git a/packages/models/src/dns/Zone/DnsZone.ts b/packages/models/src/dns/DnsZone/DnsZone.ts similarity index 94% rename from packages/models/src/dns/Zone/DnsZone.ts rename to packages/models/src/dns/DnsZone/DnsZone.ts index aa95b051..ca277e65 100644 --- a/packages/models/src/dns/Zone/DnsZone.ts +++ b/packages/models/src/dns/DnsZone/DnsZone.ts @@ -15,6 +15,7 @@ import { AsyncResourceVariant, provideReact } from "../../react/index.js"; import { config } from "../../config/config.js"; import { Project } from "../../project/index.js"; import assertObjectFound from "../../base/assertObjectFound.js"; +import { DnsRecordSet } from "../DnsRecordSet/DnsRecordSet.js"; export class DnsZone extends ReferenceModel { public static ofId(id: string): DnsZone { @@ -54,8 +55,10 @@ export class DnsZone extends ReferenceModel { } export class DnsZoneCommon extends classes(DataModel, DnsZone) { + public readonly recordSet: DnsRecordSet; public constructor(data: DnsZoneData) { super([data], [data.id]); + this.recordSet = new DnsRecordSet(this, data.recordSet); } } diff --git a/packages/models/src/dns/Zone/behaviors/api.ts b/packages/models/src/dns/DnsZone/behaviors/api.ts similarity index 52% rename from packages/models/src/dns/Zone/behaviors/api.ts rename to packages/models/src/dns/DnsZone/behaviors/api.ts index 000049e5..c185d9c6 100644 --- a/packages/models/src/dns/Zone/behaviors/api.ts +++ b/packages/models/src/dns/DnsZone/behaviors/api.ts @@ -27,4 +27,26 @@ export const apiDnsZoneBehaviors = ( totalCount: response.data.length, }; }, + delete: async (zoneId: string) => { + const response = await client.domain.dnsDeleteDnsZone({ + dnsZoneId: zoneId, + }); + assertStatus(response, 200); + }, + create: async (name: string, parentZoneId: string) => { + const response = await client.domain.dnsCreateDnsZone({ + data: { name, parentZoneId }, + }); + assertStatus(response, 201); + return { + id: response.data.id, + }; + }, + setRecordManaged: async (zoneId: string, recordSet: "a" | "mx") => { + const response = await client.domain.dnsSetRecordSetManaged({ + recordSet, + dnsZoneId: zoneId, + }); + assertStatus(response, 204); + }, }); diff --git a/packages/models/src/dns/Zone/behaviors/index.ts b/packages/models/src/dns/DnsZone/behaviors/index.ts similarity index 100% rename from packages/models/src/dns/Zone/behaviors/index.ts rename to packages/models/src/dns/DnsZone/behaviors/index.ts diff --git a/packages/models/src/dns/Zone/behaviors/types.ts b/packages/models/src/dns/DnsZone/behaviors/types.ts similarity index 60% rename from packages/models/src/dns/Zone/behaviors/types.ts rename to packages/models/src/dns/DnsZone/behaviors/types.ts index 9dccb1bd..170ecdad 100644 --- a/packages/models/src/dns/Zone/behaviors/types.ts +++ b/packages/models/src/dns/DnsZone/behaviors/types.ts @@ -4,4 +4,8 @@ import { QueryResponseData } from "../../../base/index.js"; export interface DnsZoneBehaviors { find: (id: string) => Promise; query: (projectId: string) => Promise>; + + delete: (zoneId: string) => Promise; + create: (name: string, parentZoneId: string) => Promise<{ id: string }>; + setRecordManaged: (zoneId: string, recordSet: "a" | "mx") => Promise; } diff --git a/packages/models/src/dns/Zone/index.ts b/packages/models/src/dns/DnsZone/index.ts similarity index 100% rename from packages/models/src/dns/Zone/index.ts rename to packages/models/src/dns/DnsZone/index.ts diff --git a/packages/models/src/dns/Zone/types.ts b/packages/models/src/dns/DnsZone/types.ts similarity index 100% rename from packages/models/src/dns/Zone/types.ts rename to packages/models/src/dns/DnsZone/types.ts diff --git a/packages/models/src/project/Project/Project.ts b/packages/models/src/project/Project/Project.ts index cacd2dad..37cbbdb3 100644 --- a/packages/models/src/project/Project/Project.ts +++ b/packages/models/src/project/Project/Project.ts @@ -23,7 +23,7 @@ import { import { ListQueryModel } from "../../base/ListQueryModel.js"; import { ListDataModel } from "../../base/ListDataModel.js"; import { AppInstallationListQuery } from "../../app/index.js"; -import { DnsZoneListQuery } from "../../dns/Zone/index.js"; +import { DnsZoneListQuery } from "../../dns/DnsZone/index.js"; export class Project extends ReferenceModel { public readonly ingresses: IngressListQuery;