cloudflare-ddns-sync 2.0.4 → 2.0.5
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/.eslintrc.json +229 -0
- package/CHANGELOG.md +5 -2
- package/dist/index.js +5 -5
- package/dist/lib/cloudflare-client.js +26 -41
- package/dist/lib/cron.js +1 -0
- package/dist/lib/ip-utils.js +7 -4
- package/package.json +12 -8
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"es2021": true,
|
|
4
|
+
"node": true
|
|
5
|
+
},
|
|
6
|
+
"extends": [
|
|
7
|
+
"eslint:recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended"
|
|
9
|
+
],
|
|
10
|
+
"parser": "@typescript-eslint/parser",
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"ecmaVersion": "latest",
|
|
13
|
+
"sourceType": "module"
|
|
14
|
+
},
|
|
15
|
+
"plugins": [
|
|
16
|
+
"@typescript-eslint"
|
|
17
|
+
],
|
|
18
|
+
"rules": {
|
|
19
|
+
"@typescript-eslint/ban-types": "off",
|
|
20
|
+
"@typescript-eslint/indent": ["error", 2],
|
|
21
|
+
"@typescript-eslint/no-shadow": "error",
|
|
22
|
+
"accessor-pairs": "error",
|
|
23
|
+
"array-bracket-newline": "error",
|
|
24
|
+
"array-bracket-spacing": "error",
|
|
25
|
+
"array-callback-return": "error",
|
|
26
|
+
"array-element-newline": "error",
|
|
27
|
+
"arrow-body-style": "error",
|
|
28
|
+
"arrow-parens": "error",
|
|
29
|
+
"arrow-spacing": "error",
|
|
30
|
+
"block-scoped-var": "error",
|
|
31
|
+
"block-spacing": "error",
|
|
32
|
+
"brace-style": "error",
|
|
33
|
+
"camelcase": "warn",
|
|
34
|
+
"capitalized-comments": "off",
|
|
35
|
+
"class-methods-use-this": "off",
|
|
36
|
+
"comma-dangle": ["error", "always-multiline"],
|
|
37
|
+
"comma-spacing": "error",
|
|
38
|
+
"comma-style": "error",
|
|
39
|
+
"complexity": "error",
|
|
40
|
+
"computed-property-spacing": "error",
|
|
41
|
+
"consistent-return": "error",
|
|
42
|
+
"consistent-this": "error",
|
|
43
|
+
"curly": "error",
|
|
44
|
+
"default-case": "error",
|
|
45
|
+
"default-case-last": "error",
|
|
46
|
+
"default-param-last": "error",
|
|
47
|
+
"dot-location": ["error", "property"],
|
|
48
|
+
"dot-notation": "error",
|
|
49
|
+
"eol-last": "error",
|
|
50
|
+
"eqeqeq": "error",
|
|
51
|
+
"func-call-spacing": "error",
|
|
52
|
+
"func-name-matching": "error",
|
|
53
|
+
"func-names": "error",
|
|
54
|
+
"func-style": ["error", "declaration", {
|
|
55
|
+
"allowArrowFunctions": true
|
|
56
|
+
}],
|
|
57
|
+
"function-call-argument-newline": ["error", "consistent"],
|
|
58
|
+
"function-paren-newline": "error",
|
|
59
|
+
"generator-star-spacing": "error",
|
|
60
|
+
"grouped-accessor-pairs": "error",
|
|
61
|
+
"guard-for-in": "error",
|
|
62
|
+
"id-denylist": "error",
|
|
63
|
+
"id-length": "off",
|
|
64
|
+
"id-match": "error",
|
|
65
|
+
"implicit-arrow-linebreak": "error",
|
|
66
|
+
"indent": "off",
|
|
67
|
+
"init-declarations": "off",
|
|
68
|
+
"key-spacing": "error",
|
|
69
|
+
"keyword-spacing": "error",
|
|
70
|
+
"line-comment-position": "error",
|
|
71
|
+
"linebreak-style": "error",
|
|
72
|
+
"lines-around-comment": "off",
|
|
73
|
+
"lines-between-class-members": "off",
|
|
74
|
+
"max-classes-per-file": "error",
|
|
75
|
+
"max-depth": "error",
|
|
76
|
+
"max-len": ["error", 150],
|
|
77
|
+
"max-lines": ["error", 1000],
|
|
78
|
+
"max-lines-per-function": "off",
|
|
79
|
+
"max-nested-callbacks": "error",
|
|
80
|
+
"max-params": ["warn", {"max": 4}],
|
|
81
|
+
"max-statements": "off",
|
|
82
|
+
"max-statements-per-line": "off",
|
|
83
|
+
"multiline-comment-style": "off",
|
|
84
|
+
"multiline-ternary": "off",
|
|
85
|
+
"new-cap": "error",
|
|
86
|
+
"new-parens": "error",
|
|
87
|
+
"newline-per-chained-call": "error",
|
|
88
|
+
"no-alert": "error",
|
|
89
|
+
"no-array-constructor": "error",
|
|
90
|
+
"no-await-in-loop": "off",
|
|
91
|
+
"no-bitwise": "error",
|
|
92
|
+
"no-caller": "error",
|
|
93
|
+
"no-confusing-arrow": "error",
|
|
94
|
+
"no-console": "error",
|
|
95
|
+
"no-constructor-return": "error",
|
|
96
|
+
"no-continue": "error",
|
|
97
|
+
"no-div-regex": "error",
|
|
98
|
+
"no-duplicate-imports": "error",
|
|
99
|
+
"no-else-return": "error",
|
|
100
|
+
"no-empty-function": "error",
|
|
101
|
+
"no-eq-null": "error",
|
|
102
|
+
"no-eval": "error",
|
|
103
|
+
"no-extend-native": "error",
|
|
104
|
+
"no-extra-bind": "error",
|
|
105
|
+
"no-extra-label": "error",
|
|
106
|
+
"no-extra-parens": "off",
|
|
107
|
+
"no-floating-decimal": "error",
|
|
108
|
+
"no-implicit-coercion": "error",
|
|
109
|
+
"no-implicit-globals": "error",
|
|
110
|
+
"no-implied-eval": "error",
|
|
111
|
+
"no-inline-comments": "error",
|
|
112
|
+
"no-invalid-this": "error",
|
|
113
|
+
"no-iterator": "error",
|
|
114
|
+
"no-label-var": "error",
|
|
115
|
+
"no-labels": "error",
|
|
116
|
+
"no-lone-blocks": "error",
|
|
117
|
+
"no-lonely-if": "error",
|
|
118
|
+
"no-loop-func": "error",
|
|
119
|
+
"no-magic-numbers": "off",
|
|
120
|
+
"no-mixed-operators": "error",
|
|
121
|
+
"no-multi-assign": "error",
|
|
122
|
+
"no-multi-spaces": "error",
|
|
123
|
+
"no-multi-str": "error",
|
|
124
|
+
"no-multiple-empty-lines": "error",
|
|
125
|
+
"no-negated-condition": "error",
|
|
126
|
+
"no-nested-ternary": "error",
|
|
127
|
+
"no-new": "error",
|
|
128
|
+
"no-new-func": "error",
|
|
129
|
+
"no-new-object": "error",
|
|
130
|
+
"no-new-wrappers": "error",
|
|
131
|
+
"no-octal-escape": "error",
|
|
132
|
+
"no-param-reassign": "error",
|
|
133
|
+
"no-plusplus": "off",
|
|
134
|
+
"no-promise-executor-return": "error",
|
|
135
|
+
"no-proto": "error",
|
|
136
|
+
"no-restricted-exports": "error",
|
|
137
|
+
"no-restricted-globals": "error",
|
|
138
|
+
"no-restricted-imports": "error",
|
|
139
|
+
"no-restricted-properties": "error",
|
|
140
|
+
"no-restricted-syntax": "error",
|
|
141
|
+
"no-return-assign": "error",
|
|
142
|
+
"no-return-await": "error",
|
|
143
|
+
"no-script-url": "error",
|
|
144
|
+
"no-self-compare": "error",
|
|
145
|
+
"no-sequences": "error",
|
|
146
|
+
"no-shadow": "off",
|
|
147
|
+
"no-tabs": "error",
|
|
148
|
+
"no-template-curly-in-string": "error",
|
|
149
|
+
"no-ternary": "off",
|
|
150
|
+
"no-throw-literal": "error",
|
|
151
|
+
"no-trailing-spaces": "error",
|
|
152
|
+
"no-undef-init": "error",
|
|
153
|
+
"no-undefined": "off",
|
|
154
|
+
"no-underscore-dangle": "error",
|
|
155
|
+
"no-unmodified-loop-condition": "error",
|
|
156
|
+
"no-unneeded-ternary": "error",
|
|
157
|
+
"no-unreachable-loop": "error",
|
|
158
|
+
"no-unused-expressions": "error",
|
|
159
|
+
"no-unused-private-class-members": "error",
|
|
160
|
+
"no-use-before-define": "off",
|
|
161
|
+
"no-useless-call": "error",
|
|
162
|
+
"no-useless-computed-key": "error",
|
|
163
|
+
"no-useless-concat": "error",
|
|
164
|
+
"no-useless-constructor": "error",
|
|
165
|
+
"no-useless-rename": "error",
|
|
166
|
+
"no-useless-return": "error",
|
|
167
|
+
"no-var": "error",
|
|
168
|
+
"no-void": "error",
|
|
169
|
+
"no-warning-comments": "error",
|
|
170
|
+
"no-whitespace-before-property": "error",
|
|
171
|
+
"nonblock-statement-body-position": "error",
|
|
172
|
+
"object-curly-newline": "error",
|
|
173
|
+
"object-curly-spacing": "error",
|
|
174
|
+
"object-property-newline": "error",
|
|
175
|
+
"object-shorthand": ["error", "never"],
|
|
176
|
+
"one-var": ["error", "never"],
|
|
177
|
+
"operator-assignment": "error",
|
|
178
|
+
"operator-linebreak": ["error", "before"],
|
|
179
|
+
"padded-blocks": ["error", "never"],
|
|
180
|
+
"padding-line-between-statements": "error",
|
|
181
|
+
"prefer-arrow-callback": "error",
|
|
182
|
+
"prefer-const": "error",
|
|
183
|
+
"prefer-destructuring": "error",
|
|
184
|
+
"prefer-exponentiation-operator": "error",
|
|
185
|
+
"prefer-named-capture-group": "off",
|
|
186
|
+
"prefer-numeric-literals": "error",
|
|
187
|
+
"prefer-object-spread": "error",
|
|
188
|
+
"prefer-promise-reject-errors": "error",
|
|
189
|
+
"prefer-regex-literals": "error",
|
|
190
|
+
"prefer-rest-params": "error",
|
|
191
|
+
"prefer-spread": "error",
|
|
192
|
+
"prefer-template": "error",
|
|
193
|
+
"quote-props": ["error", "as-needed"],
|
|
194
|
+
"quotes": ["error", "single"],
|
|
195
|
+
"radix": "error",
|
|
196
|
+
"require-atomic-updates": "error",
|
|
197
|
+
"require-await": "error",
|
|
198
|
+
"require-unicode-regexp": "error",
|
|
199
|
+
"rest-spread-spacing": "error",
|
|
200
|
+
"semi": "error",
|
|
201
|
+
"semi-spacing": "error",
|
|
202
|
+
"semi-style": "error",
|
|
203
|
+
"sort-imports": ["error", {
|
|
204
|
+
"ignoreCase": false,
|
|
205
|
+
"ignoreDeclarationSort": false,
|
|
206
|
+
"ignoreMemberSort": false,
|
|
207
|
+
"allowSeparatedGroups": true
|
|
208
|
+
}],
|
|
209
|
+
"sort-keys": "off",
|
|
210
|
+
"sort-vars": "error",
|
|
211
|
+
"space-before-blocks": "error",
|
|
212
|
+
"space-before-function-paren": ["error", "never"],
|
|
213
|
+
"space-in-parens": "error",
|
|
214
|
+
"space-infix-ops": "error",
|
|
215
|
+
"space-unary-ops": "error",
|
|
216
|
+
"spaced-comment": "error",
|
|
217
|
+
"strict": "error",
|
|
218
|
+
"switch-colon-spacing": "error",
|
|
219
|
+
"symbol-description": "error",
|
|
220
|
+
"template-curly-spacing": "error",
|
|
221
|
+
"template-tag-spacing": "error",
|
|
222
|
+
"unicode-bom": "error",
|
|
223
|
+
"vars-on-top": "error",
|
|
224
|
+
"wrap-iife": "error",
|
|
225
|
+
"wrap-regex": "error",
|
|
226
|
+
"yield-star-spacing": "error",
|
|
227
|
+
"yoda": "error"
|
|
228
|
+
}
|
|
229
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
1
|
# Changelog
|
|
3
2
|
|
|
4
3
|
## v2
|
|
5
4
|
|
|
5
|
+
### v2.0.5
|
|
6
|
+
|
|
7
|
+
- 🚨 Replace tslint with eslint
|
|
8
|
+
- ⬆️ Update dependencies
|
|
9
|
+
|
|
6
10
|
### v2.0.4
|
|
7
11
|
|
|
8
12
|
- 📝 Update links in README
|
|
@@ -29,7 +33,6 @@
|
|
|
29
33
|
|
|
30
34
|
- ♻️ **Rewrite Cloudflare-DDNS-Sync in Typescript**
|
|
31
35
|
|
|
32
|
-
|
|
33
36
|
## v1
|
|
34
37
|
|
|
35
38
|
### v1.5.4
|
package/dist/index.js
CHANGED
|
@@ -27,10 +27,10 @@ class CloudflareDDNSSync {
|
|
|
27
27
|
getIpv6() {
|
|
28
28
|
return ip_utils_1.default.getIpv6();
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
getRecordDataForDomain(domain) {
|
|
31
31
|
return this.cloudflareClient.getRecordDataForDomain(domain);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
getRecordDataForDomains(domains) {
|
|
34
34
|
return this.cloudflareClient.getRecordDataForDomains(domains);
|
|
35
35
|
}
|
|
36
36
|
getRecordDataForRecord(record) {
|
|
@@ -39,7 +39,7 @@ class CloudflareDDNSSync {
|
|
|
39
39
|
getRecordDataForRecords(records) {
|
|
40
40
|
return this.cloudflareClient.getRecordDataForRecords(records);
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
removeRecord(recordName, recordType) {
|
|
43
43
|
return this.cloudflareClient.removeRecordByNameAndType(recordName, recordType);
|
|
44
44
|
}
|
|
45
45
|
stopSyncOnIpChange(changeListenerId) {
|
|
@@ -63,10 +63,10 @@ class CloudflareDDNSSync {
|
|
|
63
63
|
});
|
|
64
64
|
return changeListenerId;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
syncRecord(record, ip) {
|
|
67
67
|
return this.cloudflareClient.syncRecord(record, ip);
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
syncRecords(records, ip) {
|
|
70
70
|
return this.cloudflareClient.syncRecords(records, ip);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const cloudflare_1 = __importDefault(require("cloudflare"));
|
|
7
6
|
const parse_domain_1 = require("parse-domain");
|
|
7
|
+
const cloudflare_1 = __importDefault(require("cloudflare"));
|
|
8
8
|
const ip_utils_1 = __importDefault(require("./ip-utils"));
|
|
9
|
-
const ipv4Regex = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])
|
|
10
|
-
|
|
9
|
+
const ipv4Regex = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/u;
|
|
10
|
+
// eslint-disable-next-line max-len
|
|
11
|
+
const ipv6Regex = /^(?:(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-fA-F]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,1}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,2}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,3}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:[0-9a-fA-F]{1,4})):)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,4}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,5}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,6}(?:(?:[0-9a-fA-F]{1,4})))?::))))$/u;
|
|
11
12
|
class CloudflareClient {
|
|
12
13
|
cloudflare;
|
|
13
14
|
zoneMap = new Map();
|
|
@@ -28,10 +29,8 @@ class CloudflareClient {
|
|
|
28
29
|
const result = await this.updateRecord(zoneId, recordId, record, ipToUse);
|
|
29
30
|
return result;
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
32
|
+
const result = await this.createRecord(zoneId, record, ipToUse);
|
|
33
|
+
return result;
|
|
35
34
|
}
|
|
36
35
|
async syncRecords(records, ip) {
|
|
37
36
|
const recordIds = await this.getRecordIdsForRecords(records);
|
|
@@ -44,10 +43,8 @@ class CloudflareClient {
|
|
|
44
43
|
const currentResult = await this.updateRecord(zoneId, recordId, record, ipToUse);
|
|
45
44
|
return currentResult;
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return currentResult;
|
|
50
|
-
}
|
|
46
|
+
const currentResult = await this.createRecord(zoneId, record, ipToUse);
|
|
47
|
+
return currentResult;
|
|
51
48
|
});
|
|
52
49
|
const results = await Promise.all(resultPromises);
|
|
53
50
|
return results;
|
|
@@ -61,20 +58,16 @@ class CloudflareClient {
|
|
|
61
58
|
async getRecordDataForRecord(record) {
|
|
62
59
|
const domain = this.getDomainByRecordName(record.name);
|
|
63
60
|
const recordDataForDomain = await this.getRecordsByDomain(domain);
|
|
64
|
-
const recordData = recordDataForDomain.find((singleRecordData) =>
|
|
65
|
-
return record.name.toLowerCase() === singleRecordData.name.toLowerCase();
|
|
66
|
-
});
|
|
61
|
+
const recordData = recordDataForDomain.find((singleRecordData) => record.name.toLowerCase() === singleRecordData.name.toLowerCase());
|
|
67
62
|
return recordData;
|
|
68
63
|
}
|
|
69
64
|
async getRecordDataForRecords(records) {
|
|
70
65
|
const domains = this.getDomainsFromRecords(records);
|
|
71
66
|
const recordDataPromises = domains.map(async (domain) => {
|
|
72
67
|
const recordDataForDomain = await this.getRecordsByDomain(domain);
|
|
73
|
-
const recordDataForDomainFilteredByRecords = recordDataForDomain
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
});
|
|
68
|
+
const recordDataForDomainFilteredByRecords = recordDataForDomain
|
|
69
|
+
.filter((singleRecordData) => records
|
|
70
|
+
.some((record) => record.name.toLowerCase() === singleRecordData.name.toLowerCase()));
|
|
78
71
|
return recordDataForDomainFilteredByRecords;
|
|
79
72
|
});
|
|
80
73
|
const recordDataForDomains = await Promise.all(recordDataPromises);
|
|
@@ -82,9 +75,7 @@ class CloudflareClient {
|
|
|
82
75
|
return recordData;
|
|
83
76
|
}
|
|
84
77
|
async getRecordDataForDomains(domains) {
|
|
85
|
-
const recordDataPromises = domains.map(
|
|
86
|
-
return this.getRecordDataForDomain(domain);
|
|
87
|
-
});
|
|
78
|
+
const recordDataPromises = domains.map((domain) => this.getRecordDataForDomain(domain));
|
|
88
79
|
const recordDataForDomains = await Promise.all(recordDataPromises);
|
|
89
80
|
const recordData = {};
|
|
90
81
|
recordDataForDomains.forEach((recordDataForDomain, index) => {
|
|
@@ -97,7 +88,7 @@ class CloudflareClient {
|
|
|
97
88
|
return recordData;
|
|
98
89
|
}
|
|
99
90
|
async createRecord(zoneId, record, ip) {
|
|
100
|
-
const copyOfRecord =
|
|
91
|
+
const copyOfRecord = { ...record };
|
|
101
92
|
copyOfRecord.name = record.name.toLowerCase();
|
|
102
93
|
copyOfRecord.content = copyOfRecord.content ? copyOfRecord.content : ip;
|
|
103
94
|
copyOfRecord.type = copyOfRecord.type ? copyOfRecord.type : 'A';
|
|
@@ -124,7 +115,7 @@ class CloudflareClient {
|
|
|
124
115
|
return response.result;
|
|
125
116
|
}
|
|
126
117
|
async updateRecord(zoneId, recordId, record, ip) {
|
|
127
|
-
const copyOfRecord =
|
|
118
|
+
const copyOfRecord = { ...record };
|
|
128
119
|
copyOfRecord.name = record.name.toLowerCase();
|
|
129
120
|
copyOfRecord.content = copyOfRecord.content ? copyOfRecord.content : ip;
|
|
130
121
|
copyOfRecord.type = copyOfRecord.type ? copyOfRecord.type : 'A';
|
|
@@ -162,17 +153,15 @@ class CloudflareClient {
|
|
|
162
153
|
const record = await this.getRecordByNameAndType(recordName, recordType);
|
|
163
154
|
return record.id;
|
|
164
155
|
}
|
|
165
|
-
|
|
156
|
+
getZoneIdByRecordName(recordName) {
|
|
166
157
|
const domain = this.getDomainByRecordName(recordName);
|
|
167
158
|
return this.getZoneIdByDomain(domain);
|
|
168
159
|
}
|
|
169
160
|
async getRecordByNameAndType(recordName, recordType) {
|
|
170
161
|
const domain = this.getDomainByRecordName(recordName);
|
|
171
162
|
const records = await this.getRecordsByDomain(domain);
|
|
172
|
-
const record = records.find((currentRecord) =>
|
|
173
|
-
|
|
174
|
-
&& currentRecord.type.toLowerCase() === recordType.toLowerCase();
|
|
175
|
-
});
|
|
163
|
+
const record = records.find((currentRecord) => currentRecord.name.toLowerCase() === recordName.toLowerCase()
|
|
164
|
+
&& currentRecord.type.toLowerCase() === recordType.toLowerCase());
|
|
176
165
|
const recordNotFound = record === undefined;
|
|
177
166
|
if (recordNotFound) {
|
|
178
167
|
throw new Error(`Record '${recordName}' not found.`);
|
|
@@ -213,21 +202,17 @@ class CloudflareClient {
|
|
|
213
202
|
const zoneId = this.zoneMap.get(domain.toLowerCase());
|
|
214
203
|
return zoneId;
|
|
215
204
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
throw new Error(`Could not find domain '${domain}'. Make sure the domain is set up for your cloudflare account.`);
|
|
220
|
-
}
|
|
221
|
-
const zoneId = this.zoneMap.get(domain.toLowerCase());
|
|
222
|
-
return zoneId;
|
|
205
|
+
await this.updateZoneMap();
|
|
206
|
+
if (!this.zoneMap.has(domain)) {
|
|
207
|
+
throw new Error(`Could not find domain '${domain}'. Make sure the domain is set up for your cloudflare account.`);
|
|
223
208
|
}
|
|
209
|
+
const zoneId = this.zoneMap.get(domain.toLowerCase());
|
|
210
|
+
return zoneId;
|
|
224
211
|
}
|
|
225
212
|
getDomainsFromRecords(records) {
|
|
226
|
-
const domains = records
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return domainList.indexOf(domain.toLowerCase()) === index;
|
|
230
|
-
});
|
|
213
|
+
const domains = records
|
|
214
|
+
.map((record) => this.getDomainByRecordName(record.name))
|
|
215
|
+
.filter((domain, index, domainList) => domainList.indexOf(domain.toLowerCase()) === index);
|
|
231
216
|
return domains;
|
|
232
217
|
}
|
|
233
218
|
getDomainByRecordName(recordName) {
|
package/dist/lib/cron.js
CHANGED
|
@@ -8,6 +8,7 @@ class Cron {
|
|
|
8
8
|
static createCronJob(cronExpression, callback) {
|
|
9
9
|
const cronExpressionIsInvalid = !this.isValid(cronExpression);
|
|
10
10
|
if (cronExpressionIsInvalid) {
|
|
11
|
+
// eslint-disable-next-line max-len
|
|
11
12
|
throw new Error(`'${cronExpression}' is not a valid cron expression.\nHere you can see how cron expressions work: https://cddnss.knaup.dev/cron-expression-syntax`);
|
|
12
13
|
}
|
|
13
14
|
return node_cron_1.default.schedule(cronExpression, () => {
|
package/dist/lib/ip-utils.js
CHANGED
|
@@ -22,8 +22,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const public_ip_1 = __importDefault(require("public-ip"));
|
|
26
25
|
const wimIp = __importStar(require("what-is-my-ip-address"));
|
|
26
|
+
const public_ip_1 = __importDefault(require("public-ip"));
|
|
27
27
|
class IPUtils {
|
|
28
28
|
static ipPollingDelay = 10 * 1000;
|
|
29
29
|
static ipChangeEventListeners = new Map();
|
|
@@ -69,9 +69,12 @@ class IPUtils {
|
|
|
69
69
|
IPUtils.ipChangeEventListeners.delete(eventListenerId);
|
|
70
70
|
}
|
|
71
71
|
static getRandomId() {
|
|
72
|
-
const beginningRandomString = Math.random().toString(36)
|
|
73
|
-
|
|
74
|
-
const
|
|
72
|
+
const beginningRandomString = Math.random().toString(36)
|
|
73
|
+
.substr(2);
|
|
74
|
+
const currentDateAsString = new Date().valueOf()
|
|
75
|
+
.toString(36);
|
|
76
|
+
const endingRandomString = Math.random().toString(36)
|
|
77
|
+
.substr(2);
|
|
75
78
|
const randomString = beginningRandomString + currentDateAsString + endingRandomString;
|
|
76
79
|
return randomString;
|
|
77
80
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudflare-ddns-sync",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "A simple module to update DNS records on Cloudflare whenever you want",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Steffen Knaup <SteffenKnaup@hotmail.de>",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsc",
|
|
23
|
-
"lint": "
|
|
23
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
24
|
+
"lint:fix": "eslint --fix \"src/**/*.ts\"",
|
|
24
25
|
"test": "c8 mocha dist/tests/*.js --timeout 15000 --exit",
|
|
25
26
|
"test:coverage": "npm run test:coverage-check && npm run test:coverage-report",
|
|
26
27
|
"test:coverage-check": "c8 check-coverage --lines 70 --functions 70 --branches 70",
|
|
@@ -34,16 +35,19 @@
|
|
|
34
35
|
"what-is-my-ip-address": "1.0.3"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@types/chai": "4.
|
|
38
|
+
"@types/chai": "4.3.0",
|
|
38
39
|
"@types/minimist": "1.2.2",
|
|
39
40
|
"@types/mocha": "9.0.0",
|
|
40
|
-
"@types/node": "16.11.
|
|
41
|
-
"@types/node-cron": "3.0.
|
|
42
|
-
"
|
|
41
|
+
"@types/node": "16.11.20",
|
|
42
|
+
"@types/node-cron": "3.0.1",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "5.10.0",
|
|
44
|
+
"@typescript-eslint/parser": "5.10.0",
|
|
45
|
+
"c8": "7.11.0",
|
|
43
46
|
"chai": "4.3.4",
|
|
47
|
+
"eslint": "8.7.0",
|
|
44
48
|
"minimist": "1.2.5",
|
|
45
|
-
"mocha": "9.1.
|
|
49
|
+
"mocha": "9.1.4",
|
|
46
50
|
"tslint": "6.1.3",
|
|
47
|
-
"typescript": "4.
|
|
51
|
+
"typescript": "4.5.4"
|
|
48
52
|
}
|
|
49
53
|
}
|