@rizom/brain 0.2.0-alpha.353 → 0.2.0-alpha.354
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/dist/brain.js +36 -36
- package/dist/chunks/{app-bmwdrf3f.js → app-m9hjd2pg.js} +2 -2
- package/dist/chunks/{index-3qsz79tf.js → index-4x71s1h0.js} +2 -2
- package/dist/chunks/{index-cyevdq6v.js → index-6m5e8k9d.js} +2 -2
- package/dist/chunks/{index-dj1tsbr6.js → index-dqe1320c.js} +3 -3
- package/dist/chunks/{index-dj1tsbr6.js.map → index-dqe1320c.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/model.js +37 -37
- package/dist/model.js.map +1 -1
- package/package.json +1 -1
- package/templates/deploy/scripts/update-dns.ts +32 -9
- /package/dist/chunks/{app-bmwdrf3f.js.map → app-m9hjd2pg.js.map} +0 -0
- /package/dist/chunks/{index-3qsz79tf.js.map → index-4x71s1h0.js.map} +0 -0
- /package/dist/chunks/{index-cyevdq6v.js.map → index-6m5e8k9d.js.map} +0 -0
package/package.json
CHANGED
|
@@ -13,24 +13,35 @@ const baseUrl = "https://api.cloudflare.com/client/v4";
|
|
|
13
13
|
|
|
14
14
|
interface CloudflareResult {
|
|
15
15
|
success: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface CloudflareRecordList extends CloudflareResult {
|
|
16
19
|
result?: Array<{ id: string }>;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
/**
|
|
20
23
|
* Copied verbatim into generated projects, so this stays dependency-free and
|
|
21
|
-
* checks the payload by hand. readJsonResponse returns unknown; asserting
|
|
22
|
-
*
|
|
23
|
-
* rather than failing here.
|
|
24
|
+
* checks the payload by hand. readJsonResponse returns unknown; asserting a
|
|
25
|
+
* response type onto it would let malformed error bodies pass silently.
|
|
24
26
|
*/
|
|
25
27
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
26
28
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
function
|
|
31
|
+
function readCloudflareSuccess(payload: unknown): boolean | undefined {
|
|
32
|
+
if (!isRecord(payload)) return undefined;
|
|
33
|
+
const success = payload["success"];
|
|
34
|
+
return typeof success === "boolean" ? success : undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function readCloudflareRecordList(
|
|
38
|
+
payload: unknown,
|
|
39
|
+
): CloudflareRecordList | undefined {
|
|
40
|
+
const success = readCloudflareSuccess(payload);
|
|
41
|
+
if (success === undefined) return undefined;
|
|
42
|
+
if (!success) return { success };
|
|
30
43
|
if (!isRecord(payload)) return undefined;
|
|
31
|
-
if (typeof payload["success"] !== "boolean") return undefined;
|
|
32
44
|
const result = payload["result"];
|
|
33
|
-
if (result === undefined) return { success: payload["success"] };
|
|
34
45
|
if (
|
|
35
46
|
!Array.isArray(result) ||
|
|
36
47
|
!result.every(
|
|
@@ -40,7 +51,19 @@ function readCloudflareResult(payload: unknown): CloudflareResult | undefined {
|
|
|
40
51
|
) {
|
|
41
52
|
return undefined;
|
|
42
53
|
}
|
|
43
|
-
return { success
|
|
54
|
+
return { success, result };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function readCloudflareMutation(
|
|
58
|
+
payload: unknown,
|
|
59
|
+
): CloudflareResult | undefined {
|
|
60
|
+
const success = readCloudflareSuccess(payload);
|
|
61
|
+
if (success === undefined) return undefined;
|
|
62
|
+
if (!success) return { success };
|
|
63
|
+
if (!isRecord(payload)) return undefined;
|
|
64
|
+
const result = payload["result"];
|
|
65
|
+
if (!isRecord(result) || typeof result["id"] !== "string") return undefined;
|
|
66
|
+
return { success };
|
|
44
67
|
}
|
|
45
68
|
|
|
46
69
|
async function findRecordId(
|
|
@@ -50,7 +73,7 @@ async function findRecordId(
|
|
|
50
73
|
const lookupUrl = `${baseUrl}/zones/${zoneId}/dns_records?type=${type}&name=${encodeURIComponent(name)}`;
|
|
51
74
|
const lookup = await fetch(lookupUrl, { headers });
|
|
52
75
|
const raw = await readJsonResponse(lookup, "Cloudflare DNS lookup");
|
|
53
|
-
const payload =
|
|
76
|
+
const payload = readCloudflareRecordList(raw);
|
|
54
77
|
if (!lookup.ok || !payload?.success) {
|
|
55
78
|
throw new Error(`Cloudflare DNS lookup failed: ${JSON.stringify(raw)}`);
|
|
56
79
|
}
|
|
@@ -79,7 +102,7 @@ async function upsertRecord(name: string): Promise<void> {
|
|
|
79
102
|
}),
|
|
80
103
|
});
|
|
81
104
|
const raw = await readJsonResponse(response, "Cloudflare DNS upsert");
|
|
82
|
-
const result =
|
|
105
|
+
const result = readCloudflareMutation(raw);
|
|
83
106
|
if (!response.ok || !result?.success) {
|
|
84
107
|
throw new Error(`Cloudflare DNS upsert failed: ${JSON.stringify(raw)}`);
|
|
85
108
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|