cloudflare-ddns-sync 2.0.4 → 2.0.6

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 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,16 @@
1
-
2
1
  # Changelog
3
2
 
4
3
  ## v2
5
4
 
5
+ ### v2.0.6
6
+
7
+ - ⬆️ Update dependencies
8
+
9
+ ### v2.0.5
10
+
11
+ - 🚨 Replace tslint with eslint
12
+ - ⬆️ Update dependencies
13
+
6
14
  ### v2.0.4
7
15
 
8
16
  - 📝 Update links in README
@@ -29,7 +37,6 @@
29
37
 
30
38
  - ♻️ **Rewrite Cloudflare-DDNS-Sync in Typescript**
31
39
 
32
-
33
40
  ## v1
34
41
 
35
42
  ### v1.5.4
package/README.md CHANGED
@@ -5,12 +5,11 @@
5
5
  [![NPM](https://nodei.co/npm/cloudflare-ddns-sync.png)](https://www.npmjs.com/package/cloudflare-ddns-sync)
6
6
  [![NPM](https://nodei.co/npm/cloudflare-ddns-sync-cli.png)](https://www.npmjs.com/package/cloudflare-ddns-sync-cli)
7
7
 
8
-
9
8
  ## Overview
10
9
 
11
10
  Cloudflare-DDNS-Sync is a simple module that updates Cloudflare DNS records.
12
11
 
13
- For a more detailed overview, have a look at the [Documentation](https://cddnss.knaup.dev/)
12
+ For a more detailed overview, have a look at the [Documentation](https://cddnss.knaup.pw/)
14
13
 
15
14
  You may also have a look at the **official** [CLI version](https://www.npmjs.com/package/cloudflare-ddns-sync-cli) of Cloudflare-DDNS-Sync.
16
15
 
@@ -18,7 +17,7 @@ You may also have a look at the **official** [CLI version](https://www.npmjs.com
18
17
 
19
18
  ### Prerequisites
20
19
 
21
- - Node
20
+ - Node (14, 16, 18)
22
21
  - Cloudflare Account
23
22
 
24
23
  ### Installation
@@ -34,27 +33,27 @@ in your project folder.
34
33
  ## Usage
35
34
 
36
35
  > Hint: If a record is not existing, CDS will automatically create it when
37
- syncing.
36
+ > syncing.
38
37
 
39
38
  ### Javascript Example
40
39
 
41
40
  ```javascript
42
- const Cddnss = require('cloudflare-ddns-sync').default;
41
+ const Cddnss = require("cloudflare-ddns-sync").default;
43
42
 
44
- const cddnss = new Cddnss('your@email.com', '<your-cloudflare-api-key>');
43
+ const cddnss = new Cddnss("your@email.com", "<your-cloudflare-api-key>");
45
44
 
46
45
  const records = [
47
46
  {
48
- name: 'test-1.domain.com',
49
- type: 'A', // optional
50
- proxied: true, // optional
51
- ttl: 1, // optional
52
- priority: 0, // optional
53
- content: '1.2.3.4', // optional
47
+ name: "test-1.domain.com",
48
+ type: "A", // optional
49
+ proxied: true, // optional
50
+ ttl: 1, // optional
51
+ priority: 0, // optional
52
+ content: "1.2.3.4", // optional
54
53
  },
55
54
  {
56
- name: "test-2.domain.com"
57
- }
55
+ name: "test-2.domain.com",
56
+ },
58
57
  ];
59
58
 
60
59
  cddnss.syncRecords(records).then((result) => {
@@ -65,21 +64,24 @@ cddnss.syncRecords(records).then((result) => {
65
64
  ### Typescript Example
66
65
 
67
66
  ```typescript
68
- import Cddnss, {Record, RecordData} from 'cloudflare-ddns-sync';
67
+ import Cddnss, { Record, RecordData } from "cloudflare-ddns-sync";
69
68
 
70
- const cddnss: Cddnss = new Cddnss('your@email.com', '<your-cloudflare-api-key>');
69
+ const cddnss: Cddnss = new Cddnss(
70
+ "your@email.com",
71
+ "<your-cloudflare-api-key>"
72
+ );
71
73
 
72
74
  const records: Array<Record> = [
73
75
  {
74
- name: 'test-1.yourdomain.com',
75
- type: 'A', // optional
76
- proxied: true, // optional
77
- ttl: 1, // optional
78
- priority: 0, // optional
79
- content: '1.2.3.4', // optional
76
+ name: "test-1.yourdomain.com",
77
+ type: "A", // optional
78
+ proxied: true, // optional
79
+ ttl: 1, // optional
80
+ priority: 0, // optional
81
+ content: "1.2.3.4", // optional
80
82
  },
81
83
  {
82
- name: "test-2.yourdomain.com"
84
+ name: "test-2.yourdomain.com",
83
85
  },
84
86
  ];
85
87
 
@@ -108,18 +110,18 @@ Cron expressions have the following syntax:
108
110
 
109
111
  - getIp(): Promise\<string\>
110
112
  - getIpv6(): Promise\<string\>
111
- - getRecordDataForDomain(domain: string): Promise\<Array\<[RecordData](https://cddnss.knaup.dev/types/recorddata)\>\>
112
- - getRecordDataForDomains(domains: Array\<string\>): Promise\<[DomainRecordList](https://cddnss.knaup.dev/types/domainrecordlist)\>
113
- - getRecordDataForRecord(record: [Record](https://cddnss.knaup.dev/types/record)): Promise\<[RecordData](https://cddnss.knaup.dev/types/recorddata)\>
114
- - getRecordDataForRecords(records: Array\<[Record](https://cddnss.knaup.dev/types/record)\>): Promise\<Array\<[RecordData](https://cddnss.knaup.dev/types/recorddata)\>\>
113
+ - getRecordDataForDomain(domain: string): Promise\<Array\<[RecordData](https://cddnss.knaup.pw/types/recorddata)\>\>
114
+ - getRecordDataForDomains(domains: Array\<string\>): Promise\<[DomainRecordList](https://cddnss.knaup.pw/types/domainrecordlist)\>
115
+ - getRecordDataForRecord(record: [Record](https://cddnss.knaup.pw/types/record)): Promise\<[RecordData](https://cddnss.knaup.pw/types/recorddata)\>
116
+ - getRecordDataForRecords(records: Array\<[Record](https://cddnss.knaup.pw/types/record)\>): Promise\<Array\<[RecordData](https://cddnss.knaup.pw/types/recorddata)\>\>
115
117
  - removeRecord(recordName: string, recordType?: string): Promise\<void\>
116
118
  - stopSyncOnIpChange(changeListenerId: string): void
117
- - syncByCronTime(cronExpression: string, records: Array\<[Record](https://cddnss.knaup.dev/types/recorddata)\>, callback: [MultiSyncCallback](https://cddnss.knaup.dev/types/multisynccallback), ip?: string): [ScheduledTask](https://www.npmjs.com/package/node-cron#scheduledtask-methods)
118
- - syncOnIpChange(records: Array\<[Record](https://cddnss.knaup.dev/types/record)\>, callback: multisynccallback): Promise\<string\>
119
- - syncRecord(record: [Record](https://cddnss.knaup.dev/types/record), ip?: string): Promise\<[RecordData](https://cddnss.knaup.dev/types/recorddata)\>
120
- - syncRecords(records: Array\<[Record](https://cddnss.knaup.dev/types/record)\>, ip?: string): Promise\<Array\<[RecordData](https://cddnss.knaup.dev/types/recorddata)\>\>
119
+ - syncByCronTime(cronExpression: string, records: Array\<[Record](https://cddnss.knaup.pw/types/recorddata)\>, callback: [MultiSyncCallback](https://cddnss.knaup.pw/types/multisynccallback), ip?: string): [ScheduledTask](https://www.npmjs.com/package/node-cron#scheduledtask-methods)
120
+ - syncOnIpChange(records: Array\<[Record](https://cddnss.knaup.pw/types/record)\>, callback: multisynccallback): Promise\<string\>
121
+ - syncRecord(record: [Record](https://cddnss.knaup.pw/types/record), ip?: string): Promise\<[RecordData](https://cddnss.knaup.pw/types/recorddata)\>
122
+ - syncRecords(records: Array\<[Record](https://cddnss.knaup.pw/types/record)\>, ip?: string): Promise\<Array\<[RecordData](https://cddnss.knaup.pw/types/recorddata)\>\>
121
123
 
122
- For a more detailed view, have a look at the [Documentation](https://cddnss.knaup.dev/)
124
+ For a more detailed view, have a look at the [Documentation](https://cddnss.knaup.pw/)
123
125
 
124
126
  ## Get Your Cloudflare API Key
125
127
 
@@ -1,3 +1,3 @@
1
1
  import { RecordData } from './index';
2
- export declare type SingleSyncCallback = (syncResult: RecordData) => void;
3
- export declare type MultiSyncCallback = (syncResult: Array<RecordData>) => void;
2
+ export type SingleSyncCallback = (syncResult: RecordData) => void;
3
+ export type MultiSyncCallback = (syncResult: Array<RecordData>) => void;
@@ -1,4 +1,4 @@
1
1
  import { RecordData } from './index';
2
- export declare type DomainRecordList = {
2
+ export type DomainRecordList = {
3
3
  [domain: string]: Array<RecordData>;
4
4
  };
@@ -1,4 +1,4 @@
1
- export declare type Record = {
1
+ export type Record = {
2
2
  name: string;
3
3
  type?: string;
4
4
  proxied?: boolean;
@@ -1 +1 @@
1
- export declare type ZoneMap = Map<string, string>;
1
+ export type ZoneMap = Map<string, string>;
@@ -1,4 +1,4 @@
1
- export declare type RecordData = {
1
+ export type RecordData = {
2
2
  id: string;
3
3
  type: string;
4
4
  name: string;
@@ -13,7 +13,7 @@ export declare type RecordData = {
13
13
  created_on: string;
14
14
  meta: RecordMetaData;
15
15
  };
16
- export declare type RecordMetaData = {
16
+ export type RecordMetaData = {
17
17
  auto_added: boolean;
18
18
  managed_by_apps: boolean;
19
19
  managed_by_argo_tunnel: boolean;
@@ -1,4 +1,4 @@
1
- export declare type ZoneData = {
1
+ export type ZoneData = {
2
2
  id: string;
3
3
  name: string;
4
4
  status: string;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -27,10 +31,10 @@ class CloudflareDDNSSync {
27
31
  getIpv6() {
28
32
  return ip_utils_1.default.getIpv6();
29
33
  }
30
- async getRecordDataForDomain(domain) {
34
+ getRecordDataForDomain(domain) {
31
35
  return this.cloudflareClient.getRecordDataForDomain(domain);
32
36
  }
33
- async getRecordDataForDomains(domains) {
37
+ getRecordDataForDomains(domains) {
34
38
  return this.cloudflareClient.getRecordDataForDomains(domains);
35
39
  }
36
40
  getRecordDataForRecord(record) {
@@ -39,7 +43,7 @@ class CloudflareDDNSSync {
39
43
  getRecordDataForRecords(records) {
40
44
  return this.cloudflareClient.getRecordDataForRecords(records);
41
45
  }
42
- async removeRecord(recordName, recordType) {
46
+ removeRecord(recordName, recordType) {
43
47
  return this.cloudflareClient.removeRecordByNameAndType(recordName, recordType);
44
48
  }
45
49
  stopSyncOnIpChange(changeListenerId) {
@@ -63,10 +67,10 @@ class CloudflareDDNSSync {
63
67
  });
64
68
  return changeListenerId;
65
69
  }
66
- async syncRecord(record, ip) {
70
+ syncRecord(record, ip) {
67
71
  return this.cloudflareClient.syncRecord(record, ip);
68
72
  }
69
- async syncRecords(records, ip) {
73
+ syncRecords(records, ip) {
70
74
  return this.cloudflareClient.syncRecords(records, ip);
71
75
  }
72
76
  }
@@ -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
- 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]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(?:(?:(?:(?:[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})))?::))))$/;
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]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:(?:(?:(?:(?:[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
- else {
32
- const result = await this.createRecord(zoneId, record, ipToUse);
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
- else {
48
- const currentResult = await this.createRecord(zoneId, record, ipToUse);
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.filter((singleRecordData) => {
74
- return records.some((record) => {
75
- return record.name.toLowerCase() === singleRecordData.name.toLowerCase();
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(async (domain) => {
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 = Object.assign({}, record);
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 = Object.assign({}, record);
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
- async getZoneIdByRecordName(recordName) {
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
- return currentRecord.name.toLowerCase() === recordName.toLowerCase()
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
- else {
217
- await this.updateZoneMap();
218
- if (!this.zoneMap.has(domain)) {
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.map((record) => {
227
- return this.getDomainByRecordName(record.name);
228
- }).filter((domain, index, domainList) => {
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,7 +8,8 @@ class Cron {
8
8
  static createCronJob(cronExpression, callback) {
9
9
  const cronExpressionIsInvalid = !this.isValid(cronExpression);
10
10
  if (cronExpressionIsInvalid) {
11
- 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`);
11
+ // eslint-disable-next-line max-len
12
+ throw new Error(`'${cronExpression}' is not a valid cron expression.\nHere you can see how cron expressions work: https://cddnss.knaup.pw/cron-expression-syntax`);
12
13
  }
13
14
  return node_cron_1.default.schedule(cronExpression, () => {
14
15
  callback();
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -22,8 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
27
  };
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
- const public_ip_1 = __importDefault(require("public-ip"));
26
29
  const wimIp = __importStar(require("what-is-my-ip-address"));
30
+ const public_ip_1 = __importDefault(require("public-ip"));
27
31
  class IPUtils {
28
32
  static ipPollingDelay = 10 * 1000;
29
33
  static ipChangeEventListeners = new Map();
@@ -69,9 +73,12 @@ class IPUtils {
69
73
  IPUtils.ipChangeEventListeners.delete(eventListenerId);
70
74
  }
71
75
  static getRandomId() {
72
- const beginningRandomString = Math.random().toString(36).substr(2);
73
- const currentDateAsString = new Date().valueOf().toString(36);
74
- const endingRandomString = Math.random().toString(36).substr(2);
76
+ const beginningRandomString = Math.random().toString(36)
77
+ .substr(2);
78
+ const currentDateAsString = new Date().valueOf()
79
+ .toString(36);
80
+ const endingRandomString = Math.random().toString(36)
81
+ .substr(2);
75
82
  const randomString = beginningRandomString + currentDateAsString + endingRandomString;
76
83
  return randomString;
77
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-ddns-sync",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
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>",
@@ -13,14 +13,15 @@
13
13
  "dyndns",
14
14
  "sync"
15
15
  ],
16
- "homepage": "https://cddnss.knaup.dev/",
16
+ "homepage": "https://cddnss.knaup.pw/",
17
17
  "repository": {
18
18
  "type": "git",
19
19
  "url": "git://github.com:Steffen982/cloudflare-ddns-sync.git"
20
20
  },
21
21
  "scripts": {
22
22
  "build": "tsc",
23
- "lint": "tslint --project .",
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",
@@ -28,22 +29,24 @@
28
29
  },
29
30
  "dependencies": {
30
31
  "cloudflare": "2.9.1",
31
- "node-cron": "3.0.0",
32
+ "node-cron": "3.0.2",
32
33
  "parse-domain": "4.1.0",
33
34
  "public-ip": "4.0.4",
34
35
  "what-is-my-ip-address": "1.0.3"
35
36
  },
36
37
  "devDependencies": {
37
- "@types/chai": "4.2.22",
38
+ "@types/chai": "4.3.4",
38
39
  "@types/minimist": "1.2.2",
39
- "@types/mocha": "9.0.0",
40
- "@types/node": "16.11.7",
41
- "@types/node-cron": "3.0.0",
42
- "c8": "7.10.0",
43
- "chai": "4.3.4",
44
- "minimist": "1.2.5",
45
- "mocha": "9.1.3",
46
- "tslint": "6.1.3",
47
- "typescript": "4.4.4"
40
+ "@types/mocha": "9.1.1",
41
+ "@types/node": "18.11.17",
42
+ "@types/node-cron": "3.0.6",
43
+ "@typescript-eslint/eslint-plugin": "5.46.1",
44
+ "@typescript-eslint/parser": "5.46.1",
45
+ "c8": "7.12.0",
46
+ "chai": "4.3.7",
47
+ "eslint": "8.30.0",
48
+ "minimist": "1.2.7",
49
+ "mocha": "9.2.2",
50
+ "typescript": "4.9.4"
48
51
  }
49
52
  }