@sparkvault/sdk-js 11.0.0 → 11.0.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.
@@ -85,21 +85,30 @@ export declare abstract class SparkVaultApi {
85
85
  * caches) is intentionally NOT cleared here.
86
86
  */
87
87
  resetSession(): void;
88
- /** Subclass-specific error factory. */
89
- protected abstract makeError(message: string, code: string, statusCode: number, details?: Record<string, unknown>): SparkVaultError;
88
+ /**
89
+ * Subclass-specific error factory. A refused answer passes its
90
+ * `Retry-After` (ms, as the transfer policy reads it) for the error to carry
91
+ * as `retryAfterMs`; a request that got no answer passes none.
92
+ */
93
+ protected abstract makeError(message: string, code: string, statusCode: number, details?: Record<string, unknown>, retryAfterMs?: number | null): SparkVaultError;
90
94
  /**
91
95
  * One request in the current session: `exchange` bound to this client's
92
96
  * deadline, its error factory, and the session's close signal, captured
93
97
  * here, when the request starts. resetSession() can swap the controller
94
98
  * while the request is in flight, and reading the live one afterwards would
95
99
  * misreport a genuine cancel as a timeout.
100
+ *
101
+ * @param timeoutMs - The deadline of a request whose server-side wait is
102
+ * its own (a tus HEAD or receipt, which Forge answers only after its call
103
+ * to Core); every other request takes the client's.
96
104
  */
97
- protected send<T>(url: string, init: RequestInit, copy: TransportCopy, read: (response: Response) => Promise<T>): Promise<T>;
105
+ protected send<T>(url: string, init: RequestInit, copy: TransportCopy, read: (response: Response) => Promise<T>, timeoutMs?: number): Promise<T>;
98
106
  /**
99
107
  * Issue a JSON API request. Returns the parsed JSON body (whatever shape it
100
108
  * takes; null when the body is not JSON) plus the status code. A non-2xx
101
- * answer throws the subclass error carrying the server's code, message and
102
- * details, read by the one error-body reader every transport shares.
109
+ * answer throws the subclass error carrying the server's code, message,
110
+ * details and `Retry-After`, read by the one failed-answer reader every
111
+ * transport shares.
103
112
  */
104
113
  protected rawRequest(url: string, options: RawRequestOptions): Promise<RawResponse>;
105
114
  }
package/dist/errors.d.ts CHANGED
@@ -5,16 +5,24 @@ export declare class SparkVaultError extends Error {
5
5
  readonly code: string;
6
6
  readonly statusCode?: number;
7
7
  readonly details?: Record<string, unknown>;
8
- constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>);
8
+ /**
9
+ * The answer's `Retry-After`, in ms from the answer, read as the platform's
10
+ * transfer policy reads it (RFC 9110 §10.2.3: delay-seconds or an
11
+ * HTTP-date): the earliest a next attempt can expect another answer, which
12
+ * every retry the SDK makes waits out as a floor. Null when the answer
13
+ * carried none the policy could read, or no answer arrived.
14
+ */
15
+ readonly retryAfterMs: number | null;
16
+ constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>, retryAfterMs?: number | null);
9
17
  }
10
18
  export declare class AuthenticationError extends SparkVaultError {
11
- constructor(message: string, details?: Record<string, unknown>);
19
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
12
20
  }
13
21
  export declare class AuthorizationError extends SparkVaultError {
14
- constructor(message: string, details?: Record<string, unknown>);
22
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
15
23
  }
16
24
  export declare class ValidationError extends SparkVaultError {
17
- constructor(message: string, details?: Record<string, unknown>);
25
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
18
26
  }
19
27
  /**
20
28
  * The pooled-capacity resource a quota gate refers to. Only the byte pools
@@ -29,7 +37,7 @@ export type QuotaResource = 'storage' | 'bandwidth';
29
37
  * to admins, or "ask your account admin" to members.
30
38
  */
