@aoxborrow/registrar-client 0.6.0 → 0.7.0

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/src/types.ts CHANGED
@@ -12,10 +12,34 @@ export interface RegistrarClientOptions {
12
12
  backoff: number;
13
13
  // optional AbortSignal to cancel in-flight requests
14
14
  signal?: AbortSignal;
15
+ // fetch implementation used for every request, e.g. one that routes through a
16
+ // proxy. Defaults to the global `fetch`. A transport that fails before the
17
+ // request leaves (proxy refused, tunnel not established) should throw an
18
+ // error marked with `markNotSent` so the failure is retried for any call.
19
+ fetch?: typeof globalThis.fetch;
20
+ }
21
+
22
+ // whether a call only reads registrar state or may change it. Decides what is
23
+ // safe to re-send after a failure; see `FEATURE_CALLS` in features.ts.
24
+ export type RequestIntent = 'read' | 'write';
25
+
26
+ // per-call bookkeeping the library threads through `RequestOptions` from a
27
+ // feature method down to the HTTP layer. Set by `BaseRegistrar`; callers never
28
+ // need to supply it.
29
+ export interface FeatureCall {
30
+ intent: RequestIntent;
31
+ // the feature method being served, e.g. "renewDomain"
32
+ feature?: string;
33
+ // set by the HTTP layer when a write's outcome could not be determined, so
34
+ // it survives providers that fold errors into an `OperationResult`
35
+ outcomeUnknown?: Error;
15
36
  }
16
37
 
17
38
  // per-request options that can override client-level options
18
- export type RequestOptions = Partial<RegistrarClientOptions>;
39
+ export interface RequestOptions extends Partial<RegistrarClientOptions> {
40
+ // library-internal; see `FeatureCall`
41
+ call?: FeatureCall;
42
+ }
19
43
 
20
44
  // options for `listDomains`. Extends `RequestOptions` so timeout/retries/signal
21
45
  // still flow through a single argument. `listDomains` always returns the full
@@ -56,6 +80,11 @@ export interface ConnectionResult {
56
80
  export interface OperationResult {
57
81
  success: boolean;
58
82
  message: string;
83
+ // Present only on a failed write whose request may have reached the
84
+ // registrar (timed out, connection dropped mid-response, or a 5xx). The
85
+ // change may or may not have been applied: re-read the domain before trying
86
+ // again. The library never re-sends such a request itself.
87
+ outcome?: 'unknown';
59
88
  }
60
89
 
61
90
  // a configuration field a registrar needs (used to build credential UIs generically)
package/src/utils.ts CHANGED
@@ -1,4 +1,10 @@
1
- import type { DomainForward, Domain, DomainInput, RegistrationConsent } from './types';
1
+ import type {
2
+ DomainForward,
3
+ Domain,
4
+ DomainInput,
5
+ RegistrationConsent,
6
+ RequestOptions,
7
+ } from './types';
2
8
  import { ConsentRequiredError } from './errors';
3
9
 
4
10
  // sleep helper for retry backoff
@@ -133,3 +139,12 @@ export function createDomain(data: DomainInput = {}): Domain {
133
139
  deleted: data.deleted ?? false,
134
140
  };
135
141
  }
142
+
143
+ // Marks a request made inside a write feature as a read: a lookup the write
144
+ // needs first (current records, a price, an auth token). It is retried like any
145
+ // read, and its failure is never reported as a write of unknown outcome. For
146
+ // APIs whose HTTP method can't tell reads from writes; REST providers get this
147
+ // from `safeMethods`.
148
+ export function asRead<T extends RequestOptions>(opts?: T): T {
149
+ return { ...opts, call: { ...opts?.call, intent: 'read' } } as T;
150
+ }