@treeviz/familysearch-sdk 1.0.24 → 2.0.1
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 +499 -30
- package/dist/auth/index.cjs +102 -2
- package/dist/auth/index.d.cts +1 -124
- package/dist/auth/index.d.ts +1 -124
- package/dist/auth/index.js +102 -3
- package/dist/index-B8IEIPI-.d.cts +5558 -0
- package/dist/index-D-O_e-PM.d.cts +359 -0
- package/dist/index-D-O_e-PM.d.ts +359 -0
- package/dist/index-D1LjJwtP.d.ts +5558 -0
- package/dist/index-DbUKUKnB.d.cts +171 -0
- package/dist/index-Ko_Hpn8j.d.ts +171 -0
- package/dist/index.cjs +5910 -824
- package/dist/index.d.cts +158 -5
- package/dist/index.d.ts +158 -5
- package/dist/index.js +5878 -820
- package/dist/places/index.cjs +303 -82
- package/dist/places/index.d.cts +3 -69
- package/dist/places/index.d.ts +3 -69
- package/dist/places/index.js +290 -80
- package/dist/tree/index.cjs +3412 -172
- package/dist/tree/index.d.cts +3 -50
- package/dist/tree/index.d.ts +3 -50
- package/dist/tree/index.js +3266 -169
- package/dist/tree-Bs2PWco8.d.cts +1335 -0
- package/dist/tree-Bs2PWco8.d.ts +1335 -0
- package/dist/utils/index.cjs +14 -11
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +14 -11
- package/package.json +7 -3
- package/dist/auth/index.cjs.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/client-CoN1l8gT.d.ts +0 -276
- package/dist/client-yKRhqQzH.d.cts +0 -276
- package/dist/index-DqPXkWyy.d.cts +0 -671
- package/dist/index-DqPXkWyy.d.ts +0 -671
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/places/index.cjs.map +0 -1
- package/dist/places/index.js.map +0 -1
- package/dist/tree/index.cjs.map +0 -1
- package/dist/tree/index.js.map +0 -1
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.js.map +0 -1
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core SDK Types
|
|
3
|
+
*
|
|
4
|
+
* Environment configuration, SDK initialization, and base API types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* FamilySearch API environment
|
|
8
|
+
*/
|
|
9
|
+
type FamilySearchEnvironment = "production" | "beta" | "integration";
|
|
10
|
+
/**
|
|
11
|
+
* Environment-specific endpoint configuration
|
|
12
|
+
*/
|
|
13
|
+
interface EnvironmentConfig {
|
|
14
|
+
/** Identity server host for OAuth */
|
|
15
|
+
identHost: string;
|
|
16
|
+
/** Platform API host for data operations */
|
|
17
|
+
platformHost: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Rate limiter configuration
|
|
21
|
+
*/
|
|
22
|
+
interface RateLimiterConfig {
|
|
23
|
+
/** Maximum requests per second (default: 10) */
|
|
24
|
+
requestsPerSecond?: number;
|
|
25
|
+
/** Maximum burst size (default: 20) */
|
|
26
|
+
maxBurst?: number;
|
|
27
|
+
/** Maximum retry attempts for 429 errors (default: 3) */
|
|
28
|
+
maxRetries?: number;
|
|
29
|
+
/** Initial backoff delay in ms (default: 1000) */
|
|
30
|
+
initialBackoffMs?: number;
|
|
31
|
+
/** Maximum backoff delay in ms (default: 30000) */
|
|
32
|
+
maxBackoffMs?: number;
|
|
33
|
+
/** Jitter factor (0-1) to add randomness to backoff delays (default: 0.3 = 30%) */
|
|
34
|
+
jitterFactor?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* SDK initialization options
|
|
38
|
+
*/
|
|
39
|
+
interface FamilySearchSDKConfig {
|
|
40
|
+
/** API environment (default: "integration") */
|
|
41
|
+
environment?: FamilySearchEnvironment;
|
|
42
|
+
/** OAuth access token */
|
|
43
|
+
accessToken?: string;
|
|
44
|
+
/** Application key for API requests */
|
|
45
|
+
appKey?: string;
|
|
46
|
+
/** OAuth redirect URI (required for OAuth flows) */
|
|
47
|
+
redirectUri?: string;
|
|
48
|
+
/** Optional logger for debugging */
|
|
49
|
+
logger?: SDKLogger;
|
|
50
|
+
/** Optional rate limiter configuration */
|
|
51
|
+
rateLimiter?: RateLimiterConfig;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Logger interface for SDK debugging
|
|
55
|
+
*/
|
|
56
|
+
interface SDKLogger {
|
|
57
|
+
log: (message: string, ...args: unknown[]) => void;
|
|
58
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
59
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generic API response wrapper
|
|
63
|
+
*/
|
|
64
|
+
interface FamilySearchApiResponse<T> {
|
|
65
|
+
/** Response data */
|
|
66
|
+
data?: T;
|
|
67
|
+
/** HTTP status code */
|
|
68
|
+
statusCode: number;
|
|
69
|
+
/** HTTP status text */
|
|
70
|
+
statusText: string;
|
|
71
|
+
/** Response headers */
|
|
72
|
+
headers: Record<string, string>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* API error with additional context
|
|
76
|
+
*/
|
|
77
|
+
interface FamilySearchApiError extends Error {
|
|
78
|
+
/** HTTP status code if available */
|
|
79
|
+
statusCode?: number;
|
|
80
|
+
/** Full response object */
|
|
81
|
+
response?: FamilySearchApiResponse<unknown>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Progress callback for long operations
|
|
85
|
+
*/
|
|
86
|
+
type ProgressCallback = (progress: {
|
|
87
|
+
stage: string;
|
|
88
|
+
current: number;
|
|
89
|
+
total: number;
|
|
90
|
+
percent: number;
|
|
91
|
+
}) => void;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* OAuth API Types
|
|
95
|
+
*
|
|
96
|
+
* Types for OAuth authentication flow
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* OAuth token response
|
|
101
|
+
*/
|
|
102
|
+
interface OAuthTokenResponse {
|
|
103
|
+
access_token: string;
|
|
104
|
+
token_type: string;
|
|
105
|
+
expires_in?: number;
|
|
106
|
+
refresh_token?: string;
|
|
107
|
+
id_token?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* OAuth endpoints for an environment
|
|
111
|
+
*/
|
|
112
|
+
interface OAuthEndpoints {
|
|
113
|
+
authorization: string;
|
|
114
|
+
token: string;
|
|
115
|
+
currentUser: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* OAuth configuration
|
|
119
|
+
*/
|
|
120
|
+
interface OAuthConfig {
|
|
121
|
+
clientId: string;
|
|
122
|
+
redirectUri: string;
|
|
123
|
+
environment?: FamilySearchEnvironment;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* OAuth state validation result
|
|
127
|
+
*/
|
|
128
|
+
interface OAuthStateValidation {
|
|
129
|
+
valid: boolean;
|
|
130
|
+
isLinkMode: boolean;
|
|
131
|
+
lang?: string;
|
|
132
|
+
parentUid?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* FamilySearch OAuth Authentication Module
|
|
137
|
+
*
|
|
138
|
+
* Provides OAuth 2.0 authentication utilities for FamilySearch API v3.
|
|
139
|
+
* This module is designed to be framework-agnostic and can be used
|
|
140
|
+
* in any JavaScript/TypeScript environment.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
declare const OAUTH_ENDPOINTS: Record<FamilySearchEnvironment, OAuthEndpoints>;
|
|
144
|
+
/**
|
|
145
|
+
* Get OAuth endpoints for a specific environment
|
|
146
|
+
*/
|
|
147
|
+
declare function getOAuthEndpoints(environment?: FamilySearchEnvironment): OAuthEndpoints;
|
|
148
|
+
/**
|
|
149
|
+
* Generate a cryptographically secure random state for CSRF protection
|
|
150
|
+
*/
|
|
151
|
+
declare function generateOAuthState(): string;
|
|
152
|
+
/**
|
|
153
|
+
* Build the authorization URL for OAuth flow
|
|
154
|
+
*/
|
|
155
|
+
declare function buildAuthorizationUrl(config: OAuthConfig, state: string, options?: {
|
|
156
|
+
scopes?: string[];
|
|
157
|
+
prompt?: string;
|
|
158
|
+
}): string;
|
|
159
|
+
/**
|
|
160
|
+
* Exchange authorization code for access token
|
|
161
|
+
*/
|
|
162
|
+
declare function exchangeCodeForToken(code: string, config: OAuthConfig): Promise<OAuthTokenResponse>;
|
|
163
|
+
/**
|
|
164
|
+
* Refresh an access token using a refresh token
|
|
165
|
+
*/
|
|
166
|
+
declare function refreshAccessToken(refreshToken: string, config: OAuthConfig): Promise<OAuthTokenResponse>;
|
|
167
|
+
/**
|
|
168
|
+
* Validate an access token by making a test API call
|
|
169
|
+
*/
|
|
170
|
+
declare function validateAccessToken(accessToken: string, environment?: FamilySearchEnvironment): Promise<boolean>;
|
|
171
|
+
/**
|
|
172
|
+
* Get user info from access token
|
|
173
|
+
*/
|
|
174
|
+
declare function getUserInfo(accessToken: string, environment?: FamilySearchEnvironment): Promise<{
|
|
175
|
+
sub: string;
|
|
176
|
+
name?: string;
|
|
177
|
+
given_name?: string;
|
|
178
|
+
family_name?: string;
|
|
179
|
+
email?: string;
|
|
180
|
+
email_verified?: boolean;
|
|
181
|
+
} | null>;
|
|
182
|
+
/**
|
|
183
|
+
* Storage keys for OAuth state management
|
|
184
|
+
*/
|
|
185
|
+
declare const OAUTH_STORAGE_KEYS: {
|
|
186
|
+
readonly state: "fs_oauth_state";
|
|
187
|
+
readonly linkMode: "fs_oauth_link_mode";
|
|
188
|
+
readonly lang: "fs_oauth_lang";
|
|
189
|
+
readonly parentUid: "fs_oauth_parent_uid";
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Store OAuth state in localStorage for popup flow
|
|
193
|
+
* Uses localStorage instead of sessionStorage because popup windows
|
|
194
|
+
* don't share sessionStorage with the parent window
|
|
195
|
+
*/
|
|
196
|
+
declare function storeOAuthState(state: string, options?: {
|
|
197
|
+
isLinkMode?: boolean;
|
|
198
|
+
lang?: string;
|
|
199
|
+
parentUid?: string;
|
|
200
|
+
}): void;
|
|
201
|
+
/**
|
|
202
|
+
* Validate OAuth state from callback and extract metadata
|
|
203
|
+
* Returns invalid state if localStorage is not available (SSR/Node.js environments)
|
|
204
|
+
*/
|
|
205
|
+
declare function validateOAuthState(state: string): OAuthStateValidation;
|
|
206
|
+
/**
|
|
207
|
+
* Open OAuth authorization in a popup window
|
|
208
|
+
*/
|
|
209
|
+
declare function openOAuthPopup(authUrl: string, options?: {
|
|
210
|
+
width?: number;
|
|
211
|
+
height?: number;
|
|
212
|
+
windowName?: string;
|
|
213
|
+
}): Window | null;
|
|
214
|
+
/**
|
|
215
|
+
* Parse OAuth callback parameters from URL
|
|
216
|
+
*/
|
|
217
|
+
declare function parseCallbackParams(url?: string): {
|
|
218
|
+
code?: string;
|
|
219
|
+
state?: string;
|
|
220
|
+
error?: string;
|
|
221
|
+
error_description?: string;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Generate a storage key scoped to a user ID
|
|
225
|
+
*/
|
|
226
|
+
declare function getTokenStorageKey(userId: string, type: "access" | "expires" | "refresh" | "environment"): string;
|
|
227
|
+
/**
|
|
228
|
+
* Store access token with expiration
|
|
229
|
+
* Per FamilySearch compatibility requirements:
|
|
230
|
+
* - Access tokens stored in sessionStorage (cleared on browser close)
|
|
231
|
+
* - Refresh tokens stored in localStorage (for re-authentication)
|
|
232
|
+
*/
|
|
233
|
+
declare function storeTokens(userId: string, tokens: {
|
|
234
|
+
accessToken: string;
|
|
235
|
+
expiresAt?: number;
|
|
236
|
+
refreshToken?: string;
|
|
237
|
+
environment?: string;
|
|
238
|
+
}): void;
|
|
239
|
+
/**
|
|
240
|
+
* Get stored access token
|
|
241
|
+
*/
|
|
242
|
+
declare function getStoredAccessToken(userId: string): string | null;
|
|
243
|
+
/**
|
|
244
|
+
* Get stored refresh token
|
|
245
|
+
*/
|
|
246
|
+
declare function getStoredRefreshToken(userId: string): string | null;
|
|
247
|
+
/**
|
|
248
|
+
* Clear all stored tokens for a user
|
|
249
|
+
*/
|
|
250
|
+
declare function clearStoredTokens(userId: string): void;
|
|
251
|
+
/**
|
|
252
|
+
* Clear all FamilySearch tokens from storage
|
|
253
|
+
*/
|
|
254
|
+
declare function clearAllTokens(): void;
|
|
255
|
+
/**
|
|
256
|
+
* OAuthAPI class provides convenient OAuth methods.
|
|
257
|
+
*
|
|
258
|
+
* Note: Most OAuth operations don't require SDK instance as they are stateless
|
|
259
|
+
* utility functions, but having them in a class provides consistency with other
|
|
260
|
+
* API modules and allows future extension.
|
|
261
|
+
*/
|
|
262
|
+
declare class OAuthAPI {
|
|
263
|
+
private config;
|
|
264
|
+
constructor(config: OAuthConfig);
|
|
265
|
+
/**
|
|
266
|
+
* Get OAuth endpoints for current environment
|
|
267
|
+
*/
|
|
268
|
+
getEndpoints(): OAuthEndpoints;
|
|
269
|
+
/**
|
|
270
|
+
* Generate a cryptographically secure random state
|
|
271
|
+
*/
|
|
272
|
+
generateState(): string;
|
|
273
|
+
/**
|
|
274
|
+
* Build authorization URL
|
|
275
|
+
*/
|
|
276
|
+
buildAuthorizationUrl(state: string, options?: {
|
|
277
|
+
scopes?: string[];
|
|
278
|
+
prompt?: string;
|
|
279
|
+
}): string;
|
|
280
|
+
/**
|
|
281
|
+
* Exchange authorization code for access token
|
|
282
|
+
*/
|
|
283
|
+
exchangeCodeForToken(code: string): Promise<OAuthTokenResponse>;
|
|
284
|
+
/**
|
|
285
|
+
* Refresh an access token
|
|
286
|
+
*/
|
|
287
|
+
refreshAccessToken(refreshToken: string): Promise<OAuthTokenResponse>;
|
|
288
|
+
/**
|
|
289
|
+
* Validate an access token
|
|
290
|
+
*/
|
|
291
|
+
validateAccessToken(accessToken: string): Promise<boolean>;
|
|
292
|
+
/**
|
|
293
|
+
* Get user info from access token
|
|
294
|
+
*/
|
|
295
|
+
getUserInfo(accessToken: string): Promise<{
|
|
296
|
+
sub: string;
|
|
297
|
+
name?: string;
|
|
298
|
+
given_name?: string;
|
|
299
|
+
family_name?: string;
|
|
300
|
+
email?: string;
|
|
301
|
+
email_verified?: boolean;
|
|
302
|
+
} | null>;
|
|
303
|
+
/**
|
|
304
|
+
* Store OAuth state in localStorage
|
|
305
|
+
*/
|
|
306
|
+
storeState(state: string, options?: {
|
|
307
|
+
isLinkMode?: boolean;
|
|
308
|
+
lang?: string;
|
|
309
|
+
parentUid?: string;
|
|
310
|
+
}): void;
|
|
311
|
+
/**
|
|
312
|
+
* Validate OAuth state from callback
|
|
313
|
+
*/
|
|
314
|
+
validateState(state: string): OAuthStateValidation;
|
|
315
|
+
/**
|
|
316
|
+
* Open OAuth authorization in popup
|
|
317
|
+
*/
|
|
318
|
+
openPopup(authUrl: string, options?: {
|
|
319
|
+
width?: number;
|
|
320
|
+
height?: number;
|
|
321
|
+
windowName?: string;
|
|
322
|
+
}): Window | null;
|
|
323
|
+
/**
|
|
324
|
+
* Parse OAuth callback parameters from URL
|
|
325
|
+
*/
|
|
326
|
+
parseCallbackParams(url?: string): {
|
|
327
|
+
code?: string;
|
|
328
|
+
state?: string;
|
|
329
|
+
error?: string;
|
|
330
|
+
error_description?: string;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Store tokens for a user
|
|
334
|
+
*/
|
|
335
|
+
storeTokens(userId: string, tokens: {
|
|
336
|
+
accessToken: string;
|
|
337
|
+
expiresAt?: number;
|
|
338
|
+
refreshToken?: string;
|
|
339
|
+
environment?: string;
|
|
340
|
+
}): void;
|
|
341
|
+
/**
|
|
342
|
+
* Get stored access token for a user
|
|
343
|
+
*/
|
|
344
|
+
getStoredAccessToken(userId: string): string | null;
|
|
345
|
+
/**
|
|
346
|
+
* Get stored refresh token for a user
|
|
347
|
+
*/
|
|
348
|
+
getStoredRefreshToken(userId: string): string | null;
|
|
349
|
+
/**
|
|
350
|
+
* Clear all stored tokens for a user
|
|
351
|
+
*/
|
|
352
|
+
clearStoredTokens(userId: string): void;
|
|
353
|
+
/**
|
|
354
|
+
* Clear all FamilySearch tokens from storage
|
|
355
|
+
*/
|
|
356
|
+
clearAllTokens(): void;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export { type EnvironmentConfig as E, type FamilySearchApiResponse as F, type OAuthTokenResponse as O, type ProgressCallback as P, type RateLimiterConfig as R, type SDKLogger as S, type FamilySearchEnvironment as a, type FamilySearchSDKConfig as b, type FamilySearchApiError as c, type OAuthEndpoints as d, type OAuthConfig as e, type OAuthStateValidation as f, getOAuthEndpoints as g, generateOAuthState as h, buildAuthorizationUrl as i, exchangeCodeForToken as j, getUserInfo as k, OAUTH_STORAGE_KEYS as l, validateOAuthState as m, getTokenStorageKey as n, openOAuthPopup as o, parseCallbackParams as p, storeTokens as q, refreshAccessToken as r, storeOAuthState as s, getStoredAccessToken as t, getStoredRefreshToken as u, validateAccessToken as v, clearStoredTokens as w, clearAllTokens as x, OAUTH_ENDPOINTS as y, OAuthAPI as z };
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core SDK Types
|
|
3
|
+
*
|
|
4
|
+
* Environment configuration, SDK initialization, and base API types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* FamilySearch API environment
|
|
8
|
+
*/
|
|
9
|
+
type FamilySearchEnvironment = "production" | "beta" | "integration";
|
|
10
|
+
/**
|
|
11
|
+
* Environment-specific endpoint configuration
|
|
12
|
+
*/
|
|
13
|
+
interface EnvironmentConfig {
|
|
14
|
+
/** Identity server host for OAuth */
|
|
15
|
+
identHost: string;
|
|
16
|
+
/** Platform API host for data operations */
|
|
17
|
+
platformHost: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Rate limiter configuration
|
|
21
|
+
*/
|
|
22
|
+
interface RateLimiterConfig {
|
|
23
|
+
/** Maximum requests per second (default: 10) */
|
|
24
|
+
requestsPerSecond?: number;
|
|
25
|
+
/** Maximum burst size (default: 20) */
|
|
26
|
+
maxBurst?: number;
|
|
27
|
+
/** Maximum retry attempts for 429 errors (default: 3) */
|
|
28
|
+
maxRetries?: number;
|
|
29
|
+
/** Initial backoff delay in ms (default: 1000) */
|
|
30
|
+
initialBackoffMs?: number;
|
|
31
|
+
/** Maximum backoff delay in ms (default: 30000) */
|
|
32
|
+
maxBackoffMs?: number;
|
|
33
|
+
/** Jitter factor (0-1) to add randomness to backoff delays (default: 0.3 = 30%) */
|
|
34
|
+
jitterFactor?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* SDK initialization options
|
|
38
|
+
*/
|
|
39
|
+
interface FamilySearchSDKConfig {
|
|
40
|
+
/** API environment (default: "integration") */
|
|
41
|
+
environment?: FamilySearchEnvironment;
|
|
42
|
+
/** OAuth access token */
|
|
43
|
+
accessToken?: string;
|
|
44
|
+
/** Application key for API requests */
|
|
45
|
+
appKey?: string;
|
|
46
|
+
/** OAuth redirect URI (required for OAuth flows) */
|
|
47
|
+
redirectUri?: string;
|
|
48
|
+
/** Optional logger for debugging */
|
|
49
|
+
logger?: SDKLogger;
|
|
50
|
+
/** Optional rate limiter configuration */
|
|
51
|
+
rateLimiter?: RateLimiterConfig;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Logger interface for SDK debugging
|
|
55
|
+
*/
|
|
56
|
+
interface SDKLogger {
|
|
57
|
+
log: (message: string, ...args: unknown[]) => void;
|
|
58
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
59
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generic API response wrapper
|
|
63
|
+
*/
|
|
64
|
+
interface FamilySearchApiResponse<T> {
|
|
65
|
+
/** Response data */
|
|
66
|
+
data?: T;
|
|
67
|
+
/** HTTP status code */
|
|
68
|
+
statusCode: number;
|
|
69
|
+
/** HTTP status text */
|
|
70
|
+
statusText: string;
|
|
71
|
+
/** Response headers */
|
|
72
|
+
headers: Record<string, string>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* API error with additional context
|
|
76
|
+
*/
|
|
77
|
+
interface FamilySearchApiError extends Error {
|
|
78
|
+
/** HTTP status code if available */
|
|
79
|
+
statusCode?: number;
|
|
80
|
+
/** Full response object */
|
|
81
|
+
response?: FamilySearchApiResponse<unknown>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Progress callback for long operations
|
|
85
|
+
*/
|
|
86
|
+
type ProgressCallback = (progress: {
|
|
87
|
+
stage: string;
|
|
88
|
+
current: number;
|
|
89
|
+
total: number;
|
|
90
|
+
percent: number;
|
|
91
|
+
}) => void;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* OAuth API Types
|
|
95
|
+
*
|
|
96
|
+
* Types for OAuth authentication flow
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* OAuth token response
|
|
101
|
+
*/
|
|
102
|
+
interface OAuthTokenResponse {
|
|
103
|
+
access_token: string;
|
|
104
|
+
token_type: string;
|
|
105
|
+
expires_in?: number;
|
|
106
|
+
refresh_token?: string;
|
|
107
|
+
id_token?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* OAuth endpoints for an environment
|
|
111
|
+
*/
|
|
112
|
+
interface OAuthEndpoints {
|
|
113
|
+
authorization: string;
|
|
114
|
+
token: string;
|
|
115
|
+
currentUser: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* OAuth configuration
|
|
119
|
+
*/
|
|
120
|
+
interface OAuthConfig {
|
|
121
|
+
clientId: string;
|
|
122
|
+
redirectUri: string;
|
|
123
|
+
environment?: FamilySearchEnvironment;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* OAuth state validation result
|
|
127
|
+
*/
|
|
128
|
+
interface OAuthStateValidation {
|
|
129
|
+
valid: boolean;
|
|
130
|
+
isLinkMode: boolean;
|
|
131
|
+
lang?: string;
|
|
132
|
+
parentUid?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* FamilySearch OAuth Authentication Module
|
|
137
|
+
*
|
|
138
|
+
* Provides OAuth 2.0 authentication utilities for FamilySearch API v3.
|
|
139
|
+
* This module is designed to be framework-agnostic and can be used
|
|
140
|
+
* in any JavaScript/TypeScript environment.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
declare const OAUTH_ENDPOINTS: Record<FamilySearchEnvironment, OAuthEndpoints>;
|
|
144
|
+
/**
|
|
145
|
+
* Get OAuth endpoints for a specific environment
|
|
146
|
+
*/
|
|
147
|
+
declare function getOAuthEndpoints(environment?: FamilySearchEnvironment): OAuthEndpoints;
|
|
148
|
+
/**
|
|
149
|
+
* Generate a cryptographically secure random state for CSRF protection
|
|
150
|
+
*/
|
|
151
|
+
declare function generateOAuthState(): string;
|
|
152
|
+
/**
|
|
153
|
+
* Build the authorization URL for OAuth flow
|
|
154
|
+
*/
|
|
155
|
+
declare function buildAuthorizationUrl(config: OAuthConfig, state: string, options?: {
|
|
156
|
+
scopes?: string[];
|
|
157
|
+
prompt?: string;
|
|
158
|
+
}): string;
|
|
159
|
+
/**
|
|
160
|
+
* Exchange authorization code for access token
|
|
161
|
+
*/
|
|
162
|
+
declare function exchangeCodeForToken(code: string, config: OAuthConfig): Promise<OAuthTokenResponse>;
|
|
163
|
+
/**
|
|
164
|
+
* Refresh an access token using a refresh token
|
|
165
|
+
*/
|
|
166
|
+
declare function refreshAccessToken(refreshToken: string, config: OAuthConfig): Promise<OAuthTokenResponse>;
|
|
167
|
+
/**
|
|
168
|
+
* Validate an access token by making a test API call
|
|
169
|
+
*/
|
|
170
|
+
declare function validateAccessToken(accessToken: string, environment?: FamilySearchEnvironment): Promise<boolean>;
|
|
171
|
+
/**
|
|
172
|
+
* Get user info from access token
|
|
173
|
+
*/
|
|
174
|
+
declare function getUserInfo(accessToken: string, environment?: FamilySearchEnvironment): Promise<{
|
|
175
|
+
sub: string;
|
|
176
|
+
name?: string;
|
|
177
|
+
given_name?: string;
|
|
178
|
+
family_name?: string;
|
|
179
|
+
email?: string;
|
|
180
|
+
email_verified?: boolean;
|
|
181
|
+
} | null>;
|
|
182
|
+
/**
|
|
183
|
+
* Storage keys for OAuth state management
|
|
184
|
+
*/
|
|
185
|
+
declare const OAUTH_STORAGE_KEYS: {
|
|
186
|
+
readonly state: "fs_oauth_state";
|
|
187
|
+
readonly linkMode: "fs_oauth_link_mode";
|
|
188
|
+
readonly lang: "fs_oauth_lang";
|
|
189
|
+
readonly parentUid: "fs_oauth_parent_uid";
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Store OAuth state in localStorage for popup flow
|
|
193
|
+
* Uses localStorage instead of sessionStorage because popup windows
|
|
194
|
+
* don't share sessionStorage with the parent window
|
|
195
|
+
*/
|
|
196
|
+
declare function storeOAuthState(state: string, options?: {
|
|
197
|
+
isLinkMode?: boolean;
|
|
198
|
+
lang?: string;
|
|
199
|
+
parentUid?: string;
|
|
200
|
+
}): void;
|
|
201
|
+
/**
|
|
202
|
+
* Validate OAuth state from callback and extract metadata
|
|
203
|
+
* Returns invalid state if localStorage is not available (SSR/Node.js environments)
|
|
204
|
+
*/
|
|
205
|
+
declare function validateOAuthState(state: string): OAuthStateValidation;
|
|
206
|
+
/**
|
|
207
|
+
* Open OAuth authorization in a popup window
|
|
208
|
+
*/
|
|
209
|
+
declare function openOAuthPopup(authUrl: string, options?: {
|
|
210
|
+
width?: number;
|
|
211
|
+
height?: number;
|
|
212
|
+
windowName?: string;
|
|
213
|
+
}): Window | null;
|
|
214
|
+
/**
|
|
215
|
+
* Parse OAuth callback parameters from URL
|
|
216
|
+
*/
|
|
217
|
+
declare function parseCallbackParams(url?: string): {
|
|
218
|
+
code?: string;
|
|
219
|
+
state?: string;
|
|
220
|
+
error?: string;
|
|
221
|
+
error_description?: string;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Generate a storage key scoped to a user ID
|
|
225
|
+
*/
|
|
226
|
+
declare function getTokenStorageKey(userId: string, type: "access" | "expires" | "refresh" | "environment"): string;
|
|
227
|
+
/**
|
|
228
|
+
* Store access token with expiration
|
|
229
|
+
* Per FamilySearch compatibility requirements:
|
|
230
|
+
* - Access tokens stored in sessionStorage (cleared on browser close)
|
|
231
|
+
* - Refresh tokens stored in localStorage (for re-authentication)
|
|
232
|
+
*/
|
|
233
|
+
declare function storeTokens(userId: string, tokens: {
|
|
234
|
+
accessToken: string;
|
|
235
|
+
expiresAt?: number;
|
|
236
|
+
refreshToken?: string;
|
|
237
|
+
environment?: string;
|
|
238
|
+
}): void;
|
|
239
|
+
/**
|
|
240
|
+
* Get stored access token
|
|
241
|
+
*/
|
|
242
|
+
declare function getStoredAccessToken(userId: string): string | null;
|
|
243
|
+
/**
|
|
244
|
+
* Get stored refresh token
|
|
245
|
+
*/
|
|
246
|
+
declare function getStoredRefreshToken(userId: string): string | null;
|
|
247
|
+
/**
|
|
248
|
+
* Clear all stored tokens for a user
|
|
249
|
+
*/
|
|
250
|
+
declare function clearStoredTokens(userId: string): void;
|
|
251
|
+
/**
|
|
252
|
+
* Clear all FamilySearch tokens from storage
|
|
253
|
+
*/
|
|
254
|
+
declare function clearAllTokens(): void;
|
|
255
|
+
/**
|
|
256
|
+
* OAuthAPI class provides convenient OAuth methods.
|
|
257
|
+
*
|
|
258
|
+
* Note: Most OAuth operations don't require SDK instance as they are stateless
|
|
259
|
+
* utility functions, but having them in a class provides consistency with other
|
|
260
|
+
* API modules and allows future extension.
|
|
261
|
+
*/
|
|
262
|
+
declare class OAuthAPI {
|
|
263
|
+
private config;
|
|
264
|
+
constructor(config: OAuthConfig);
|
|
265
|
+
/**
|
|
266
|
+
* Get OAuth endpoints for current environment
|
|
267
|
+
*/
|
|
268
|
+
getEndpoints(): OAuthEndpoints;
|
|
269
|
+
/**
|
|
270
|
+
* Generate a cryptographically secure random state
|
|
271
|
+
*/
|
|
272
|
+
generateState(): string;
|
|
273
|
+
/**
|
|
274
|
+
* Build authorization URL
|
|
275
|
+
*/
|
|
276
|
+
buildAuthorizationUrl(state: string, options?: {
|
|
277
|
+
scopes?: string[];
|
|
278
|
+
prompt?: string;
|
|
279
|
+
}): string;
|
|
280
|
+
/**
|
|
281
|
+
* Exchange authorization code for access token
|
|
282
|
+
*/
|
|
283
|
+
exchangeCodeForToken(code: string): Promise<OAuthTokenResponse>;
|
|
284
|
+
/**
|
|
285
|
+
* Refresh an access token
|
|
286
|
+
*/
|
|
287
|
+
refreshAccessToken(refreshToken: string): Promise<OAuthTokenResponse>;
|
|
288
|
+
/**
|
|
289
|
+
* Validate an access token
|
|
290
|
+
*/
|
|
291
|
+
validateAccessToken(accessToken: string): Promise<boolean>;
|
|
292
|
+
/**
|
|
293
|
+
* Get user info from access token
|
|
294
|
+
*/
|
|
295
|
+
getUserInfo(accessToken: string): Promise<{
|
|
296
|
+
sub: string;
|
|
297
|
+
name?: string;
|
|
298
|
+
given_name?: string;
|
|
299
|
+
family_name?: string;
|
|
300
|
+
email?: string;
|
|
301
|
+
email_verified?: boolean;
|
|
302
|
+
} | null>;
|
|
303
|
+
/**
|
|
304
|
+
* Store OAuth state in localStorage
|
|
305
|
+
*/
|
|
306
|
+
storeState(state: string, options?: {
|
|
307
|
+
isLinkMode?: boolean;
|
|
308
|
+
lang?: string;
|
|
309
|
+
parentUid?: string;
|
|
310
|
+
}): void;
|
|
311
|
+
/**
|
|
312
|
+
* Validate OAuth state from callback
|
|
313
|
+
*/
|
|
314
|
+
validateState(state: string): OAuthStateValidation;
|
|
315
|
+
/**
|
|
316
|
+
* Open OAuth authorization in popup
|
|
317
|
+
*/
|
|
318
|
+
openPopup(authUrl: string, options?: {
|
|
319
|
+
width?: number;
|
|
320
|
+
height?: number;
|
|
321
|
+
windowName?: string;
|
|
322
|
+
}): Window | null;
|
|
323
|
+
/**
|
|
324
|
+
* Parse OAuth callback parameters from URL
|
|
325
|
+
*/
|
|
326
|
+
parseCallbackParams(url?: string): {
|
|
327
|
+
code?: string;
|
|
328
|
+
state?: string;
|
|
329
|
+
error?: string;
|
|
330
|
+
error_description?: string;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Store tokens for a user
|
|
334
|
+
*/
|
|
335
|
+
storeTokens(userId: string, tokens: {
|
|
336
|
+
accessToken: string;
|
|
337
|
+
expiresAt?: number;
|
|
338
|
+
refreshToken?: string;
|
|
339
|
+
environment?: string;
|
|
340
|
+
}): void;
|
|
341
|
+
/**
|
|
342
|
+
* Get stored access token for a user
|
|
343
|
+
*/
|
|
344
|
+
getStoredAccessToken(userId: string): string | null;
|
|
345
|
+
/**
|
|
346
|
+
* Get stored refresh token for a user
|
|
347
|
+
*/
|
|
348
|
+
getStoredRefreshToken(userId: string): string | null;
|
|
349
|
+
/**
|
|
350
|
+
* Clear all stored tokens for a user
|
|
351
|
+
*/
|
|
352
|
+
clearStoredTokens(userId: string): void;
|
|
353
|
+
/**
|
|
354
|
+
* Clear all FamilySearch tokens from storage
|
|
355
|
+
*/
|
|
356
|
+
clearAllTokens(): void;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export { type EnvironmentConfig as E, type FamilySearchApiResponse as F, type OAuthTokenResponse as O, type ProgressCallback as P, type RateLimiterConfig as R, type SDKLogger as S, type FamilySearchEnvironment as a, type FamilySearchSDKConfig as b, type FamilySearchApiError as c, type OAuthEndpoints as d, type OAuthConfig as e, type OAuthStateValidation as f, getOAuthEndpoints as g, generateOAuthState as h, buildAuthorizationUrl as i, exchangeCodeForToken as j, getUserInfo as k, OAUTH_STORAGE_KEYS as l, validateOAuthState as m, getTokenStorageKey as n, openOAuthPopup as o, parseCallbackParams as p, storeTokens as q, refreshAccessToken as r, storeOAuthState as s, getStoredAccessToken as t, getStoredRefreshToken as u, validateAccessToken as v, clearStoredTokens as w, clearAllTokens as x, OAUTH_ENDPOINTS as y, OAuthAPI as z };
|