@kumulo/dns-godaddy 0.0.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +25 -0
- package/dist/client/godaddy-dns.d.ts +93 -0
- package/dist/config.d.ts +31 -0
- package/dist/errors.d.ts +29 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +332 -0
- package/dist/provider/dns-provider.d.ts +14 -0
- package/dist/transport/http-client.d.ts +13 -0
- package/package.json +57 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Stahl-Gruber
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @kumulo/dns-godaddy
|
|
2
|
+
|
|
3
|
+
DnsProvider implementation backed by the GoDaddy Domains DNS API.
|
|
4
|
+
|
|
5
|
+
Part of [kumulo](../../../README.md) — a CLI that provisions and manages
|
|
6
|
+
Kubernetes clusters on OVH from a single YAML config. This package is
|
|
7
|
+
published from that workspace and is normally consumed through the `kumulo`
|
|
8
|
+
CLI rather than directly.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
bun add @kumulo/dns-godaddy
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Set `dns.module: godaddy` and export `GODADDY_API_TOKEN`, a personal access
|
|
17
|
+
token with scope `domains.dns:update` from
|
|
18
|
+
https://developer.godaddy.com/personal-access-token. `GODADDY_API_BASE_URL` is
|
|
19
|
+
optional. TTLs must be at least 600, and a CNAME cannot sit on the apex. A 403
|
|
20
|
+
means a missing scope or an account GoDaddy does not allow to use the DNS API.
|
|
21
|
+
The root README's "GoDaddy DNS" section covers eligibility, OTE and the
|
|
22
|
+
nameserver fallback.
|
|
23
|
+
|
|
24
|
+
See the [root README](../../../README.md) for configuration, commands and
|
|
25
|
+
examples, and the [changelog](../../../CHANGELOG.md) for release notes.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import type { DnsError } from "@kumulo/core";
|
|
4
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
5
|
+
export declare const DnsRecordType: Schema.Literals<readonly ["A", "AAAA", "CNAME", "MX", "TXT", "NS", "SRV", "SOA", "CAA"]>;
|
|
6
|
+
export type DnsRecordType = typeof DnsRecordType.Type;
|
|
7
|
+
export declare const DnsRecord: Schema.Struct<{
|
|
8
|
+
readonly recordId: Schema.String;
|
|
9
|
+
readonly name: Schema.String;
|
|
10
|
+
readonly type: Schema.Literals<readonly ["A", "AAAA", "CNAME", "MX", "TXT", "NS", "SRV", "SOA", "CAA"]>;
|
|
11
|
+
readonly data: Schema.String;
|
|
12
|
+
readonly ttl: Schema.Number;
|
|
13
|
+
readonly priority: Schema.optionalKey<Schema.Number>;
|
|
14
|
+
readonly service: Schema.optionalKey<Schema.String>;
|
|
15
|
+
readonly port: Schema.optionalKey<Schema.Number>;
|
|
16
|
+
readonly weight: Schema.optionalKey<Schema.Number>;
|
|
17
|
+
readonly protocol: Schema.optionalKey<Schema.String>;
|
|
18
|
+
readonly flag: Schema.optionalKey<Schema.Number>;
|
|
19
|
+
readonly tag: Schema.optionalKey<Schema.String>;
|
|
20
|
+
}>;
|
|
21
|
+
export type DnsRecord = typeof DnsRecord.Type;
|
|
22
|
+
export declare const DnsRecordInput: Schema.Struct<{
|
|
23
|
+
readonly name: Schema.String;
|
|
24
|
+
readonly type: Schema.Literals<readonly ["A", "AAAA", "CNAME", "MX", "TXT", "NS", "SRV", "SOA", "CAA"]>;
|
|
25
|
+
readonly data: Schema.String;
|
|
26
|
+
readonly ttl: Schema.Number;
|
|
27
|
+
readonly priority: Schema.optionalKey<Schema.Number>;
|
|
28
|
+
readonly service: Schema.optionalKey<Schema.String>;
|
|
29
|
+
readonly port: Schema.optionalKey<Schema.Number>;
|
|
30
|
+
readonly weight: Schema.optionalKey<Schema.Number>;
|
|
31
|
+
readonly protocol: Schema.optionalKey<Schema.String>;
|
|
32
|
+
readonly flag: Schema.optionalKey<Schema.Number>;
|
|
33
|
+
readonly tag: Schema.optionalKey<Schema.String>;
|
|
34
|
+
}>;
|
|
35
|
+
export type DnsRecordInput = typeof DnsRecordInput.Type;
|
|
36
|
+
export declare const DnsRecordList: Schema.Struct<{
|
|
37
|
+
readonly items: Schema.$Array<Schema.Struct<{
|
|
38
|
+
readonly recordId: Schema.String;
|
|
39
|
+
readonly name: Schema.String;
|
|
40
|
+
readonly type: Schema.Literals<readonly ["A", "AAAA", "CNAME", "MX", "TXT", "NS", "SRV", "SOA", "CAA"]>;
|
|
41
|
+
readonly data: Schema.String;
|
|
42
|
+
readonly ttl: Schema.Number;
|
|
43
|
+
readonly priority: Schema.optionalKey<Schema.Number>;
|
|
44
|
+
readonly service: Schema.optionalKey<Schema.String>;
|
|
45
|
+
readonly port: Schema.optionalKey<Schema.Number>;
|
|
46
|
+
readonly weight: Schema.optionalKey<Schema.Number>;
|
|
47
|
+
readonly protocol: Schema.optionalKey<Schema.String>;
|
|
48
|
+
readonly flag: Schema.optionalKey<Schema.Number>;
|
|
49
|
+
readonly tag: Schema.optionalKey<Schema.String>;
|
|
50
|
+
}>>;
|
|
51
|
+
readonly links: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
52
|
+
readonly rel: Schema.String;
|
|
53
|
+
readonly href: Schema.String;
|
|
54
|
+
}>>>;
|
|
55
|
+
}>;
|
|
56
|
+
export type DnsRecordList = typeof DnsRecordList.Type;
|
|
57
|
+
export type GodaddyDnsClientError = DnsError;
|
|
58
|
+
export interface GodaddyDnsClient {
|
|
59
|
+
readonly listRecords: (input: {
|
|
60
|
+
readonly zone: string;
|
|
61
|
+
}) => Effect.Effect<ReadonlyArray<DnsRecord>, GodaddyDnsClientError>;
|
|
62
|
+
readonly probe: (input: {
|
|
63
|
+
readonly zone: string;
|
|
64
|
+
}) => Effect.Effect<void, GodaddyDnsClientError>;
|
|
65
|
+
readonly createRecord: (input: {
|
|
66
|
+
readonly zone: string;
|
|
67
|
+
readonly record: DnsRecordInput;
|
|
68
|
+
}) => Effect.Effect<DnsRecord, GodaddyDnsClientError>;
|
|
69
|
+
readonly replaceRecord: (input: {
|
|
70
|
+
readonly zone: string;
|
|
71
|
+
readonly recordId: string;
|
|
72
|
+
readonly record: DnsRecordInput;
|
|
73
|
+
}) => Effect.Effect<DnsRecord, GodaddyDnsClientError>;
|
|
74
|
+
readonly deleteRecord: (input: {
|
|
75
|
+
readonly zone: string;
|
|
76
|
+
readonly recordId: string;
|
|
77
|
+
}) => Effect.Effect<void, GodaddyDnsClientError>;
|
|
78
|
+
}
|
|
79
|
+
export declare const clientOperations: readonly [{
|
|
80
|
+
readonly method: "get";
|
|
81
|
+
readonly path: "/zones/{zone}/dns-records";
|
|
82
|
+
}, {
|
|
83
|
+
readonly method: "post";
|
|
84
|
+
readonly path: "/zones/{zone}/dns-records";
|
|
85
|
+
}, {
|
|
86
|
+
readonly method: "put";
|
|
87
|
+
readonly path: "/zones/{zone}/dns-records/{recordId}";
|
|
88
|
+
}, {
|
|
89
|
+
readonly method: "delete";
|
|
90
|
+
readonly path: "/zones/{zone}/dns-records/{recordId}";
|
|
91
|
+
}];
|
|
92
|
+
export declare const pageSize = 100;
|
|
93
|
+
export declare const makeGodaddyDnsClient: (httpClient: HttpClient.HttpClient) => GodaddyDnsClient;
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const godaddyTtlMinimum: import("@kumulo/core").CrossFieldRule<{
|
|
2
|
+
dns: {
|
|
3
|
+
module: string;
|
|
4
|
+
ttl?: number;
|
|
5
|
+
};
|
|
6
|
+
}>;
|
|
7
|
+
export declare const godaddyApexNotCname: import("@kumulo/core").CrossFieldRule<{
|
|
8
|
+
dns: {
|
|
9
|
+
module: string;
|
|
10
|
+
zone?: string;
|
|
11
|
+
records?: ReadonlyArray<{
|
|
12
|
+
name: string;
|
|
13
|
+
target: string;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
export declare const godaddyConfigRules: (import("@kumulo/core").CrossFieldRule<{
|
|
18
|
+
dns: {
|
|
19
|
+
module: string;
|
|
20
|
+
ttl?: number;
|
|
21
|
+
};
|
|
22
|
+
}> | import("@kumulo/core").CrossFieldRule<{
|
|
23
|
+
dns: {
|
|
24
|
+
module: string;
|
|
25
|
+
zone?: string;
|
|
26
|
+
records?: ReadonlyArray<{
|
|
27
|
+
name: string;
|
|
28
|
+
target: string;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
}>)[];
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import type { SchemaError } from "effect/Schema";
|
|
3
|
+
import * as HttpClientError from "effect/http/HttpClientError";
|
|
4
|
+
import type { DnsError } from "@kumulo/core";
|
|
5
|
+
export declare const GodaddyError: Schema.Struct<{
|
|
6
|
+
readonly code: Schema.String;
|
|
7
|
+
readonly message: Schema.optional<Schema.String>;
|
|
8
|
+
readonly fields: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
9
|
+
readonly code: Schema.optional<Schema.String>;
|
|
10
|
+
readonly message: Schema.optional<Schema.String>;
|
|
11
|
+
readonly path: Schema.optional<Schema.String>;
|
|
12
|
+
readonly pathRelated: Schema.optional<Schema.String>;
|
|
13
|
+
}>>>;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const GodaddyErrorLimit: Schema.Struct<{
|
|
16
|
+
readonly code: Schema.String;
|
|
17
|
+
readonly message: Schema.optional<Schema.String>;
|
|
18
|
+
readonly retryAfterSec: Schema.Number;
|
|
19
|
+
readonly fields: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
20
|
+
readonly code: Schema.optional<Schema.String>;
|
|
21
|
+
readonly message: Schema.optional<Schema.String>;
|
|
22
|
+
readonly path: Schema.optional<Schema.String>;
|
|
23
|
+
}>>>;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const toDnsError: ({ cause, name, zone }: {
|
|
26
|
+
readonly cause: HttpClientError.HttpClientError | SchemaError;
|
|
27
|
+
readonly zone: string;
|
|
28
|
+
readonly name: string;
|
|
29
|
+
}) => Effect.Effect<DnsError>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const packageName = "@kumulo/dns-godaddy";
|
|
2
|
+
export { GodaddyHttpLive } from "./transport/http-client";
|
|
3
|
+
export { makeGodaddyDnsClient } from "./client/godaddy-dns";
|
|
4
|
+
export type { GodaddyDnsClient } from "./client/godaddy-dns";
|
|
5
|
+
export { godaddyDnsProviderLive } from "./provider/dns-provider";
|
|
6
|
+
export { godaddyApexNotCname, godaddyConfigRules, godaddyTtlMinimum } from "./config";
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { Effect, Layer, Option, Predicate, Redacted, Schema } from "effect";
|
|
2
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
4
|
+
import { AuthenticationFailed, DnsProvider, HttpTransportError, ProviderApiError, RateLimited, ResourceNotFound, ResponseDecodeError, classifyHttpError, crossFieldRule, isIpLiteral, makeProviderHttpClient, ownerTagOf, paginate, reconcileDns, recordKind } from "@kumulo/core";
|
|
5
|
+
import * as Schema$1 from "effect/Schema";
|
|
6
|
+
import * as SchemaIssue from "effect/SchemaIssue";
|
|
7
|
+
import * as HttpClientError from "effect/http/HttpClientError";
|
|
8
|
+
import * as HttpClientResponse from "effect/http/HttpClientResponse";
|
|
9
|
+
const _writeMethods = [
|
|
10
|
+
"POST",
|
|
11
|
+
"PUT",
|
|
12
|
+
"DELETE"
|
|
13
|
+
];
|
|
14
|
+
const _withIdempotencyKey = (request) => _writeMethods.includes(request.method) && request.headers["idempotency-key"] === void 0 ? HttpClientRequest.setHeader(request, "Idempotency-Key", crypto.randomUUID()) : request;
|
|
15
|
+
const _prepare = (baseUrl) => (request) => _withIdempotencyKey(URL.canParse(request.url) ? request : HttpClientRequest.prependUrl(request, baseUrl));
|
|
16
|
+
const makeGodaddyHttpClient = (options) => Effect.map(makeProviderHttpClient({
|
|
17
|
+
base: options.base,
|
|
18
|
+
authorize: (request) => Effect.succeed(HttpClientRequest.setHeader(request, "Authorization", `Bearer ${Redacted.value(options.token)}`))
|
|
19
|
+
}), (client) => HttpClient.mapRequest(client, _prepare(options.baseUrl ?? "https://api.godaddy.com/v3/domains")));
|
|
20
|
+
const GodaddyHttpLive = ({ baseUrl, token }) => Layer.effect(HttpClient.HttpClient, Effect.flatMap(HttpClient.HttpClient, (base) => makeGodaddyHttpClient({
|
|
21
|
+
base,
|
|
22
|
+
token,
|
|
23
|
+
baseUrl
|
|
24
|
+
})));
|
|
25
|
+
// src/errors.ts
|
|
26
|
+
const GodaddyError = Schema.Struct({
|
|
27
|
+
code: Schema.String,
|
|
28
|
+
message: Schema.optional(Schema.String),
|
|
29
|
+
fields: Schema.optional(Schema.Array(Schema.Struct({
|
|
30
|
+
code: Schema.optional(Schema.String),
|
|
31
|
+
message: Schema.optional(Schema.String),
|
|
32
|
+
path: Schema.optional(Schema.String),
|
|
33
|
+
pathRelated: Schema.optional(Schema.String)
|
|
34
|
+
})))
|
|
35
|
+
});
|
|
36
|
+
const GodaddyErrorLimit = Schema.Struct({
|
|
37
|
+
code: Schema.String,
|
|
38
|
+
message: Schema.optional(Schema.String),
|
|
39
|
+
retryAfterSec: Schema.Number,
|
|
40
|
+
fields: Schema.optional(Schema.Array(Schema.Struct({
|
|
41
|
+
code: Schema.optional(Schema.String),
|
|
42
|
+
message: Schema.optional(Schema.String),
|
|
43
|
+
path: Schema.optional(Schema.String)
|
|
44
|
+
})))
|
|
45
|
+
});
|
|
46
|
+
const _kind = "dns-record";
|
|
47
|
+
const _ref = (ctx) => `${ctx.zone}/${ctx.name}`;
|
|
48
|
+
const _describe = (body) => body === void 0 ? "no error body" : `${body.code}${body.message === void 0 ? "" : `: ${body.message}`}`;
|
|
49
|
+
const _decodeError = Schema.decodeUnknownOption(GodaddyError);
|
|
50
|
+
const _decodeLimit = Schema.decodeUnknownOption(GodaddyErrorLimit);
|
|
51
|
+
const _override = (ctx) => {
|
|
52
|
+
const parsed = Option.liftThrowable(JSON.parse)(ctx.body);
|
|
53
|
+
const body = Option.getOrUndefined(Option.flatMap(parsed, _decodeError));
|
|
54
|
+
const detail = _describe(body);
|
|
55
|
+
if (ctx.status === 401) return new AuthenticationFailed({ hint: `${ctx.ref}: GoDaddy rejected the token (${detail}); the API token is missing, expired or revoked` });
|
|
56
|
+
if (ctx.status === 403) return new AuthenticationFailed({ hint: `${ctx.ref}: GoDaddy forbade the request (${detail}); either the token lacks the domains.dns:update scope, or the account is not eligible for the DNS API (it needs at least one domain or a qualifying plan)` });
|
|
57
|
+
if (ctx.status === 404) return new ResourceNotFound({
|
|
58
|
+
kind: _kind,
|
|
59
|
+
ref: `${ctx.ref} (zone not in this GoDaddy account)`
|
|
60
|
+
});
|
|
61
|
+
if (ctx.status === 429) {
|
|
62
|
+
const seconds = Option.getOrUndefined(Option.flatMap(parsed, _decodeLimit))?.retryAfterSec;
|
|
63
|
+
return new RateLimited({
|
|
64
|
+
kind: _kind,
|
|
65
|
+
ref: ctx.ref,
|
|
66
|
+
retryAfter: ctx.retryAfter ?? (seconds === void 0 ? void 0 : String(seconds))
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (ctx.status === 422) return new ProviderApiError({
|
|
70
|
+
operation: `${_kind} ${ctx.ref} [${body?.code ?? "UNKNOWN"}]`,
|
|
71
|
+
status: ctx.status,
|
|
72
|
+
body: ctx.body
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const _asDnsError = (error) => {
|
|
76
|
+
if (Predicate.isTagged(error, "ResourceNotFound") || Predicate.isTagged(error, "ResourceConflict") || Predicate.isTagged(error, "AuthenticationFailed") || Predicate.isTagged(error, "RateLimited") || Predicate.isTagged(error, "ProviderApiError") || Predicate.isTagged(error, "ResponseDecodeError") || Predicate.isTagged(error, "HttpTransportError")) return error;
|
|
77
|
+
return new ProviderApiError({
|
|
78
|
+
operation: _kind,
|
|
79
|
+
status: 0,
|
|
80
|
+
body: error._tag
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const toDnsError = ({ cause, name, zone }) => {
|
|
84
|
+
const ref = _ref({
|
|
85
|
+
zone,
|
|
86
|
+
name
|
|
87
|
+
});
|
|
88
|
+
if (!HttpClientError.isHttpClientError(cause)) return Effect.succeed(new ResponseDecodeError({
|
|
89
|
+
endpoint: `${_kind}/${ref}`,
|
|
90
|
+
issue: cause.issue
|
|
91
|
+
}));
|
|
92
|
+
const response = cause.response;
|
|
93
|
+
if (response === void 0) return Effect.succeed(new HttpTransportError({ cause }));
|
|
94
|
+
return response.text.pipe(Effect.orElseSucceed(() => ""), Effect.map((body) => _asDnsError(classifyHttpError({
|
|
95
|
+
status: response.status,
|
|
96
|
+
body,
|
|
97
|
+
kind: _kind,
|
|
98
|
+
ref,
|
|
99
|
+
retryAfter: response.headers["retry-after"],
|
|
100
|
+
override: _override
|
|
101
|
+
}))));
|
|
102
|
+
};
|
|
103
|
+
// src/client/godaddy-dns.ts
|
|
104
|
+
const DnsRecordType = Schema$1.Literals([
|
|
105
|
+
"A",
|
|
106
|
+
"AAAA",
|
|
107
|
+
"CNAME",
|
|
108
|
+
"MX",
|
|
109
|
+
"TXT",
|
|
110
|
+
"NS",
|
|
111
|
+
"SRV",
|
|
112
|
+
"SOA",
|
|
113
|
+
"CAA"
|
|
114
|
+
]);
|
|
115
|
+
const DnsRecord = Schema$1.Struct({
|
|
116
|
+
recordId: Schema$1.String,
|
|
117
|
+
name: Schema$1.String,
|
|
118
|
+
type: DnsRecordType,
|
|
119
|
+
data: Schema$1.String,
|
|
120
|
+
ttl: Schema$1.Number,
|
|
121
|
+
priority: Schema$1.optionalKey(Schema$1.Number),
|
|
122
|
+
service: Schema$1.optionalKey(Schema$1.String),
|
|
123
|
+
port: Schema$1.optionalKey(Schema$1.Number),
|
|
124
|
+
weight: Schema$1.optionalKey(Schema$1.Number),
|
|
125
|
+
protocol: Schema$1.optionalKey(Schema$1.String),
|
|
126
|
+
flag: Schema$1.optionalKey(Schema$1.Number),
|
|
127
|
+
tag: Schema$1.optionalKey(Schema$1.String)
|
|
128
|
+
});
|
|
129
|
+
Schema$1.Struct({
|
|
130
|
+
name: Schema$1.String,
|
|
131
|
+
type: DnsRecordType,
|
|
132
|
+
data: Schema$1.String,
|
|
133
|
+
ttl: Schema$1.Number,
|
|
134
|
+
priority: Schema$1.optionalKey(Schema$1.Number),
|
|
135
|
+
service: Schema$1.optionalKey(Schema$1.String),
|
|
136
|
+
port: Schema$1.optionalKey(Schema$1.Number),
|
|
137
|
+
weight: Schema$1.optionalKey(Schema$1.Number),
|
|
138
|
+
protocol: Schema$1.optionalKey(Schema$1.String),
|
|
139
|
+
flag: Schema$1.optionalKey(Schema$1.Number),
|
|
140
|
+
tag: Schema$1.optionalKey(Schema$1.String)
|
|
141
|
+
});
|
|
142
|
+
const DnsRecordList = Schema$1.Struct({
|
|
143
|
+
items: Schema$1.Array(DnsRecord),
|
|
144
|
+
links: Schema$1.optionalKey(Schema$1.Array(Schema$1.Struct({
|
|
145
|
+
rel: Schema$1.String,
|
|
146
|
+
href: Schema$1.String
|
|
147
|
+
})))
|
|
148
|
+
});
|
|
149
|
+
const _recordsPath = (zone) => `/zones/${encodeURIComponent(zone)}/dns-records`;
|
|
150
|
+
const _recordPath = (input) => `${_recordsPath(input.zone)}/${encodeURIComponent(input.recordId)}`;
|
|
151
|
+
const _mapErrors = (input) => (effect) => Effect.catch(effect, (cause) => Effect.flatMap(toDnsError({
|
|
152
|
+
cause,
|
|
153
|
+
...input
|
|
154
|
+
}), Effect.fail));
|
|
155
|
+
const _maxPages = 1e3;
|
|
156
|
+
const _schemaFailure = (message) => new Schema$1.SchemaError(new SchemaIssue.InvalidValue({ message }));
|
|
157
|
+
const _pageSearch = (href) => new URL(href, "https://relative.invalid").search;
|
|
158
|
+
const _nextUrl = ({ list, zone }) => {
|
|
159
|
+
const href = list.links?.find((link) => link.rel === "next")?.href;
|
|
160
|
+
return href === void 0 ? void 0 : `${_recordsPath(zone)}${_pageSearch(href)}`;
|
|
161
|
+
};
|
|
162
|
+
const _listAll = ({ httpClient, zone }) => paginate({
|
|
163
|
+
initial: `${_recordsPath(zone)}?pageSize=100`,
|
|
164
|
+
fetch: (url) => httpClient.execute(HttpClientRequest.get(url)).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.flatMap(HttpClientResponse.schemaBodyJson(DnsRecordList))),
|
|
165
|
+
items: (list) => list.items,
|
|
166
|
+
next: ({ page }) => _nextUrl({
|
|
167
|
+
list: page,
|
|
168
|
+
zone
|
|
169
|
+
}),
|
|
170
|
+
maxPages: _maxPages
|
|
171
|
+
}).pipe(Effect.mapError((error) => error instanceof Schema$1.SchemaError || HttpClientError.isHttpClientError(error) ? error : _schemaFailure(`pagination did not terminate: ${error._tag}`)));
|
|
172
|
+
const _CreatedBody = Schema$1.Struct({ recordId: Schema$1.optionalKey(Schema$1.String) });
|
|
173
|
+
const _decodeCreatedBody = Schema$1.decodeUnknownEffect(Schema$1.fromJsonString(_CreatedBody));
|
|
174
|
+
const _recordIdFromLocation = (response) => Option.fromNullishOr(response.headers["location"]).pipe(Option.flatMap((location) => Option.fromNullishOr(location.split("?")[0]?.split("/").filter((s) => s !== "").pop())), Option.map(decodeURIComponent));
|
|
175
|
+
const _decodeCreated = (input) => (response) => response.text.pipe(Effect.flatMap((text) => text.trim() === "" ? Effect.succeed({}) : _decodeCreatedBody(text)), Effect.map((body) => Option.fromNullishOr(body.recordId).pipe(Option.orElse(() => _recordIdFromLocation(response)))), Effect.flatMap((recordId) => Option.match(recordId, {
|
|
176
|
+
onNone: () => Effect.fail(new HttpClientError.HttpClientError({ reason: new HttpClientError.DecodeError({
|
|
177
|
+
request: response.request,
|
|
178
|
+
response,
|
|
179
|
+
description: "created record has no id in body or Location header"
|
|
180
|
+
}) })),
|
|
181
|
+
onSome: (id) => Effect.succeed({
|
|
182
|
+
...input,
|
|
183
|
+
recordId: id
|
|
184
|
+
})
|
|
185
|
+
})));
|
|
186
|
+
const _decodeDeleted = (response) => response.status === 404 ? Effect.void : Effect.asVoid(HttpClientResponse.filterStatusOk(response));
|
|
187
|
+
const makeGodaddyDnsClient = (httpClient) => ({
|
|
188
|
+
listRecords: ({ zone }) => _listAll({
|
|
189
|
+
httpClient,
|
|
190
|
+
zone
|
|
191
|
+
}).pipe(_mapErrors({
|
|
192
|
+
zone,
|
|
193
|
+
name: "*"
|
|
194
|
+
})),
|
|
195
|
+
probe: ({ zone }) => httpClient.execute(HttpClientRequest.get(`${_recordsPath(zone)}?pageSize=1`)).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.asVoid, _mapErrors({
|
|
196
|
+
zone,
|
|
197
|
+
name: "*"
|
|
198
|
+
})),
|
|
199
|
+
createRecord: ({ zone, record }) => HttpClientRequest.post(_recordsPath(zone)).pipe(HttpClientRequest.bodyJson(record), Effect.mapError((error) => _schemaFailure(`could not encode the request body: ${error.message}`)), Effect.flatMap((request) => httpClient.execute(request)), Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.flatMap(_decodeCreated(record)), _mapErrors({
|
|
200
|
+
zone,
|
|
201
|
+
name: record.name
|
|
202
|
+
})),
|
|
203
|
+
replaceRecord: ({ zone, recordId, record }) => HttpClientRequest.put(_recordPath({
|
|
204
|
+
zone,
|
|
205
|
+
recordId
|
|
206
|
+
})).pipe(HttpClientRequest.bodyJson(record), Effect.mapError((error) => _schemaFailure(`could not encode the request body: ${error.message}`)), Effect.flatMap((request) => httpClient.execute(request)), Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.flatMap(HttpClientResponse.schemaBodyJson(DnsRecord)), _mapErrors({
|
|
207
|
+
zone,
|
|
208
|
+
name: record.name
|
|
209
|
+
})),
|
|
210
|
+
deleteRecord: (input) => httpClient.execute(HttpClientRequest.delete(_recordPath(input))).pipe(Effect.flatMap(_decodeDeleted), _mapErrors({
|
|
211
|
+
zone: input.zone,
|
|
212
|
+
name: input.recordId
|
|
213
|
+
}))
|
|
214
|
+
});
|
|
215
|
+
// src/provider/dns-provider.ts
|
|
216
|
+
const _APEX = "@";
|
|
217
|
+
const _normalize = ({ name, zone }) => {
|
|
218
|
+
const lowered = name.toLowerCase();
|
|
219
|
+
const apex = zone.toLowerCase();
|
|
220
|
+
if (lowered === "" || lowered === _APEX || lowered === apex) return _APEX;
|
|
221
|
+
return lowered.endsWith(`.${apex}`) ? lowered.slice(0, lowered.length - apex.length - 1) : lowered;
|
|
222
|
+
};
|
|
223
|
+
const _unquote = (data) => data.length >= 2 && data.startsWith("\"") && data.endsWith("\"") ? data.slice(1, -1) : data;
|
|
224
|
+
const _canonicalIpv6 = (data) => {
|
|
225
|
+
const url = Option.liftThrowable(() => new URL(`http://[${data}]`))();
|
|
226
|
+
return Option.match(url, {
|
|
227
|
+
onNone: () => data.toLowerCase(),
|
|
228
|
+
onSome: (u) => u.hostname
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
const _canonical = ({ type, value }) => {
|
|
232
|
+
const bare = _unquote(value);
|
|
233
|
+
if (type === "CNAME") return bare.toLowerCase().replace(/\.$/, "");
|
|
234
|
+
return type === "AAAA" ? _canonicalIpv6(bare) : bare;
|
|
235
|
+
};
|
|
236
|
+
const _isRecordType = Schema.is(DnsRecordType);
|
|
237
|
+
const _toZoneRecord = (record) => ({
|
|
238
|
+
id: record.recordId,
|
|
239
|
+
name: record.name,
|
|
240
|
+
type: record.type,
|
|
241
|
+
value: record.data,
|
|
242
|
+
ttl: record.ttl
|
|
243
|
+
});
|
|
244
|
+
const _unsupported = (record) => new ProviderApiError({
|
|
245
|
+
operation: "ensureRecords",
|
|
246
|
+
status: 422,
|
|
247
|
+
body: `unsupported record type ${record.type} at ${record.name}`
|
|
248
|
+
});
|
|
249
|
+
const _toInput = (record) => _isRecordType(record.type) ? Effect.succeed({
|
|
250
|
+
name: record.name,
|
|
251
|
+
type: record.type,
|
|
252
|
+
data: record.value,
|
|
253
|
+
ttl: record.ttl
|
|
254
|
+
}) : Effect.fail(_unsupported(record));
|
|
255
|
+
const _requireId = (record) => record.id === void 0 ? Effect.fail(new ProviderApiError({
|
|
256
|
+
operation: "godaddy record id",
|
|
257
|
+
status: 0,
|
|
258
|
+
body: `record ${record.name} has no id`
|
|
259
|
+
})) : Effect.succeed(record.id);
|
|
260
|
+
const makeGodaddyDnsAdapter = ({ dns, ttl }) => ({
|
|
261
|
+
ttl,
|
|
262
|
+
list: (zone) => Effect.map(dns.listRecords({ zone }), (records) => records.map(_toZoneRecord)),
|
|
263
|
+
create: ({ zone, record }) => Effect.flatMap(_toInput(record), (input) => Effect.asVoid(dns.createRecord({
|
|
264
|
+
zone,
|
|
265
|
+
record: input
|
|
266
|
+
}))),
|
|
267
|
+
update: ({ zone, existing, record }) => Effect.flatMap(Effect.all([_requireId(existing), _toInput(record)]), ([recordId, input]) => Effect.asVoid(dns.replaceRecord({
|
|
268
|
+
zone,
|
|
269
|
+
recordId,
|
|
270
|
+
record: input
|
|
271
|
+
}))),
|
|
272
|
+
delete: ({ zone, record }) => Effect.flatMap(_requireId(record), (recordId) => dns.deleteRecord({
|
|
273
|
+
zone,
|
|
274
|
+
recordId
|
|
275
|
+
})),
|
|
276
|
+
normalize: _normalize,
|
|
277
|
+
canonical: _canonical
|
|
278
|
+
});
|
|
279
|
+
const _isOwnershipRecord = (record) => ownerTagOf(record.target) !== void 0;
|
|
280
|
+
const _apexCname = ({ records, zone }) => records.find((r) => !_isOwnershipRecord(r) && _normalize({
|
|
281
|
+
name: r.name,
|
|
282
|
+
zone
|
|
283
|
+
}) === _APEX && recordKind(r.target) === "CNAME");
|
|
284
|
+
const _rejectApexCname = ({ records, zone }) => Option.match(Option.fromNullishOr(_apexCname({
|
|
285
|
+
records,
|
|
286
|
+
zone
|
|
287
|
+
})), {
|
|
288
|
+
onNone: () => Effect.void,
|
|
289
|
+
onSome: (record) => Effect.fail(new ProviderApiError({
|
|
290
|
+
operation: "ensureRecords",
|
|
291
|
+
status: 422,
|
|
292
|
+
body: `GoDaddy rejects a CNAME at the zone apex: ${zone} would point at ${record.target}; target an IP address instead`
|
|
293
|
+
}))
|
|
294
|
+
});
|
|
295
|
+
const makeGodaddyDnsProvider = (options) => {
|
|
296
|
+
const reconciler = reconcileDns(makeGodaddyDnsAdapter(options));
|
|
297
|
+
return {
|
|
298
|
+
ensureRecords: (zone, records) => Effect.andThen(_rejectApexCname({
|
|
299
|
+
records,
|
|
300
|
+
zone
|
|
301
|
+
}), reconciler.ensureRecords(zone, records)),
|
|
302
|
+
removeClusterRecords: reconciler.removeClusterRecords
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
const godaddyDnsProviderLive = (options) => Layer.succeed(DnsProvider, makeGodaddyDnsProvider(options));
|
|
306
|
+
// src/config.ts
|
|
307
|
+
const _reservedDnsTargets = [
|
|
308
|
+
"api_server",
|
|
309
|
+
"ingress",
|
|
310
|
+
"cdn"
|
|
311
|
+
];
|
|
312
|
+
const godaddyTtlMinimum = crossFieldRule({
|
|
313
|
+
check: (config) => config.dns.module === "godaddy" && config.dns.ttl !== void 0 && config.dns.ttl < 600 ? "GoDaddy requires dns.ttl >= 600" : void 0,
|
|
314
|
+
jsonSchema: [{
|
|
315
|
+
if: {
|
|
316
|
+
properties: { dns: {
|
|
317
|
+
properties: { module: { const: "godaddy" } },
|
|
318
|
+
required: ["module"]
|
|
319
|
+
} },
|
|
320
|
+
required: ["dns"]
|
|
321
|
+
},
|
|
322
|
+
then: { properties: { dns: { properties: { ttl: { minimum: 600 } } } } }
|
|
323
|
+
}]
|
|
324
|
+
});
|
|
325
|
+
const godaddyApexNotCname = crossFieldRule({
|
|
326
|
+
check: (config) => config.dns.module === "godaddy" && config.dns.records?.some((record) => (record.name === "@" || record.name === config.dns.zone) && !_reservedDnsTargets.includes(record.target) && !isIpLiteral(record.target)) === true ? "GoDaddy rejects an apex CNAME: dns.records at the zone apex must target an IP address" : void 0,
|
|
327
|
+
jsonSchema: []
|
|
328
|
+
});
|
|
329
|
+
const godaddyConfigRules = [godaddyTtlMinimum, godaddyApexNotCname];
|
|
330
|
+
// src/index.ts
|
|
331
|
+
const packageName = "@kumulo/dns-godaddy";
|
|
332
|
+
export { GodaddyHttpLive, godaddyApexNotCname, godaddyConfigRules, godaddyDnsProviderLive, godaddyTtlMinimum, makeGodaddyDnsClient, packageName };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import { DnsProvider } from "@kumulo/core";
|
|
3
|
+
import type { DesiredRecord, DnsAdapter, DnsError } from "@kumulo/core";
|
|
4
|
+
import type { GodaddyDnsClient } from "../client/godaddy-dns";
|
|
5
|
+
export interface GodaddyDnsProviderOptions {
|
|
6
|
+
readonly dns: GodaddyDnsClient;
|
|
7
|
+
readonly ttl?: number | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare const makeGodaddyDnsAdapter: ({ dns, ttl }: GodaddyDnsProviderOptions) => DnsAdapter;
|
|
10
|
+
export declare const makeGodaddyDnsProvider: (options: GodaddyDnsProviderOptions) => {
|
|
11
|
+
ensureRecords: (zone: string, records: ReadonlyArray<DesiredRecord>) => Effect.Effect<void, DnsError>;
|
|
12
|
+
removeClusterRecords: (zone: string, tag: import("@kumulo/core").ClusterTag) => Effect.Effect<void, DnsError>;
|
|
13
|
+
};
|
|
14
|
+
export declare const godaddyDnsProviderLive: (options: GodaddyDnsProviderOptions) => Layer.Layer<DnsProvider, never, never>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Effect, Layer, Redacted } from "effect";
|
|
2
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
export declare const GODADDY_API_BASE_URL = "https://api.godaddy.com/v3/domains";
|
|
4
|
+
export interface GodaddyHttpClientOptions {
|
|
5
|
+
readonly base: HttpClient.HttpClient;
|
|
6
|
+
readonly token: Redacted.Redacted<string>;
|
|
7
|
+
readonly baseUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const makeGodaddyHttpClient: (options: GodaddyHttpClientOptions) => Effect.Effect<HttpClient.HttpClient>;
|
|
10
|
+
export declare const GodaddyHttpLive: ({ baseUrl, token }: {
|
|
11
|
+
readonly token: Redacted.Redacted<string>;
|
|
12
|
+
readonly baseUrl?: string;
|
|
13
|
+
}) => Layer.Layer<HttpClient.HttpClient, never, HttpClient.HttpClient>;
|
package/package.json
CHANGED
|
@@ -1 +1,57 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@kumulo/dns-godaddy",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "GoDaddy DNS provider for kumulo.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "David Stahl-Gruber",
|
|
7
|
+
"homepage": "https://github.com/DwieDave/kumulo#readme",
|
|
8
|
+
"bugs": "https://github.com/DwieDave/kumulo/issues",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/DwieDave/kumulo.git",
|
|
12
|
+
"directory": "packages/godaddy/dns"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"godaddy",
|
|
16
|
+
"dns",
|
|
17
|
+
"effect",
|
|
18
|
+
"typescript"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.mjs",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@kumulo/core": "0.3.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"effect": "4.1.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@effect/vitest": "4.1.0",
|
|
48
|
+
"vitest": "5.0.5",
|
|
49
|
+
"effect": "4.1.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "bash ../../../scripts/build-package.sh",
|
|
53
|
+
"prepack": "node ../../../scripts/prepack-exports.mjs strip",
|
|
54
|
+
"postpack": "node ../../../scripts/prepack-exports.mjs restore",
|
|
55
|
+
"prepublishOnly": "bun run build"
|
|
56
|
+
}
|
|
57
|
+
}
|