@softwarepatterns/am 0.0.1 → 0.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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,34 @@
1
+ /**
2
+ * Standard error object following RFC 7807 (Problem Details for HTTP APIs).
3
+ *
4
+ * Returned in AuthError.problem when the server responds with application/problem+json.
5
+ *
6
+ * - `type`: A URI reference that identifies the problem type. Often links to human-readable documentation.
7
+ * - `title`: A short, human-readable summary of the problem type.
8
+ * - `status`: The HTTP status code.
9
+ * - `code`: Application-specific error code for programmatic handling. Maps to the final part of the error type.
10
+ * - `detail`: Human-readable explanation specific to this occurrence. Do not rely on this for programmatic handling.
11
+ * - `invalidParams`: Present on validation errors (typically 400). Provides field-level details
12
+ * for building precise UI feedback and can be used for programmatic handling. Each entry includes:
13
+ * - `in`: Location of the invalid parameter (body, cookie, header, query, path).
14
+ * - `path`: Dot-separated path to the invalid parameter.
15
+ * - `type`: Error type code for this parameter (e.g. "required", "email", "min_length").
16
+ * - `received`: The actual value received.
17
+ * - `expected`: (optional) Description of the expected value.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * catch (e) {
22
+ * if (e instanceof AuthError && e.invalidParams) {
23
+ * const errors = e.invalidParams.reduce((acc, p) => {
24
+ * acc[p.path] = p.type;
25
+ * return acc;
26
+ * }, {} as Record<string, string>);
27
+ * setFieldErrors(errors);
28
+ * }
29
+ * }
30
+ * ```
31
+ */
1
32
  type ProblemDetails = {
2
33
  type: string;
3
34
  title: string;
@@ -12,28 +43,97 @@ type ProblemDetails = {
12
43
  expected?: string;
13
44
  }[];
14
45
  };
46
+ /**
47
+ * Opaque identifier for a client application.
48
+ *
49
+ * Used to look up client-specific settings on how authentication should be handled.
50
+ *
51
+ * All client-specific operations (invites, branding, rate limits) are scoped to a ClientId.
52
+ */
15
53
  type ClientId = `cid${string}`;
54
+ /** Identifier for a user. */
16
55
  type UserId = `uid${string}`;
56
+ /** Identifier for an account (i.e., a billable entity). */
17
57
  type AccountId = `acc${string}`;
58
+ /** Identifier for a membership linking a user to an account. */
18
59
  type MembershipId = `mbr${string}`;
60
+ /**
61
+ * Possible statuses for an account.
62
+ *
63
+ * - active: Normal operation
64
+ * - trial: In trial period
65
+ * - past_due: Payment failed but grace period active
66
+ * - suspended: Access restricted due to billing or policy
67
+ * - closed: Permanently closed
68
+ */
69
+ type AccountStatus = "active" | "trial" | "past_due" | "suspended" | "closed";
70
+ /**
71
+ * Accounts are billable entities that can access resources. Users are linked to accounts via memberships with roles.
72
+ *
73
+ * An account with subaccounts is acting as a tenant, and is used to create services with their own billing,
74
+ * accounts, users, memberships, etc. This is useful for SaaS platforms that want to offer isolated environments
75
+ * for different customers, and to allow reselling of their services to other SaaS providers.
76
+ *
77
+ * For example, an email service lets customers sign up. However, some customers want to offer
78
+ * email services to their own clients. Therefore, the email provider has an account for each customer, and those
79
+ * customers have accounts for their own clients as well. Each level is isolated, with separate billing and users.
80
+ */
81
+ type AccountResource = {
82
+ id: AccountId;
83
+ /** Display name chosen by the account owner */
84
+ name: string | null;
85
+ /** URL to the account's avatar image */
86
+ avatarUrl: string | null;
87
+ /** Current account status */
88
+ status: AccountStatus;
89
+ /** ISO 8601 timestamp until which the account is paid (null if never paid or closed) */
90
+ paidUntil: string | null;
91
+ };
92
+ /**
93
+ * Possible statuses for a user.
94
+ *
95
+ * - active: Normal operation
96
+ * - trial: In trial period
97
+ * - past_due: Payment failed but grace period active
98
+ * - suspended: Access restricted due to billing or policy
99
+ * - closed: Permanently closed
100
+ */
19
101
  type UserStatus = "active" | "trial" | "past_due" | "suspended" | "closed";
