Skip to content

Commit

Permalink
feat(models): add dnsrecordset and behaviors for dnszone
Browse files Browse the repository at this point in the history
  • Loading branch information
ntdoJanneck committed Oct 11, 2024
1 parent 94d8345 commit 101e79f
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/models/src/config/behaviors/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions packages/models/src/dns/DnsRecordSet/DnsRecordSet.ts
Original file line number Diff line number Diff line change
@@ -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<DnsRecordSetData> {
public readonly zone: DnsZone;
public constructor(zone: DnsZoneCommon, data: DnsRecordSetData) {
super(data);
this.zone = zone;
}
}
2 changes: 2 additions & 0 deletions packages/models/src/dns/DnsRecordSet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./DnsRecordSet.js";
export * from "./types.js";
18 changes: 18 additions & 0 deletions packages/models/src/dns/DnsRecordSet/types.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -54,8 +55,10 @@ export class DnsZone extends ReferenceModel {
}

export class DnsZoneCommon extends classes(DataModel<DnsZoneData>, DnsZone) {
public readonly recordSet: DnsRecordSet;
public constructor(data: DnsZoneData) {
super([data], [data.id]);
this.recordSet = new DnsRecordSet(this, data.recordSet);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ import { QueryResponseData } from "../../../base/index.js";
export interface DnsZoneBehaviors {
find: (id: string) => Promise<DnsZoneData | undefined>;
query: (projectId: string) => Promise<QueryResponseData<DnsZoneListItemData>>;

delete: (zoneId: string) => Promise<void>;
create: (name: string, parentZoneId: string) => Promise<{ id: string }>;
setRecordManaged: (zoneId: string, recordSet: "a" | "mx") => Promise<void>;
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/models/src/project/Project/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 101e79f

Please sign in to comment.