@nodeart/cloudflare-provisioning 1.0.15 → 1.0.17

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 CHANGED
@@ -319,27 +319,33 @@ class CloudFlare {
319
319
  }
320
320
 
321
321
  async rewriteFirewallRules (firewallRules) {
322
- const { id: rulesetId, rules: currentFirewallRules } = await this.getFirewallRules()
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
- for (const firewallRule of firewallRules) {
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
- try {
335
- if (currentFirewallRule) {
336
- await this.updateFirewallRule(rulesetId, currentFirewallRule.id, firewallRule)
337
- } else {
338
- await this.createFirewallRule(rulesetId, firewallRule)
339
- }
340
- } catch (error) {
341
- console.error(`Could not update firewall rule for domain ${this.domain}: ${JSON.stringify(firewallRule)}, error: ${error}`)
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.15",
3
+ "version": "1.0.17",
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
  }
package/template.js CHANGED
@@ -7,10 +7,8 @@ module.exports = {
7
7
  {
8
8
  description: 'block bots',
9
9
  action: 'block',
10
- filter: {
11
- enabled: true,
12
- expression: '(cf.client.bot and not http.request.uri.path contains ".well-known")'
13
- }
10
+ enabled: true,
11
+ expression: '(cf.client.bot and not http.request.uri.path contains ".well-known")'
14
12
  }
15
13
  ]
16
14
  },