@didis/client 0.2.3 → 0.2.4
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/CHANGELOG.md +8 -1
- package/README.md +2 -0
- package/dist/index.d.ts +21 -1
- package/dist/index.js +40 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to `@didis/client` are listed here. The format follows [Keep
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.2.4] - 2026-10-19
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Automatic wait-and-retry for `429` (request budget used up) and `503` (temporarily overloaded) responses that carry `Retry-After`. By default the client retries up to 2 times and never waits longer than 10 seconds per attempt; a short random delay is added so clients refused together do not return together. Both statuses are refused before the request is processed, so retrying is safe for every call. Tune with `new DidisClient({ retry: { maxRetries, maxWaitMs } })` or turn off with `retry: false`. When retries run out, the last `DidisError` is thrown as before, with `problem.retryAfter`.
|
|
12
|
+
|
|
7
13
|
## [0.2.3] - 2026-10-18
|
|
8
14
|
|
|
9
15
|
### Added
|
|
@@ -56,7 +62,8 @@ All notable changes to `@didis/client` are listed here. The format follows [Keep
|
|
|
56
62
|
- `DidisError` carrying the RFC 9457 problem body and `Retry-After`.
|
|
57
63
|
- Webhook helpers `verifyWebhookSignature` and `verifyCustomerMonitorSignature`.
|
|
58
64
|
|
|
59
|
-
[Unreleased]: https://github.com/did-is/didis-js/compare/v0.2.
|
|
65
|
+
[Unreleased]: https://github.com/did-is/didis-js/compare/v0.2.4...HEAD
|
|
66
|
+
[0.2.4]: https://github.com/did-is/didis-js/compare/v0.2.3...v0.2.4
|
|
60
67
|
[0.2.3]: https://github.com/did-is/didis-js/compare/v0.2.2...v0.2.3
|
|
61
68
|
[0.2.2]: https://github.com/did-is/didis-js/compare/v0.2.1...v0.2.2
|
|
62
69
|
[0.2.1]: https://github.com/did-is/didis-js/compare/v0.2.0...v0.2.1
|
package/README.md
CHANGED
|
@@ -63,6 +63,8 @@ try {
|
|
|
63
63
|
|
|
64
64
|
Identifiers are percent-encoded exactly once by the client. Non-2xx responses throw `DidisError` with the RFC 9457 problem body (including the resolution `trace` where available).
|
|
65
65
|
|
|
66
|
+
**Rate limits.** When the public budget is used up the API answers `429` with `Retry-After`. The client waits that long and retries (up to 2 times, at most 10 s per wait), so a loop of calls slows down instead of failing. Tune with `new DidisClient({ retry: { maxRetries: 3, maxWaitMs: 5000 } })` or turn it off with `retry: false`.
|
|
67
|
+
|
|
66
68
|
## Guard agent tools
|
|
67
69
|
|
|
68
70
|
Wrap a tool handler so it runs only when (1) the tool definition the agent received still matches the one you approved and (2) DID.is says the agent's registered delegation grants the tool. Every failure throws `DidisGuardError` and the handler does not run (fail-closed).
|
package/dist/index.d.ts
CHANGED
|
@@ -672,18 +672,38 @@ export interface DidisClientOptions {
|
|
|
672
672
|
adminToken?: string;
|
|
673
673
|
timeoutMs?: number;
|
|
674
674
|
fetch?: typeof fetch;
|
|
675
|
+
/**
|
|
676
|
+
* Automatic wait-and-retry when the API answers 429 (request budget used up) or 503
|
|
677
|
+
* (temporarily overloaded) with a `Retry-After` header. Such refusals happen before the
|
|
678
|
+
* request is processed, so retrying is safe for every call. Default: up to 2 retries,
|
|
679
|
+
* never waiting longer than 10 s for one retry. Pass `false` to turn it off.
|
|
680
|
+
*/
|
|
681
|
+
retry?: false | {
|
|
682
|
+
maxRetries?: number;
|
|
683
|
+
maxWaitMs?: number;
|
|
684
|
+
};
|
|
675
685
|
}
|
|
686
|
+
/** Milliseconds to wait from a `Retry-After` value (delta-seconds or HTTP-date); null if unusable. */
|
|
687
|
+
export declare function retryAfterMs(value: string | null | undefined, now?: number): number | null;
|
|
676
688
|
/** Public DID.is API. Point `baseUrl` at your own deployment when self-hosting. */
|
|
677
689
|
export declare const DEFAULT_BASE_URL = "https://did.is/api";
|
|
678
690
|
/** Package version, kept equal to package.json (checked by the test suite). */
|
|
679
|
-
export declare const VERSION = "0.2.
|
|
691
|
+
export declare const VERSION = "0.2.4";
|
|
680
692
|
export declare class DidisClient {
|
|
681
693
|
private readonly baseUrl;
|
|
682
694
|
private readonly adminToken?;
|
|
683
695
|
private readonly timeoutMs;
|
|
684
696
|
private readonly fetchImpl;
|
|
697
|
+
private readonly maxRetries;
|
|
698
|
+
private readonly maxWaitMs;
|
|
685
699
|
constructor(options?: string | DidisClientOptions);
|
|
700
|
+
/**
|
|
701
|
+
* Waits out a 429/503 refusal when the server says how long, within the configured bounds.
|
|
702
|
+
* A small random delay spreads out many clients that were refused at the same moment.
|
|
703
|
+
*/
|
|
704
|
+
private backoff;
|
|
686
705
|
private request;
|
|
706
|
+
private once;
|
|
687
707
|
private admin;
|
|
688
708
|
health(): Promise<HealthStatus>;
|
|
689
709
|
/** Enriched resolution: verdict, evidence dimensions, graph, telemetry. */
|
package/dist/index.js
CHANGED
|
@@ -12,10 +12,21 @@ export class DidisError extends Error {
|
|
|
12
12
|
this.problem = problem;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
/** Milliseconds to wait from a `Retry-After` value (delta-seconds or HTTP-date); null if unusable. */
|
|
16
|
+
export function retryAfterMs(value, now = Date.now()) {
|
|
17
|
+
if (!value)
|
|
18
|
+
return null;
|
|
19
|
+
const v = value.trim();
|
|
20
|
+
if (/^\d+$/.test(v))
|
|
21
|
+
return Number(v) * 1000;
|
|
22
|
+
const at = Date.parse(v);
|
|
23
|
+
return Number.isNaN(at) ? null : Math.max(0, at - now);
|
|
24
|
+
}
|
|
25
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
15
26
|
/** Public DID.is API. Point `baseUrl` at your own deployment when self-hosting. */
|
|
16
27
|
export const DEFAULT_BASE_URL = "https://did.is/api";
|
|
17
28
|
/** Package version, kept equal to package.json (checked by the test suite). */
|
|
18
|
-
export const VERSION = "0.2.
|
|
29
|
+
export const VERSION = "0.2.4";
|
|
19
30
|
/**
|
|
20
31
|
* Identifies the SDK to the API so DID.is can count SDK use apart from other HTTP clients.
|
|
21
32
|
* Only the product name and version are sent. Browsers are left alone: there the browser
|
|
@@ -28,14 +39,42 @@ export class DidisClient {
|
|
|
28
39
|
adminToken;
|
|
29
40
|
timeoutMs;
|
|
30
41
|
fetchImpl;
|
|
42
|
+
maxRetries;
|
|
43
|
+
maxWaitMs;
|
|
31
44
|
constructor(options = {}) {
|
|
32
45
|
const o = typeof options === "string" ? { baseUrl: options } : options;
|
|
33
46
|
this.baseUrl = (o.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
34
47
|
this.adminToken = o.adminToken;
|
|
35
48
|
this.timeoutMs = o.timeoutMs ?? 30_000;
|
|
36
49
|
this.fetchImpl = o.fetch ?? fetch;
|
|
50
|
+
this.maxRetries = o.retry === false ? 0 : Math.max(0, Math.floor(o.retry?.maxRetries ?? 2));
|
|
51
|
+
this.maxWaitMs = o.retry === false ? 0 : Math.max(0, o.retry?.maxWaitMs ?? 10_000);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Waits out a 429/503 refusal when the server says how long, within the configured bounds.
|
|
55
|
+
* A small random delay spreads out many clients that were refused at the same moment.
|
|
56
|
+
*/
|
|
57
|
+
async backoff(attempt, status, retryAfter) {
|
|
58
|
+
if (attempt >= this.maxRetries || (status !== 429 && status !== 503))
|
|
59
|
+
return false;
|
|
60
|
+
const wait = retryAfterMs(retryAfter);
|
|
61
|
+
if (wait === null || wait > this.maxWaitMs)
|
|
62
|
+
return false;
|
|
63
|
+
await sleep(wait + Math.floor(Math.random() * 250));
|
|
64
|
+
return true;
|
|
37
65
|
}
|
|
38
66
|
async request(method, path, body, headers = {}) {
|
|
67
|
+
for (let attempt = 0;; attempt++) {
|
|
68
|
+
try {
|
|
69
|
+
return await this.once(method, path, body, headers);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
if (!(e instanceof DidisError) || !(await this.backoff(attempt, e.status, e.problem.retryAfter ?? null)))
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async once(method, path, body, headers = {}) {
|
|
39
78
|
const controller = new AbortController();
|
|
40
79
|
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
41
80
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@didis/client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Official TypeScript/JavaScript SDK for the DID.is public API: DID resolution with evidence, credentials, policies and agent trust",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|