102
+ /**
103
+ * A reference to a user. Will not be deleted even due to GDPR requests or account closures,
104
+ * to maintain referential integrity in audit logs and historical records.
105
+ */
20
106
  type UserResource = {
21
107
  id: UserId;
22
108
  accountId: AccountId;
23
109
  status: UserStatus;
24
110
  preferredMembershipId: MembershipId | null;
25
111
  };
112
+ /**
113
+ * Personal identity information (PII) for a user. Will be deleted due to GDPR requests or account
114
+ * closures to respect legal requirements of various regions..
115
+ */
26
116
  type UserIdentity = {
27
117
  id: UserId;
28
118
  avatarUrl: string | null;
119
+ /** External identifier from third-party provider (i.e., SCIM) */
29
120
  externalId: string | null;
30
121
  givenName: string | null;
31
122
  familyName: string | null;
32
123
  displayName: string | null;
124
+ /** Preferred language code (en-CA, fr-FR, zh-CN, etc.) */
33
125
  preferredLanguage: string | null;
126
+ /** Locale code (e.g., "en-US") */
34
127
  locale: string | null;
35
128
  timezone: string | null;
36
129
  };
130
+ /**
131
+ * Roles within an account membership.
132
+ *
133
+ * - owner: Full administrative access, may perform destructive actions.
134
+ * - member: Standard non-destructive access
135
+ * - viewer: Read-only access
136
+ */
37
137
  type MembershipRole = "owner" | "member" | "viewer";
