@nodeart/cloudflare-provisioning 1.0.15 → 1.0.16
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/cloudflare.js +23 -14
- package/package.json +4 -1
package/cloudflare.js
CHANGED
|
@@ -319,27 +319,33 @@ class CloudFlare {
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
async rewriteFirewallRules (firewallRules) {
|
|
322
|
-
const { id: rulesetId
|
|
322
|
+
const { id: rulesetId } = await this.getFirewallRules()
|
|
323
323
|
|
|
324
324
|
if (!rulesetId) {
|
|
325
325
|
console.error(`Could not update firewall rules for domain ${this.domain}: custom firewall ruleset id is not found`)
|
|
326
326
|
throw new Error('Custom firewall ruleset id is not found')
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
|
|
330
|
-
const currentFirewallRule = currentFirewallRules?.find(
|
|
331
|
-
rule => rule.description === firewallRule.description
|
|
332
|
-
)
|
|
329
|
+
const url = CLOUDFLARE_API_URL + `zones/${this.zoneId}/rulesets/${rulesetId}`
|
|
333
330
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
331
|
+
const { statusCode, body } = await this.requestWithDelay(url, {
|
|
332
|
+
method: 'PUT',
|
|
333
|
+
headers: {
|
|
334
|
+
...this.authorizationHeaders,
|
|
335
|
+
'Content-Type': 'application/json'
|
|
336
|
+
},
|
|
337
|
+
body: JSON.stringify({ rules: firewallRules })
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
let response
|
|
341
|
+
try {
|
|
342
|
+
response = await body.json()
|
|
343
|
+
} catch (e) {
|
|
344
|
+
response = await body.text()
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (statusCode !== 200) {
|
|
348
|
+
throw new Error(`Could not update firewall rules: ${statusCode}, error: ${JSON.stringify(response)}`)
|
|
343
349
|
}
|
|
344
350
|
}
|
|
345
351
|
|
|
@@ -568,6 +574,9 @@ class CloudFlare {
|
|
|
568
574
|
const response = await body.json()
|
|
569
575
|
|
|
570
576
|
if (statusCode !== 200) {
|
|
577
|
+
if (response && response.errors && response.errors.find(e => e.code === 1015)) {
|
|
578
|
+
return response
|
|
579
|
+
}
|
|
571
580
|
throw new Error(`Could not set prefetch URLs: ${statusCode}, error: ${JSON.stringify(response)}`)
|
|
572
581
|
}
|
|
573
582
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodeart/cloudflare-provisioning",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,5 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"undici": "^7.3.0"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
19
22
|
}
|
|
20
23
|
}
|