@sparkvault/sdk 1.23.9 → 1.24.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.
@@ -0,0 +1,58 @@
1
+ /**
2
+ * SparkVault API Base
3
+ *
4
+ * Shared lifecycle and HTTP plumbing for every internal API client in the
5
+ * SDK. Concrete clients (IdentityApi, UploadApi, ...) extend this and
6
+ * provide:
7
+ * - their own error factory via makeError()
8
+ * - their own typed endpoint methods that call rawRequest()
9
+ *
10
+ * Session lifecycle invariant: every user-facing session (a modal open, a
11
+ * verify flow, an upload widget invocation) starts with the owning Module
12
+ * calling resetSession(). close() aborts the current AbortController; the
13
+ * next resetSession() swaps in a fresh one. The Module is responsible for
14
+ * this; clients of the SDK never see any of it.
15
+ */
16
+ import { SparkVaultError } from './errors';
17
+ export interface RawRequestOptions {
18
+ method: string;
19
+ body?: string;
20
+ headers?: Record<string, string>;
21
+ }
22
+ export interface RawResponse {
23
+ data: unknown;
24
+ status: number;
25
+ }
26
+ export declare abstract class SparkVaultApi {
27
+ protected readonly timeoutMs: number;
28
+ /**
29
+ * Abort controller for the current session. Replaced by resetSession()
30
+ * at the start of every user-facing session — an aborted controller can
31
+ * never leak into the next session.
32
+ */
33
+ private closeController;
34
+ constructor(timeoutMs?: number);
35
+ /** Abort all pending requests on this client. Called by the Module on close. */
36
+ abort(): void;
37
+ /** Whether the *current* session has been aborted. */
38
+ isAborted(): boolean;
39
+ /** The current session's abort signal — for callers that need to wire it into XHR/etc. */
40
+ getAbortSignal(): AbortSignal;
41
+ /**
42
+ * Swap in a fresh AbortController. The Module calls this at the start of
43
+ * every user-facing session. Long-lived per-client state (e.g. config
44
+ * caches) is intentionally NOT cleared here.
45
+ */
46
+ resetSession(): void;
47
+ /** Subclass-specific error factory. */
48
+ protected abstract makeError(message: string, code: string, statusCode: number): SparkVaultError;
49
+ /**
50
+ * Issue an HTTP request with timeout + session abort + standard error
51
+ * mapping. Subclasses build URLs and unwrap response envelopes on top.
52
+ *
53
+ * Returns the parsed JSON body (whatever shape it takes) plus the
54
+ * status code. Throws subclass-typed errors via makeError() for: aborted
55
+ * sessions, timeouts, network failures, and non-2xx responses.
56
+ */
57
+ protected rawRequest(url: string, options: RawRequestOptions): Promise<RawResponse>;
58
+ }
@@ -5,36 +5,16 @@
5
5
  * Single responsibility: API calls only.
6
6
  */
7
7
  import type { ResolvedConfig } from '../config';
8
+ import { SparkVaultApi } from '../api-base';
9
+ import { SparkVaultError } from '../errors';
8
10
  import type { SdkConfig, TotpSendResponse, TotpVerifyResponse, PasskeyChallengeResponse, PasskeyVerifyResponse, SparkLinkSendResponse, AuthContext } from './types';