31
39
  export declare class PlanRequiredError extends SparkVaultError {
32
- constructor(message: string, details?: Record<string, unknown>);
40
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
33
41
  }
34
42
  /**
35
43
  * Quota exceeded gate (402 QUOTA_EXCEEDED) — a pooled-capacity limit is
@@ -38,7 +46,7 @@ export declare class PlanRequiredError extends SparkVaultError {
38
46
  */
39
47
  export declare class QuotaExceededError extends SparkVaultError {
40
48
  readonly resource?: QuotaResource;
41
- constructor(message: string, details?: Record<string, unknown>);
49
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
42
50
  }
43
51
  /**
44
52
  * Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED) — the account has
@@ -47,7 +55,7 @@ export declare class QuotaExceededError extends SparkVaultError {
47
55
  * nothing, so surface a subscribe CTA rather than a sign-in prompt.
48
56
  */
49
57
  export declare class NotifySubscriptionRequiredError extends SparkVaultError {
50
- constructor(message: string, details?: Record<string, unknown>);
58
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
51
59
  }
52
60
  export declare class NetworkError extends SparkVaultError {
53
61
  constructor(message: string, details?: Record<string, unknown>);
@@ -72,18 +80,26 @@ export declare class PopupBlockedError extends SparkVaultError {
72
80
  export declare class PopupSeveredError extends SparkVaultError {
73
81
  constructor();
74
82
  }
75
- /** What a failed SparkVault API response says about itself. */
76
- export interface ApiErrorBody {
83
+ /** What a failed SparkVault API response says about itself: its status, its error body, and the floor it names. */
84
+ export interface ApiFailure {
85
+ status: number;
77
86
  message: string;
78
87
  code: string;
79
88
  details?: Record<string, unknown>;
89
+ /** The answer's `Retry-After` in ms ({@link SparkVaultError.retryAfterMs}); null when it carries none. */
90
+ retryAfterMs: number | null;
91
+ }
92
+ /** A failed answer as a transport holds it: its status, its whole body's text, and a reader of its headers. */
93
+ export interface FailedAnswer {
94
+ readonly status: number;
95
+ readonly body: string;
96
+ readonly header: (name: string) => string | null;
80
97
  }
81
98
  /**
82
- * Read a failed response's error body: the one reading every SDK transport
83
- * shares. SparkVault services answer `{ error: { code, message, details } }`;
84
- * a framework or gateway answers flat (`{ code, message }`, `{ message }`) or
85
- * with no JSON at all, so each field falls back to its flat form and then to a
86
- * default. The body is read leniently: a failure's status and class never
87
- * depend on the body being JSON.
99
+ * Read a failed answer a transport holds as text (an XMLHttpRequest's
100
+ * `responseText`, a body it also keeps a snippet of), parsed whole, so
101
+ * nothing past any length is lost to the reading.
88
102
  */
89
- export declare function readApiErrorBody(response: Response): Promise<ApiErrorBody>;
103
+ export declare function apiFailureOf(answer: FailedAnswer): ApiFailure;
104
+ /** Read a failed fetch response; a body that is not JSON, or cannot be read, reads as none. */
105
+ export declare function readApiFailure(response: Response): Promise<ApiFailure>;
package/dist/http.d.ts CHANGED
@@ -57,6 +57,14 @@ export declare class HttpClient {
57
57
  private getAccessToken;
58
58
  request<T = unknown>(path: ApiPath, options?: RequestOptions): Promise<ApiResponse<T>>;
59
59
  private parseResponse;
60
+ /**
61
+ * The SDK error for a failed answer, typed by its status: the gates a host
62
+ * page branches on get their own class, and every other answer is the base
63
+ * error under the service's own code. Each carries the answer's
64
+ * `Retry-After` (`retryAfterMs`), the floor for whoever retries it — the
65
+ * SDK's own transfers when the answer is a download link's mint, and the
66
+ * host page otherwise.
67
+ */
60
68
  private createErrorFromResponse;
61
69
  private unwrapApiResponse;
62
70
  /**