@nodeart/cloudflare-provisioning 1.0.14 → 1.0.15

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.
@@ -11,10 +11,10 @@ jobs:
11
11
  build:
12
12
  runs-on: ubuntu-latest
13
13
  steps:
14
- - uses: actions/checkout@v3
15
- - uses: actions/setup-node@v3
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-node@v4
16
16
  with:
17
- node-version: 16
17
+ node-version: 24
18
18
  - run: npm ci
19
19
  - run: npm test
20
20
 
@@ -22,10 +22,10 @@ jobs:
22
22
  needs: build
23
23
  runs-on: ubuntu-latest
24
24
  steps:
25
- - uses: actions/checkout@v3
26
- - uses: actions/setup-node@v3
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/setup-node@v4
27
27
  with:
28
- node-version: 16
28
+ node-version: 24
29
29
  registry-url: https://registry.npmjs.org/
30
30
  - run: npm ci
31
31
  - run: npm publish
@@ -10,9 +10,9 @@ jobs:
10
10
  build:
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v3
14
- - uses: actions/setup-node@v3
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-node@v4
15
15
  with:
16
- node-version: 16
16
+ node-version: 24
17
17
  - run: npm ci
18
18
  - run: npm test
package/cloudflare.js CHANGED
@@ -460,27 +460,33 @@ class CloudFlare {
460
460
  }
461
461
 
462
462
  async rewriteRedirectRules (redirectRules) {
463
- const { id: rulesetId, rules: currentRedirectRules } = await this.getRedirectRules()
463
+ const { id: rulesetId } = await this.getRedirectRules()
464
464
 
465
465
  if (!rulesetId) {
466
466
  console.error(`Could not update redirect rules for domain ${this.domain}: custom firewall ruleset id is not found`)
467
467
  throw new Error('Custom redirect ruleset id is not found')
468
468
  }
469
469
 
470
- for (const redirectRule of redirectRules) {
471
- const currentRedirectRule = currentRedirectRules?.find(
472
- rule => rule.description === redirectRule.description
473
- )
470
+ const url = CLOUDFLARE_API_URL + `zones/${this.zoneId}/rulesets/${rulesetId}`
474
471
 
475
- try {
476
- if (currentRedirectRule) {
477
- await this.updateRedirectRule(rulesetId, currentRedirectRule.id, redirectRule)
478
- } else {
479
- await this.createRedirectRule(rulesetId, redirectRule)
480
- }
481
- } catch (error) {
482
- console.error(`Could not update redirect rule for domain ${this.domain}: ${JSON.stringify(redirectRule)}, error: ${error}`)
483
- }
472
+ const { statusCode, body } = await this.requestWithDelay(url, {
473
+ method: 'PUT',
474
+ headers: {
475
+ ...this.authorizationHeaders,
476
+ 'Content-Type': 'application/json'
477
+ },
478
+ body: JSON.stringify({ rules: redirectRules })
479
+ })
480
+
481
+ let response
482
+ try {
483
+ response = await body.json()
484
+ } catch (e) {
485
+ response = await body.text()
486
+ }
487
+
488
+ if (statusCode !== 200) {
489
+ throw new Error(`Could not update redirect rules: ${statusCode}, error: ${JSON.stringify(response)}`)
484
490
  }
485
491
  }
486
492
 
@@ -583,6 +589,9 @@ class CloudFlare {
583
589
  const response = await body.json()
584
590
 
585
591
  if (statusCode !== 200) {
592
+ if (response && response.errors && response.errors.find(e => e.code === 1015)) {
593
+ return response
594
+ }
586
595
  throw new Error(`Could not set HTTP2: ${statusCode}, error: ${JSON.stringify(response)}`)
587
596
  }
588
597
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodeart/cloudflare-provisioning",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {