@molecule/app-angular 3.2.0 → 3.2.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 +58 -158
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-11-
|
|
6
|
+
Generated: 2026-11-04T14:09:03.868Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-angular
|
|
@@ -133,165 +133,65 @@ Provides login/logout/register flows, token management, profile
|
|
|
133
133
|
updates, and auth state subscription.
|
|
134
134
|
|
|
135
135
|
```typescript
|
|
136
|
-
interface AuthClient<
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
getAccessToken(): string | null;
|
|
192
|
-
/**
|
|
193
|
-
* Stores the access token in the configured token storage adapter (in a
|
|
194
|
-
* browser, Web Storage; `'memory'` where no browser store exists). Use this
|
|
195
|
-
* to seed the token after an out-of-band exchange (e.g. the OAuth
|
|
196
|
-
* code→token redirect) instead of writing to `localStorage` directly,
|
|
197
|
-
* which would violate the storage contract and make a stored bearer token
|
|
198
|
-
* JS-readable (XSS-exfiltratable). Pass `null` to clear it.
|
|
199
|
-
*
|
|
200
|
-
* This changes token storage only: passing `null` does not by itself sign a
|
|
201
|
-
* signed-in client out, and a non-null token does not sign an anonymous
|
|
202
|
-
* client in (`authenticated` and `status` are unchanged). Use {@link logout}
|
|
203
|
-
* to end a session, or {@link setUser} with `null` for local-only sign-out.
|
|
204
|
-
* Use {@link login} / {@link register} for a credential exchange, or call
|
|
205
|
-
* {@link setSession} with the token and user to establish an already-issued
|
|
206
|
-
* session.
|
|
207
|
-
*/
|
|
208
|
-
setAccessToken(token: string | null): void;
|
|
209
|
-
/**
|
|
210
|
-
* Adopts a session an out-of-band exchange already established: stores the
|
|
211
|
-
* access token (and the refresh token when given), caches the user, and
|
|
212
|
-
* sets the COMPLETE state — `initialized`, `authenticated`, `status:
|
|
213
|
-
* 'authenticated'`, no error — in one update, with one subscriber
|
|
214
|
-
* notification. Every hook reading the shared client sees the user as
|
|
215
|
-
* signed in immediately.
|
|
216
|
-
*
|
|
217
|
-
* This is the way to seed an OAuth/custom sign-in. Calling
|
|
218
|
-
* {@link setAccessToken} and {@link setUser} instead does NOT sign the
|
|
219
|
-
* client in.
|
|
220
|
-
*/
|
|
221
|
-
setSession(session: AuthSessionSeed<T>): void;
|
|
222
|
-
/**
|
|
223
|
-
* Gets the refresh token.
|
|
224
|
-
*/
|
|
225
|
-
getRefreshToken(): string | null;
|
|
226
|
-
/**
|
|
227
|
-
* Logs in with credentials.
|
|
228
|
-
*/
|
|
229
|
-
login(credentials: LoginCredentials): Promise<AuthResult<T>>;
|
|
230
|
-
/**
|
|
231
|
-
* Logs out the current user. The server request is best-effort: a missing
|
|
232
|
-
* logout route (404), any other HTTP failure, or a network error never makes
|
|
233
|
-
* this method reject. It always clears the access token, refresh token and
|
|
234
|
-
* cached user, stops automatic refresh, and publishes one settled
|
|
235
|
-
* `authenticated: false`, `status: 'unauthenticated'` transition. Every pending
|
|
236
|
-
* session operation loses ownership; a persistent marker prevents reload from
|
|
237
|
-
* restoring an older session, and late credentials are revoked best-effort.
|
|
238
|
-
*
|
|
239
|
-
* When the API has no logout route, set {@link AuthClientConfigOptions.logoutEndpoint}
|
|
240
|
-
* to `null` (or `''`) to skip the request. Local sign-out still happens.
|
|
241
|
-
*/
|
|
242
|
-
logout(): Promise<void>;
|
|
243
|
-
/**
|
|
244
|
-
* Registers a new user. Accepts the base fields plus the app's own fields
|
|
245
|
-
* (`TRegister`) at the top level — see {@link RegisterData}.
|
|
246
|
-
*/
|
|
247
|
-
register(data: RegisterData<TRegister>): Promise<AuthResult<T>>;
|
|
248
|
-
/**
|
|
249
|
-
* Refreshes the access token.
|
|
250
|
-
*/
|
|
251
|
-
refresh(): Promise<AuthResult<T>>;
|
|
252
|
-
/**
|
|
253
|
-
* Requests a password reset.
|
|
254
|
-
*/
|
|
255
|
-
requestPasswordReset(data: PasswordResetRequest): Promise<void>;
|
|
256
|
-
/**
|
|
257
|
-
* Confirms a password reset.
|
|
258
|
-
*/
|
|
259
|
-
confirmPasswordReset(data: PasswordResetConfirm): Promise<void>;
|
|
260
|
-
/**
|
|
261
|
-
* Updates the current user's profile.
|
|
262
|
-
* Returns the saved profile: the answer applied onto the signed-in user field
|
|
263
|
-
* by field, with or without an `id` — a field it carries replaces the value
|
|
264
|
-
* (`null` clears it), one it omits or leaves `undefined` is kept, so a field
|
|
265
|
-
* cleared by omission must arrive as `null`. A non-object answer is returned
|
|
266
|
-
* as it came. An answer for a replaced or ended session leaves the current one
|
|
267
|
-
* untouched.
|
|
268
|
-
*/
|
|
269
|
-
updateProfile(data: Partial<T>): Promise<T>;
|
|
270
|
-
/**
|
|
271
|
-
* Changes the current user's password.
|
|
272
|
-
*/
|
|
273
|
-
changePassword(oldPassword: string, newPassword: string): Promise<void>;
|
|
274
|
-
/**
|
|
275
|
-
* Initializes auth state (e.g., from stored tokens).
|
|
276
|
-
*
|
|
277
|
-
* LAZY and IDEMPOTENT: the first read of the state ({@link getState},
|
|
278
|
-
* {@link subscribe}, `useAuth()`) starts this same restore when nobody has called
|
|
279
|
-
* `initialize()`, and every later call shares the one promise instead of sending a
|
|
280
|
-
* second request. An app that keeps the template's explicit call behaves exactly as
|
|
281
|
-
* before; an app that loses that line still restores its session.
|
|
282
|
-
*
|
|
283
|
-
* With a stored token AND a stored user it marks the session `'authenticated'`
|
|
284
|
-
* SYNCHRONOUSLY — before its first `await` — so the first render is the
|
|
285
|
-
* signed-in UI and no page waits on a verification round trip. Any check
|
|
286
|
-
* (a refresh, the cookie-restore probe) settles behind that render, and only an
|
|
287
|
-
* explicit 401/403 ends the session; a network/5xx/404 failure keeps it and
|
|
288
|
-
* reports `'unavailable'`. With no stored user the client stays `'loading'`
|
|
289
|
-
* until the cookie restore decides.
|
|
290
|
-
*
|
|
291
|
-
* Do not put this call (or a `/me` request of your own) in front of the first
|
|
292
|
-
// … truncated — the full declaration is in node_modules/@molecule/app-angular/dist
|
|
136
|
+
interface AuthClient<
|
|
137
|
+
T = UserProfile,
|
|
138
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
139
|
+
> {
|
|
140
|
+
/** Returns the current authentication state snapshot. */
|
|
141
|
+
getState(): AuthState<T>
|
|
142
|
+
/** Returns whether the user is currently authenticated. */
|
|
143
|
+
isAuthenticated(): boolean
|
|
144
|
+
/** Gets the current user. */
|
|
145
|
+
getUser(): T | null
|
|
146
|
+
/** Optional ownership marker for the current session. */
|
|
147
|
+
getSessionRevision?(): number
|
|
148
|
+
/** Updates the cached user object (state + persistent storage) without hitting the network. */
|
|
149
|
+
setUser(user: T | null): void
|
|
150
|
+
/** Gets the current access token. */
|
|
151
|
+
getAccessToken(): string | null
|
|
152
|
+
/** Stores the access token in the configured token storage adapter (in a browser, Web Storage; `'memory'` where no browser store exists). */
|
|
153
|
+
setAccessToken(token: string | null): void
|
|
154
|
+
/** Adopts a session an out-of-band exchange already established: stores the access token (and the refresh token when given), caches the user, and sets the COMPLET… */
|
|
155
|
+
setSession(session: AuthSessionSeed<T>): void
|
|
156
|
+
/** Gets the refresh token. */
|
|
157
|
+
getRefreshToken(): string | null
|
|
158
|
+
/** Logs in with credentials. */
|
|
159
|
+
login(credentials: LoginCredentials): Promise<AuthResult<T>>
|
|
160
|
+
/** Logs out the current user. */
|
|
161
|
+
logout(): Promise<void>
|
|
162
|
+
/** Registers a new user. */
|
|
163
|
+
register(data: RegisterData<TRegister>): Promise<AuthResult<T>>
|
|
164
|
+
/** Refreshes the access token. */
|
|
165
|
+
refresh(): Promise<AuthResult<T>>
|
|
166
|
+
/** Requests a password reset. */
|
|
167
|
+
requestPasswordReset(data: PasswordResetRequest): Promise<void>
|
|
168
|
+
/** Confirms a password reset. */
|
|
169
|
+
confirmPasswordReset(data: PasswordResetConfirm): Promise<void>
|
|
170
|
+
/** Updates the current user's profile. */
|
|
171
|
+
updateProfile(data: Partial<T>): Promise<T>
|
|
172
|
+
/** Changes the current user's password. */
|
|
173
|
+
changePassword(oldPassword: string, newPassword: string): Promise<void>
|
|
174
|
+
/** Initializes auth state (e.g., from stored tokens). */
|
|
175
|
+
initialize(): Promise<void>
|
|
176
|
+
/** Re-checks a restored session against the server, in the background — the boot-time validation an app with a stored token needs when a revoked or expired token… */
|
|
177
|
+
validateSession?(): Promise<void>
|
|
178
|
+
/** Resolves when the session restore started by `initialize()` has settled — the point after which the client knows whether this visitor is signed in. */
|
|
179
|
+
whenRestored?(): Promise<void>
|
|
180
|
+
/** Subscribes to auth state changes. */
|
|
181
|
+
subscribe(callback: (state: AuthState<T>) => void): () => void
|
|
182
|
+
/** Subscribes to auth state changes (alias for subscribe). */
|
|
183
|
+
onAuthChange(callback: (state: AuthState<T>) => void): () => void
|
|
184
|
+
/** Gets the current access token (alias for getAccessToken). */
|
|
185
|
+
getToken?(): string | null
|
|
186
|
+
/** Adds an auth event listener. */
|
|
187
|
+
addEventListener(listener: AuthEventListener<T>): () => void
|
|
188
|
+
/** Destroys the auth client. */
|
|
189
|
+
destroy(): void
|
|
190
|
+
}
|
|
293
191
|
```
|
|
294
192
|
|
|
193
|
+
_(Member comments are shortened to their first sentence to fit; the full declaration is in `node_modules/@molecule/app-angular/dist`.)_
|
|
194
|
+
|
|
295
195
|
#### `FormController`
|
|
296
196
|
|
|
297
197
|
Form controller interface.
|