9
- export declare class IdentityApi {
11
+ export declare class IdentityApi extends SparkVaultApi {
10
12
  private readonly config;
11
- private readonly timeoutMs;
12
13
  /** Cached config promise - allows preloading and deduplication */
13
14
  private configCache;
14
- /**
15
- * Abort controller for cancelling all pending requests on close.
16
- * Replaced by resetSession() at the start of every user-facing session.
17
- */
18
- private closeController;
19
15
  constructor(config: ResolvedConfig, timeoutMs?: number);
20
- /**
21
- * Abort all pending requests.
22
- * Call this when the renderer is closed to prevent orphaned requests.
23
- */
24
- abort(): void;
25
- /**
26
- * Check if the API has been aborted.
27
- */
28
- isAborted(): boolean;
29
- /**
30
- * Reset the session lifecycle by swapping in a fresh AbortController.
31
- * The Module calls this at the start of every user-facing session so a
32
- * previously-closed session can never leak its aborted state into the
33
- * next one. The config cache is intentionally preserved across sessions
34
- * so preloadConfig() keeps making modal opens instant.
35
- */
36
- resetSession(): void;
37
16
  private get baseUrl();
17
+ protected makeError(message: string, code: string, statusCode: number): IdentityApiError;
38
18
  private request;
39
19
  /**
40
20
  * Fetch SDK configuration (branding, enabled methods).
@@ -120,8 +100,6 @@ export declare class IdentityApi {
120
100
  */
121
101
  sendSparkLink(email: string, connectionId: string, authContext?: AuthContext): Promise<SparkLinkSendResponse>;
122
102
  }
123
- export declare class IdentityApiError extends Error {
124
- readonly code: string;
125
- readonly statusCode: number;
103
+ export declare class IdentityApiError extends SparkVaultError {
126
104
  constructor(message: string, code: string, statusCode: number);
127
105
  }
package/dist/index.d.ts CHANGED
@@ -117,6 +117,37 @@ interface TokenClaims {
117
117
  method: string;
118
118
  }
119
119
 
120
+ /**
121
+ * SparkVault SDK Error Types
122
+ */
123
+ declare class SparkVaultError extends Error {
124
+ readonly code: string;
125
+ readonly statusCode?: number;
126
+ readonly details?: Record<string, unknown>;
127
+ constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>);
128
+ }
129
+ declare class AuthenticationError extends SparkVaultError {
130
+ constructor(message: string, details?: Record<string, unknown>);
131
+ }
132
+ declare class AuthorizationError extends SparkVaultError {
133
+ constructor(message: string, details?: Record<string, unknown>);
134
+ }
135
+ declare class ValidationError extends SparkVaultError {
136
+ constructor(message: string, details?: Record<string, unknown>);
137
+ }
138
+ declare class NetworkError extends SparkVaultError {
139
+ constructor(message: string, details?: Record<string, unknown>);
140
+ }
141
+ declare class TimeoutError extends SparkVaultError {
142
+ constructor(message?: string);
143
+ }
144
+ declare class UserCancelledError extends SparkVaultError {
145
+ constructor(message?: string);
146
+ }
147
+ declare class PopupBlockedError extends SparkVaultError {
148
+ constructor();
149
+ }
150
+
120
151
  /**
121
152
  * Identity Module
122
153
  *
@@ -455,37 +486,6 @@ interface UploadResult {
455
486
  uploadTime: string;
456
487
  }
457
488
 
458
- /**
459
- * SparkVault SDK Error Types
460
- */
461
- declare class SparkVaultError extends Error {
462
- readonly code: string;
463
- readonly statusCode?: number;
464
- readonly details?: Record<string, unknown>;
465
- constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>);
466
- }
467
- declare class AuthenticationError extends SparkVaultError {
468
- constructor(message: string, details?: Record<string, unknown>);
469
- }
470
- declare class AuthorizationError extends SparkVaultError {
471
- constructor(message: string, details?: Record<string, unknown>);
472
- }
473
- declare class ValidationError extends SparkVaultError {
474
- constructor(message: string, details?: Record<string, unknown>);
475
- }
476
- declare class NetworkError extends SparkVaultError {
477
- constructor(message: string, details?: Record<string, unknown>);
478
- }
479
- declare class TimeoutError extends SparkVaultError {
480
- constructor(message?: string);
481
- }
482
- declare class UserCancelledError extends SparkVaultError {
483
- constructor(message?: string);
484
- }
485
- declare class PopupBlockedError extends SparkVaultError {
486
- constructor();
487
- }
488
-
489
489
  /**
490
490
  * Vaults Module
491
491
  *