38
138
  type Membership = {
39
139
  id: MembershipId;
@@ -41,34 +141,129 @@ type Membership = {
41
141
  accountId: AccountId;
42
142
  role: MembershipRole;
43
143
  };
144
+ /**
145
+ * Email credential record attached to a user.
146
+ *
147
+ * Sensitive fields (email) are only included when explicitly requested
148
+ * or when the caller has appropriate permissions.
149
+ */
44
150
  type EmailCredential = {
45
151
  id: string;
46
152
  email: string | null;
47
- hashedEmail: string | null;
48
- hashedPassword: string | null;
49
153
  emailVerifiedAt: string | null;
50
154
  };
51
155
  type SessionTokens = {
156
+ /** Signed JWT access token for authenticating API requests */
52
157
  accessToken: string;
158
+ /** Opaque refresh token for obtaining new access tokens */
53
159
  refreshToken: string;
54
160
  tokenType: "Bearer";
161
+ /** Seconds until the access token expires from time of issuance */
55
162
  expiresIn: number;
56
163
  idToken?: string;
164
+ /** Absolute expiration time (milliseconds since epoch) set by the client library */
165
+ expiresAt: number;
57
166
  };
167
+ /**
168
+ * Complete profile of the currently authenticated user.
169
+ *
170
+ * Combines basic user data with identity, credentials, memberships, and freshness timestamp.
171
+ *
172
+ * `lastUpdatedAt` is updated whenever the profile is fetched from the server.
173
+ */
58
174
  type SessionProfile = UserResource & {
59
- identity: UserIdentity;
175
+ identity: UserIdentity | null;
60
176
  emailCredentials: EmailCredential[];
61
177
  memberships: Membership[];
178
+ /** Currently active membership in the accessToken (determined by preferredMembershipId or context) */
62
179
  activeMembership: Membership | null;
180
+ lastUpdatedAt: number;
63
181
  };
64
- type AuthenticationResult = {
65
- session: SessionTokens;
66
- profile: SessionProfile;
182
+ /**
183
+ * Combined authentication state containing tokens and optional profile.
184
+ */
185
+ type Authentication = {
186
+ tokens: SessionTokens;
187
+ profile: SessionProfile | null;
67
188
  };
189
+ /**
190
+ * Result of checkEmail() indicating whether the email is registered.
191
+ */
68
192
  type EmailCheckStatus = "active" | "inactive";
193
+ /**
194
+ * Supported login methods for an email address.
195
+ *
196
+ * Currently limited to email/password and magic link flows.
197
+ */
69
198
  type LoginMethod = "email_password" | "magic_link";
199
+ /**
200
+ * Minimal storage interface required for session persistence.
201
+ *
202
+ * Compatible with localStorage, sessionStorage, AsyncStorage (React Native), or any custom implementation.
203
+ */
204
+ type StorageLike = {
205
+ getItem(key: string): string | null;
206
+ setItem(key: string, value: string): void;
207
+ removeItem(key: string): void;
208
+ };
70
209
 
210
+ type StorageConfig = StorageLike | "localStorage" | null | undefined;
71
211
  type FetchFn = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
212
+ type Config = {
213
+ baseUrl: string;
214
+ earlyRefreshMs: number;
215
+ fetchFn: FetchFn;
216
+ onRefresh?: (tokens: SessionTokens) => void | Promise<void>;
217
+ onProfileRefetch?: (profile: SessionProfile) => void | Promise<void>;
218
+ onUnauthenticated?: (e: AuthError) => void | Promise<void>;
219
+ profileStorageKey: string;
220
+ storage: StorageConfig;
221
+ tokensStorageKey: string;
222
+ };
223
+ /**
224
+ * Error type for authentication-related failures.
225
+ *
226
+ * Always thrown on non-2xx responses from auth endpoints. Contains structured ProblemDetails
227
+ * from the server when available.
228
+ *
229
+ * Most 400 errors will also contain `invalidParams` for parameters that caused
230
+ * the error, which can be used to display field-level validation messages.
231
+ *
232
+ * Note that network errors, timeouts, etc. will throw other Error types (e.g. TypeError) unrelated
233
+ * to AuthError.
234
+ *
235
+ * Note that HTTP error codes are distinctly:
236
+ * - 400: Client error (bad request, invalid input, etc.)
237
+ * - 401: Unauthenticated (we don't know who you are)
238
+ * - 402: Payment required (e.g. billing issue)
239
+ * - 403: Unauthorized (we know who you are, but you don't have permission)
240
+ * - 404: Not found
241
+ * - 409: Conflict (email already registered, user already invited, etc.)
242
+ * - 429: Too many requests (rate limiting)
243
+ * - 500: Internal server error (server's fault)
244
+ *
245
+ * Also note that the `type` field often contains a URI that points to documentation about the
246
+ * specific error type, including how to resolve it, code samples, and links to the RFCs or other
247
+ * standards that define the error.
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * try {
252
+ * const session = await am.signIn({ email: 'test@example.com', password: 'password123' });
253
+ * } catch (e) {
254
+ * if (e instanceof AuthError) {
255
+ * console.error("Authentication failed:", e.title);
256
+ * if (e.invalidParams) {
257
+ * for (const param of e.invalidParams) {
258
+ * console.error(` - Invalid parameter: ${param.path} (${param.type})`);
259
+ * }
260
+ * }
261
+ * } else {
262
+ * console.error("Unexpected error:", e);
263
+ * }
264
+ * }
265
+ * ```
266
+ */
72
267
  declare class AuthError extends Error {
73
268
  readonly problem: ProblemDetails;
74
269
  constructor(problem: ProblemDetails);
@@ -79,48 +274,177 @@ declare class AuthError extends Error {
79
274
  get detail(): string | undefined;
80
275
  get invalidParams(): ProblemDetails["invalidParams"] | undefined;
81
276
  }
82
- type Config = {
83
- fetchFn: FetchFn;
84
- baseUrl: string;
85
- };
277
+ /**
278
+ * You receive an AuthSession after successful sign-in/register/etc.
279
+ *
280
+ * It contains the current access token, user profile, and methods to perform authorized
281
+ * requests.
282
+ *
283
+ * Features:
284
+ * - session.fetch() will always use a valid access token (refreshing automatically)
285
+ * - All non-2xx responses throw AuthError
286
+ * - Tokens and profile are automatically persisted to storage (if configured)
287
+ */
86
288
  declare class AuthSession {
87
- private tokens;
88
- private config;
89
- private lastUpdated;
90
- constructor(tokens: SessionTokens, config: Partial<Config>);
91
- get accessToken(): string;
92
- get refreshToken(): string;
93
- get idToken(): string | undefined;
94
- get tokenType(): "Bearer";
95
- get expiresIn(): number;
96
- get lastUpdatedAt(): Date;
97
- get expiresAt(): Date;
289
+ constructor(initial: Authentication, config: Partial<Config>);
290
+ /**
291
+ * Restores an AuthSession from persisted storage. Returns null if no valid session
292
+ * is found.
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * const session = AuthSession.restoreSession();
297
+ * if (session) {
298
+ * console.log("Restored session for user:", session.profile);
299
+ * } else {
300
+ * console.log("No valid session found.");
301
+ * }
302
+ * ```
303
+ */
304
+ static restoreSession(config?: Partial<Config>): AuthSession | null;
305
+ /**
306
+ * Removes all persisted data (tokens, profile) from storage, and prevents future
307
+ * refreshs of token and profile data. Does NOT clear current token or profile data from the
308
+ * session memory, but effectively deactivates the session for future use.
309
+ */
310
+ clear(): void;
311
+ accessToken(): string;
312
+ refreshToken(): string;
313
+ idToken(): string | undefined;
314
+ expiresIn(): number;
315
+ expiresAt(): Date;
316
+ profile(): SessionProfile | null;
317
+ toJSON(): Authentication;
318
+ /**
319
+ * Creates an AuthSession from existing authentication data. Useful for restoring
320
+ * a session from custom storage or creating a session from custom server-provided data.
321
+ */
322
+ static fromJSON(initial: Authentication, config: Partial<Config>): AuthSession;
323
+ /**
324
+ * Returns true if the access token is expired or will expire soon. The
325
+ * "soon" threshold is configured via Config.earlyRefreshMs (default 1 minute).
326
+ */
98
327
  isExpired(): boolean;
99
328
  /**
100
- * Fetch with automatic token refresh.
329
+ * Perform an authenticated fetch. Used to call your own APIs with the current
330
+ * session's access token. Any service can validate the token against Am's public
331
+ * keys at https://api.accountmaker.com/.well-known/jwks.json?client_id={clientId}
332
+ *
333
+ * Automatically:
334
+ * - Adds Authorization header
335
+ * - Refreshes token if expired
336
+ * - Retries once on 401 if refresh succeeds
337
+ *
338
+ * Assumes the response is JSON and parses it. Throws AuthError on non-2xx responses.
101
339
  *
102
- * If the access token is expired, it will be refreshed before making the request. The
103
- * Authorization header will be set with the current access token.
340
+ * If the error is a RFC 7807 Problem Details response, the AuthError.problem
341
+ * will contain the full details.
342
+ *
343
+ * @example
344
+ * ```ts
345
+ * const res = await session.fetch('/api/projects');
346
+ * const projects = await res.json();
347
+ * ```
348
+ *
349
+ * Throws AuthError on network errors, etc.
350
+ * @throws AuthError
351
+ */
352
+ fetch(url: string | URL, init?: RequestInit): Promise<any>;
353
+ /**
354
+ * Refreshes the access token using the refresh token. Updates the stored tokens on
355
+ * success. This is called automatically by fetch() if the token is expired or close to
356
+ * expiring.
104
357
  */
105
- fetch(url: string | URL | Request, init?: RequestInit): Promise<Response>;
106
358
  refresh(): Promise<void>;
359
+ /**
360
+ * Refetches the user's profile from the server and updates the stored profile.
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * await session.refetchProfile();
365
+ * console.log("Updated profile:", session.profile);
366
+ * ```
367
+ *
368
+ * Throws AuthError on network errors, etc.
369
+ * @throws AuthError
370
+ */
371
+ refetchProfile(): Promise<void>;
372
+ /**
373
+ * Sends a verification email to the user's primary email address. This only succeeds if
374
+ * called by the currently authenticated user or an account admin.
375
+ *
376
+ * Throws AuthError on network errors, etc.
377
+ * @throws AuthError
378
+ */
107
379
  sendVerificationEmail(): Promise<void>;
108
- me(): Promise<SessionProfile>;
380
+ /**
381
+ * Fetches a user by ID.
382
+ *
383
+ * Throws AuthError on invalid user ID, network errors, etc.
384
+ * @throws AuthError
385
+ */
109
386
  user(id: UserId): Promise<UserResource>;
110
387
  }
388
+ /**
389
+ * Use `Am` to perform initial sign-in, registration, password reset flows, magic links,
390
+ * invite acceptance, and other unauthenticated actions.
391
+ *
392
+ * Once authentication succeeds, these methods return an `AuthSession` that you use
393
+ * for all subsequent authenticated requests.
394
+ *
395
+ * Example:
396
+ * ```ts
397
+ * const am = new Am();
398
+ * const session = await am.signIn({ email: 'user@example.com', password: 'secret' });
399
+ * // Now use `session` for protected API calls
400
+ * ```
401
+ */
111
402
  declare class Am {
112
403
  private options;
113
404
  constructor(config?: Partial<Config>);
114
- static createAuthSession(tokens: SessionTokens, config?: Partial<Config>): AuthSession;
115
- createAuthSession(tokens: SessionTokens): AuthSession;
405
+ /**
406
+ * Creates an AuthSession from existing authentication data. Useful for restoring
407
+ * a session from custom storage or creating a session from custom server-provided data.
408
+ */
409
+ static createAuthSession(initial: Authentication, config?: Partial<Config>): AuthSession;
410
+ /**
411
+ * Creates an AuthSession from existing authentication data. Useful for restoring
412
+ * a session from custom storage or creating a session from custom server-provided data.
413
+ */
414
+ createAuthSession(initial: Authentication): AuthSession;
415
+ /**
416
+ * Accepts an invitation to join an account. On success, returns an AuthSession
417
+ * containing fresh tokens and profile. Tokens are automatically persisted (if
418
+ * storage is enabled).
419
+ *
420
+ * Throws AuthError on invalid or expired token, etc.
421
+ * @throws AuthError
422
+ */
116
423
  static acceptInvite(query: {
117
424
  clientId: ClientId;
118
425
  token: string;
119
- }, config?: Partial<Config>): Promise<AuthenticationResult>;
426
+ }, config?: Partial<Config>): Promise<AuthSession>;
427
+ /**
428
+ * Accepts an invitation to join an account. On success, returns an AuthSession
429
+ * containing fresh tokens and profile. Tokens are automatically persisted (if
430
+ * storage is enabled).
431
+ *
432
+ * Throws AuthError on invalid or expired token, etc.
433
+ * @throws AuthError
434
+ */
120
435
  acceptInvite(query: {
121
436
  clientId: ClientId;
122
437
  token: string;
123
- }): Promise<AuthenticationResult>;
438
+ }): Promise<AuthSession>;
439
+ /**
440
+ * Checks the status of an email address for authentication purposes. Indicates whether the
441
+ * email is associated with an active account, and what login methods are preferred and
442
+ * available for that user. This can be used to enforce login expierences for enterprise SSO or
443
+ * to prefer passwordless login methods.
444
+ *
445
+ * Throws AuthError on invalid client ID, network errors, etc.
446
+ * @throws AuthError
447
+ */
124
448
  static checkEmail(body: {
125
449
  clientId: ClientId;
126
450
  email: string;
@@ -130,6 +454,15 @@ declare class Am {
130
454
  preferred: LoginMethod[];
131
455
  available: LoginMethod[];
132
456
  }>;
457
+ /**
458
+ * Checks the status of an email address for authentication purposes. Indicates whether the
459
+ * email is associated with an active account, and what login methods are preferred and
460
+ * available for that user. This can be used to enforce login expierences for enterprise SSO or
461
+ * to prefer passwordless login methods.
462
+ *
463
+ * Throws AuthError on invalid client ID, network errors, etc.
464
+ * @throws AuthError
465
+ */
133
466
  checkEmail(body: {
134
467
  clientId: ClientId;
135
468
  email: string;
@@ -139,67 +472,207 @@ declare class Am {
139
472
  preferred: LoginMethod[];
140
473
  available: LoginMethod[];
141
474
  }>;
475
+ /**
476
+ * When called, sets a httpOnly CSRF session cookie. Then when rendering a form, call csrfToken()
477
+ * to get the signed token to include in the form. When the form is submitted, the server
478
+ * will verify the signed token against the session cookie. This prevents a certain class
479
+ * of CSRF attacks that rely on being able to read values from the target site.
480
+ */
142
481
  static csrfSession(config?: Partial<Config>): Promise<{
143
482
  csrfToken: string;
144
483
  }>;
484
+ /**
485
+ * When called, sets a httpOnly CSRF session cookie. Then when rendering a form, call csrfToken()
486
+ * to get the signed token to include in the form. When the form is submitted, the server
487
+ * will verify the signed token against the session cookie. This prevents a certain class
488
+ * of CSRF attacks that rely on being able to read values from the target site.
489
+ */
145
490
  csrfSession(): Promise<{
146
491
  csrfToken: string;
147
492
  }>;
493
+ /**
494
+ * Fetches a signed CSRF token for use in forms. Call csrfSession() first to set a httpOnly CSRF
495
+ * session cookie, then call this method to get the signed token, then include the token in your
496
+ * form submissions. When the form is submitted, the server will verify the signed token against
497
+ * the httpOnly session cookie. This prevents a certain class of CSRF attacks that rely on being
498
+ * able to read values from the target site.
499
+ *
500
+ * @throws AuthError
501
+ */
148
502
  static csrfToken(config?: Partial<Config>): Promise<{
149
503
  csrfToken: string;
150
504
  }>;
505
+ /**
506
+ * Fetches a signed CSRF token for use in forms. Call csrfSession() first to set a httpOnly CSRF
507
+ * session cookie, then call this method to get the signed token, then include the token in your
508
+ * form submissions. When the form is submitted, the server will verify the signed token against
509
+ * the httpOnly session cookie. This prevents a certain class of CSRF attacks that rely on being
510
+ * able to read values from the target site.
511
+ *
512
+ * @throws AuthError
513
+ */
151
514
  csrfToken(): Promise<{
152
515
  csrfToken: string;
153
516
  }>;
154
- static login(body: {
517
+ /**
518
+ * On success, returns an AuthSession containing fresh tokens and profile.
519
+ * Tokens are automatically persisted (if storage is enabled).
520
+ *
521
+ * Throws AuthError on invalid credentials, unverified email, etc.
522
+ * @throws AuthError
523
+ */
524
+ static signIn(body: {
525
+ clientId: ClientId;
155
526
  email: string;
156
527
  password: string;
157
528
  csrfToken?: string;
158
- }, config?: Partial<Config>): Promise<AuthenticationResult>;
159
- login(body: {
529
+ }, config?: Partial<Config>): Promise<AuthSession>;
530
+ /**
531
+ * On success, returns an AuthSession containing fresh tokens and profile.
532
+ * Tokens are automatically persisted (if storage is enabled).
533
+ *
534
+ * Throws AuthError on invalid credentials, unverified email, etc.
535
+ * @throws AuthError
536
+ */
537
+ signIn(body: {
538
+ clientId: ClientId;
160
539
  email: string;
161
540
  password: string;
162
541
  csrfToken?: string;
163
- }): Promise<AuthenticationResult>;
164
- static tokenLogin(token: string, config?: Partial<Config>): Promise<AuthenticationResult>;
165
- tokenLogin(token: string): Promise<AuthenticationResult>;
542
+ }): Promise<AuthSession>;
543
+ /**
544
+ * Authenticates using a one-time token (e.g., magic link or invite token).
545
+ *
546
+ * On success, returns an AuthSession containing fresh tokens and profile.
547
+ * Tokens are automatically persisted (if storage is enabled).
548
+ *
549
+ * Throws AuthError on invalid or expired token, etc.
550
+ * @throws AuthError
551
+ */
552
+ static signInWithToken(token: string, config?: Partial<Config>): Promise<AuthSession>;
553
+ /**
554
+ * Authenticates using a one-time token (e.g., magic link or invite token).
555
+ *
556
+ * On success, returns an AuthSession containing fresh tokens and profile.
557
+ * Tokens are automatically persisted (if storage is enabled).
558
+ *
559
+ * Throws AuthError on invalid or expired token, etc.
560
+ * @throws AuthError
561
+ */
562
+ signInWithToken(token: string): Promise<AuthSession>;
563
+ /**
564
+ * Manually refreshes session tokens using the provided refresh token. Does NOT
565
+ * persist tokens. Use AuthSession.refresh() to refresh and persist tokens in an
566
+ * existing session.
567
+ *
568
+ * Throws AuthError on invalid or expired refresh token, etc.
569
+ * @throws AuthError
570
+ */
166
571
  static refresh(refreshToken: string, config?: Partial<Config>): Promise<SessionTokens>;
572
+ /**
573
+ * Manually refreshes session tokens using the provided refresh token. Does NOT
574
+ * persist tokens. Use AuthSession.refresh() to refresh and persist tokens in an
575
+ * existing session.
576
+ *
577
+ * Throws AuthError on invalid or expired refresh token, etc.
578
+ * @throws AuthError
579
+ */
167
580
  refresh(refreshToken: string): Promise<SessionTokens>;
168
- static register(body: {
581
+ /**
582
+ * Successful registration immediately authenticates the user and returns an
583
+ * AuthSession. Tokens are automatically persisted (if storage is enabled).
584
+ *
585
+ * Throws AuthError on invalid data, existing email, etc.
586
+ * @throws AuthError
587
+ */
588
+ static signUp(body: {
589
+ clientId: ClientId;
169
590
  email: string;
170
591
  password: string;
171
592
  csrfToken?: string;
172
- }, config?: Partial<Config>): Promise<AuthenticationResult>;
173
- register(body: {
593
+ }, config?: Partial<Config>): Promise<AuthSession>;
594
+ /**
595
+ * Successful registration immediately authenticates the user and returns an
596
+ * AuthSession. Tokens are automatically persisted (if storage is enabled).
597
+ *
598
+ * Throws AuthError on invalid data, existing email, etc.
599
+ * @throws AuthError
600
+ */
601
+ signUp(body: {
602
+ clientId: ClientId;
174
603
  email: string;
175
604
  password: string;
176
605
  csrfToken?: string;
177
- }): Promise<AuthenticationResult>;
606
+ }): Promise<AuthSession>;
607
+ /**
608
+ * Completes a password reset using the token received via email. On success,
609
+ * the user's password is updated.
610
+ *
611
+ * Throws AuthError on invalid or expired token, weak password, etc.
612
+ * @throws AuthError
613
+ */
178
614
  static resetPassword(body: {
179
615
  token: string;
180
616
  newPassword: string;
181
617
  }, config?: Partial<Config>): Promise<void>;
618
+ /**
619
+ * Completes a password reset using the token received via email. On success,
620
+ * the user's password is updated.
621
+ *
622
+ * Throws AuthError on invalid or expired token, weak password, etc.
623
+ * @throws AuthError
624
+ */
182
625
  resetPassword(body: {
183
626
  token: string;
184
627
  newPassword: string;
185
628
  }): Promise<void>;
629
+ /**
630
+ * Sends a magic link email to the specified address. A magic link allows
631
+ * passwordless authentication.
632
+ *
633
+ * Throws AuthError on invalid email format, etc.
634
+ * @throws AuthError
635
+ */
186
636
  static sendMagicLink(body: {
637
+ clientId: ClientId;
187
638
  email: string;
188
639
  csrfToken?: string;
189
640
  }, config?: Partial<Config>): Promise<void>;
641
+ /**
642
+ * Sends a magic link email to the specified address. A magic link allows
643
+ * passwordless authentication.
644
+ *
645
+ * Throws AuthError on invalid email format, etc.
646
+ * @throws AuthError
647
+ */
190
648
  sendMagicLink(body: {
649
+ clientId: ClientId;
191
650
  email: string;
192
651
  csrfToken?: string;
193
652
  }): Promise<void>;
653
+ /**
654
+ * Sends a password reset email to the specified address.
655
+ *
656
+ * Throws AuthError on invalid email format, etc.
657
+ * @throws AuthError
658
+ */
194
659
  static sendPasswordReset(body: {
660
+ clientId: ClientId;
195
661
  email: string;
196
662
  csrfToken?: string;
197
663
  }, config?: Partial<Config>): Promise<void>;
664
+ /**
665
+ * Sends a password reset email to the specified address.
666
+ *
667
+ * Throws AuthError on invalid email format, etc.
668
+ * @throws AuthError
669
+ */
198
670
  sendPasswordReset(body: {
671
+ clientId: ClientId;
199
672
  email: string;
200
673
  csrfToken?: string;
201
674
  }): Promise<void>;
202
675
  }
203
676
 
204
677
  export { Am, AuthError, AuthSession };
205
- export type { AuthenticationResult, ClientId, EmailCheckStatus, LoginMethod, ProblemDetails, SessionProfile, SessionTokens, UserId, UserResource };
678
+ export type { AccountId, AccountResource, AccountStatus, Authentication, ClientId, EmailCheckStatus, EmailCredential, LoginMethod, Membership, MembershipId, MembershipRole, ProblemDetails, SessionProfile, SessionTokens, StorageLike, UserId, UserIdentity, UserResource, UserStatus };