@theholocron/cloudflare-client 1.57.1-alpha.1 → 1.57.1-alpha.2
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/README.md +10 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +14 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -118,6 +118,16 @@ await cf.workers.createRoute("zone-id", "example.com/*", "my-worker");
|
|
|
118
118
|
await cf.workers.updateRoute("zone-id", routes[0].id, "example.com/*", "my-worker");
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
+
## Retries
|
|
122
|
+
|
|
123
|
+
A read (`GET`) that Cloudflare answers with `500`, `502`, `503` or `504`, or that fails in transit, is sent again up to twice, waiting 300 ms and then 900 ms. A write (`POST`, `PATCH`, `PUT`, `DELETE`) is never sent again, because it may have been applied. When a read still fails, the `ProviderApiError` keeps the last status and body and its message says how many sends it took, with the `cf-ray` id when Cloudflare sent one:
|
|
124
|
+
|
|
125
|
+
```text
|
|
126
|
+
Cloudflare GET /zones/abc/dns_records → 500 (after 3 attempts; cf-ray: 8a1b2c3d4e5f-LHR)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Pass `retries` (`0` turns it off) and `retryDelayMs` to `createCloudflareClient` to change this. A `429` is not retried: its `Retry-After` is not honoured.
|
|
130
|
+
|
|
121
131
|
## Auth
|
|
122
132
|
|
|
123
133
|
Create an [API Token](https://dash.cloudflare.com/profile/api-tokens) with the permissions your use case requires:
|
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,10 @@ interface CloudflareClientOptions {
|
|
|
10
10
|
logger?: Logger;
|
|
11
11
|
/** Reports transport failures and unexpected 5xx. Defaults to a no-op. */
|
|
12
12
|
errors?: ErrorSink;
|
|
13
|
+
/** How many times a read is sent again after a transient failure (see `retryDelayMs`). Defaults to 2; 0 turns it off. */
|
|
14
|
+
retries?: number;
|
|
15
|
+
/** Milliseconds before the first retry; each later one waits three times as long. Defaults to 300. */
|
|
16
|
+
retryDelayMs?: number;
|
|
13
17
|
}
|
|
14
18
|
interface CfEnvelope<T> {
|
|
15
19
|
success: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { ProviderApiError, createRestClient } from "@theholocron/http-client";
|
|
2
2
|
// src/utils.ts
|
|
3
|
+
/**
|
|
4
|
+
* Cloudflare answers these when the API itself is briefly unavailable. A read that gets one is asked for again; a
|
|
5
|
+
* write is never repeated (it may have been applied). A 429 is left out because its `Retry-After` is not honoured here.
|
|
6
|
+
*/
|
|
7
|
+
const TRANSIENT_STATUSES = [
|
|
8
|
+
500,
|
|
9
|
+
502,
|
|
10
|
+
503,
|
|
11
|
+
504
|
|
12
|
+
];
|
|
3
13
|
function createCloudflareRestClient(opts) {
|
|
4
14
|
return createRestClient({
|
|
5
15
|
baseUrl: opts.baseUrl ?? "https://api.cloudflare.com/client/v4",
|
|
@@ -7,7 +17,10 @@ function createCloudflareRestClient(opts) {
|
|
|
7
17
|
vendor: "Cloudflare",
|
|
8
18
|
fetch: opts.fetch,
|
|
9
19
|
logger: opts.logger,
|
|
10
|
-
errors: opts.errors
|
|
20
|
+
errors: opts.errors,
|
|
21
|
+
retryStatuses: TRANSIENT_STATUSES,
|
|
22
|
+
retries: opts.retries,
|
|
23
|
+
retryDelayMs: opts.retryDelayMs
|
|
11
24
|
});
|
|
12
25
|
}
|
|
13
26
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/cloudflare-client",
|
|
3
|
-
"version": "1.57.1-alpha.
|
|
3
|
+
"version": "1.57.1-alpha.2",
|
|
4
4
|
"description": "A TypeScript client for the Cloudflare API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -32,14 +32,10 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@theholocron/
|
|
36
|
-
"@theholocron/
|
|
35
|
+
"@theholocron/http-client": "^1.57.1-alpha.2",
|
|
36
|
+
"@theholocron/observability": "^0.6.1-alpha.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@theholocron/eslint-config": "^8.8.2",
|
|
40
|
-
"@theholocron/tsconfig": "^8.8.2",
|
|
41
|
-
"@theholocron/tsdown-config": "^8.8.2",
|
|
42
|
-
"@theholocron/vitest-config": "^8.8.2",
|
|
43
39
|
"@types/node": "^26",
|
|
44
40
|
"@vitest/coverage-v8": "^5.0.5",
|
|
45
41
|
"@vitest/eslint-plugin": "^1.6.27",
|
|
@@ -48,7 +44,11 @@
|
|
|
48
44
|
"globals": "^17.11.0",
|
|
49
45
|
"tsdown": "^0.23.3",
|
|
50
46
|
"typescript": "^5.9.3",
|
|
51
|
-
"vitest": "^5.0.5"
|
|
47
|
+
"vitest": "^5.0.5",
|
|
48
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.3",
|
|
49
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.3",
|
|
50
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.3",
|
|
51
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.3"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22.0.0"
|