@nodeart/cloudflare-provisioning 1.0.14 → 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.
|
@@ -11,10 +11,10 @@ jobs:
|
|
|
11
11
|
build:
|
|
12
12
|
runs-on: ubuntu-latest
|
|
13
13
|
steps:
|
|
14
|
-
- uses: actions/checkout@
|
|
15
|
-
- uses: actions/setup-node@
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
16
|
with:
|
|
17
|
-
node-version:
|
|
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@
|
|
26
|
-
- uses: actions/setup-node@
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- uses: actions/setup-node@v4
|
|
27
27
|
with:
|
|
28
|
-
node-version:
|
|
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@
|
|
14
|
-
- uses: actions/setup-node@
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
15
|
with:
|
|
16
|
-
node-version:
|
|
16
|
+
node-version: 24
|
|
17
17
|
- run: npm ci
|
|
18
18
|
- run: npm test
|
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
|
|
|
@@ -460,27 +466,33 @@ class CloudFlare {
|
|
|
460
466
|
}
|
|
461
467
|
|
|
462
468
|
async rewriteRedirectRules (redirectRules) {
|
|
463
|
-
const { id: rulesetId
|
|
469
|
+
const { id: rulesetId } = await this.getRedirectRules()
|
|
464
470
|
|
|
465
471
|
if (!rulesetId) {
|
|
466
472
|
console.error(`Could not update redirect rules for domain ${this.domain}: custom firewall ruleset id is not found`)
|
|
467
473
|
throw new Error('Custom redirect ruleset id is not found')
|
|
468
474
|
}
|
|
469
475
|
|
|
470
|
-
|
|
471
|
-
const currentRedirectRule = currentRedirectRules?.find(
|
|
472
|
-
rule => rule.description === redirectRule.description
|
|
473
|
-
)
|
|
476
|
+
const url = CLOUDFLARE_API_URL + `zones/${this.zoneId}/rulesets/${rulesetId}`
|
|
474
477
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
478
|
+
const { statusCode, body } = await this.requestWithDelay(url, {
|
|
479
|
+
method: 'PUT',
|
|
480
|
+
headers: {
|
|
481
|
+
...this.authorizationHeaders,
|
|
482
|
+
'Content-Type': 'application/json'
|
|
483
|
+
},
|
|
484
|
+
body: JSON.stringify({ rules: redirectRules })
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
let response
|
|
488
|
+
try {
|
|
489
|
+
response = await body.json()
|
|
490
|
+
} catch (e) {
|
|
491
|
+
response = await body.text()
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (statusCode !== 200) {
|
|
495
|
+
throw new Error(`Could not update redirect rules: ${statusCode}, error: ${JSON.stringify(response)}`)
|
|
484
496
|
}
|
|
485
497
|
}
|
|
486
498
|
|
|
@@ -562,6 +574,9 @@ class CloudFlare {
|
|
|
562
574
|
const response = await body.json()
|
|
563
575
|
|
|
564
576
|
if (statusCode !== 200) {
|
|
577
|
+
if (response && response.errors && response.errors.find(e => e.code === 1015)) {
|
|
578
|
+
return response
|
|
579
|
+
}
|
|
565
580
|
throw new Error(`Could not set prefetch URLs: ${statusCode}, error: ${JSON.stringify(response)}`)
|
|
566
581
|
}
|
|
567
582
|
|
|
@@ -583,6 +598,9 @@ class CloudFlare {
|
|
|
583
598
|
const response = await body.json()
|
|
584
599
|
|
|
585
600
|
if (statusCode !== 200) {
|
|
601
|
+
if (response && response.errors && response.errors.find(e => e.code === 1015)) {
|
|
602
|
+
return response
|
|
603
|
+
}
|
|
586
604
|
throw new Error(`Could not set HTTP2: ${statusCode}, error: ${JSON.stringify(response)}`)
|
|
587
605
|
}
|
|
588
606
|
|
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
|
}
|