@molecule/app-svelte 3.7.1 → 3.8.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.
- package/README.md +363 -76
- package/dist/hooks/live-store.d.ts +18 -2
- package/dist/hooks/live-store.d.ts.map +1 -1
- package/dist/hooks/live-store.js +9 -5
- package/dist/hooks/useAIModels.d.ts +4 -1
- package/dist/hooks/useAIModels.d.ts.map +1 -1
- package/dist/hooks/useAIModels.js +8 -2
- package/dist/hooks/useForm.d.ts +6 -6
- package/dist/hooks/useForm.d.ts.map +1 -1
- package/dist/hooks/useForm.js +51 -23
- package/dist/hooks/useStore.d.ts +18 -1
- package/dist/hooks/useStore.d.ts.map +1 -1
- package/dist/hooks/useStore.js +5 -30
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/hooks/useTheme.js +42 -13
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +79 -0
- package/dist/link/Link.svelte +13 -3
- package/dist/link/Link.svelte.d.ts +1 -1
- package/dist/link/Link.svelte.d.ts.map +1 -1
- package/dist/link/types.d.ts +3 -1
- package/dist/link/types.d.ts.map +1 -1
- package/dist/stores/auth.d.ts +2 -2
- package/dist/stores/change-password.d.ts +1 -1
- package/dist/stores/change-password.d.ts.map +1 -1
- package/dist/stores/forms.d.ts.map +1 -1
- package/dist/stores/forms.js +4 -6
- package/dist/stores/login.d.ts +2 -2
- package/dist/stores/login.d.ts.map +1 -1
- package/dist/stores/promise.d.ts +6 -3
- package/dist/stores/promise.d.ts.map +1 -1
- package/dist/stores/promise.js +0 -1
- package/dist/stores/signup.d.ts +2 -2
- package/dist/stores/signup.d.ts.map +1 -1
- package/package.json +3 -3
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-20T06:32:18.746Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-svelte
|
|
@@ -55,6 +55,87 @@ then consume services anywhere below via store factories
|
|
|
55
55
|
{/if}
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
```svelte
|
|
59
|
+
<!-- Dashboard.svelte — the session, the theme and translations as stores -->
|
|
60
|
+
<script lang="ts">
|
|
61
|
+
import { useAuth, useTheme, useTranslation } from '@molecule/app-svelte'
|
|
62
|
+
|
|
63
|
+
const { user, status, logout } = useAuth<{ name?: string }>()
|
|
64
|
+
const { t } = useTranslation()
|
|
65
|
+
const { theme, toggleTheme } = useTheme()
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
{#if $status === 'loading'}
|
|
69
|
+
<p>{t('auth.restoring', undefined, { defaultValue: 'Restoring session...' })}</p>
|
|
70
|
+
{:else if $status === 'unauthenticated'}
|
|
71
|
+
<p>{t('auth.required', undefined, { defaultValue: 'Please log in.' })}</p>
|
|
72
|
+
{:else}
|
|
73
|
+
<div style:background={$theme.colors.background}>
|
|
74
|
+
<h1>
|
|
75
|
+
{t('greeting.welcome', { name: $user?.name ?? '' }, { defaultValue: 'Welcome, {{name}}!' })}
|
|
76
|
+
</h1>
|
|
77
|
+
<button onclick={toggleTheme}>
|
|
78
|
+
{t('theme.toggle', undefined, { defaultValue: 'Toggle theme' })}
|
|
79
|
+
</button>
|
|
80
|
+
<button onclick={() => logout()}>
|
|
81
|
+
{t('auth.logout', undefined, { defaultValue: 'Log out' })}
|
|
82
|
+
</button>
|
|
83
|
+
</div>
|
|
84
|
+
{/if}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```svelte
|
|
88
|
+
<!-- FavoriteButton.svelte — a server-backed favorite that changes at once -->
|
|
89
|
+
<script lang="ts">
|
|
90
|
+
import { useHttpClient, useOptimisticValue, useTranslation } from '@molecule/app-svelte'
|
|
91
|
+
|
|
92
|
+
interface FavoriteRecord {
|
|
93
|
+
slug: string
|
|
94
|
+
favorited: boolean
|
|
95
|
+
favoritesCount: number
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let {
|
|
99
|
+
article,
|
|
100
|
+
onChanged,
|
|
101
|
+
}: {
|
|
102
|
+
article: FavoriteRecord
|
|
103
|
+
onChanged?: (saved: FavoriteRecord) => void
|
|
104
|
+
} = $props()
|
|
105
|
+
|
|
106
|
+
const http = useHttpClient()
|
|
107
|
+
const { t } = useTranslation()
|
|
108
|
+
const { value: favorite, update } = useOptimisticValue({
|
|
109
|
+
value: { favorited: article.favorited, count: article.favoritesCount },
|
|
110
|
+
commit: async (next) => {
|
|
111
|
+
const path = `/articles/${article.slug}/favorite`
|
|
112
|
+
const response = next.favorited
|
|
113
|
+
? await http.post<{ article: FavoriteRecord }>(path)
|
|
114
|
+
: await http.delete<{ article: FavoriteRecord }>(path)
|
|
115
|
+
const saved = response.data.article
|
|
116
|
+
onChanged?.(saved)
|
|
117
|
+
return { favorited: saved.favorited, count: saved.favoritesCount }
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<button
|
|
123
|
+
aria-pressed={$favorite.favorited}
|
|
124
|
+
aria-label={t('article.favorite', undefined, { defaultValue: 'Favorite article' })}
|
|
125
|
+
onclick={() =>
|
|
126
|
+
update((current) => ({
|
|
127
|
+
favorited: !current.favorited,
|
|
128
|
+
count: current.count + (current.favorited ? -1 : 1),
|
|
129
|
+
}))}>{$favorite.count}</button
|
|
130
|
+
>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Session state is a three-way decision, not a boolean: `status === 'loading'`
|
|
134
|
+
is undecided, so wait for it and redirect only on
|
|
135
|
+
`status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
|
|
136
|
+
for retry, so a restore that failed with anything other than a 401/403 never
|
|
137
|
+
signs the user out.
|
|
138
|
+
|
|
58
139
|
## Type
|
|
59
140
|
|
|
60
141
|
`framework`
|
|
@@ -160,55 +241,143 @@ interface AuthClient<
|
|
|
160
241
|
T = UserProfile,
|
|
161
242
|
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
162
243
|
> {
|
|
163
|
-
/**
|
|
244
|
+
/**
|
|
245
|
+
* Returns the current authentication state snapshot.
|
|
246
|
+
*
|
|
247
|
+
* READING the state starts the client's one session restore when nobody has called
|
|
248
|
+
* {@link initialize} yet — lazily and exactly once, sharing the promise an explicit
|
|
249
|
+
* `initialize()` returns. A hook (`useAuth()`), a subscriber, `isAuthenticated()` and
|
|
250
|
+
* `getUser()` are reads too, so a client whose entry file dropped the template's
|
|
251
|
+
* `authClient.initialize()` line still restores instead of reporting `'loading'`
|
|
252
|
+
* forever.
|
|
253
|
+
*/
|
|
164
254
|
getState(): AuthState<T>
|
|
165
255
|
|
|
166
|
-
/**
|
|
256
|
+
/**
|
|
257
|
+
* Returns whether the user is currently authenticated.
|
|
258
|
+
*/
|
|
167
259
|
isAuthenticated(): boolean
|
|
168
260
|
|
|
169
|
-
/**
|
|
261
|
+
/**
|
|
262
|
+
* Gets the current user.
|
|
263
|
+
*/
|
|
170
264
|
getUser(): T | null
|
|
171
265
|
|
|
172
|
-
/**
|
|
266
|
+
/**
|
|
267
|
+
* Optional ownership marker for the current session. Compare values only within
|
|
268
|
+
* this client: replacing or ending a session changes it, including re-adopting
|
|
269
|
+
* the same token and user. Profile updates and same-session refreshes keep it.
|
|
270
|
+
* Consumers can use it to discard stale async work without treating editable
|
|
271
|
+
* user fields as an immutable account identifier. Providers without this
|
|
272
|
+
* capability require the consumer's own stable identity check.
|
|
273
|
+
*/
|
|
173
274
|
getSessionRevision?(): number
|
|
174
275
|
|
|
175
276
|
/** Updates the cached user object (state + persistent storage) without hitting the network. */
|
|
176
277
|
setUser(user: T | null): void
|
|
177
278
|
|
|
178
|
-
/**
|
|
279
|
+
/**
|
|
280
|
+
* Gets the current access token.
|
|
281
|
+
*/
|
|
179
282
|
getAccessToken(): string | null
|
|
180
283
|
|
|
181
|
-
/**
|
|
284
|
+
/**
|
|
285
|
+
* Stores the access token in the configured token storage adapter (in a
|
|
286
|
+
* browser, Web Storage; `'memory'` where no browser store exists). Use this
|
|
287
|
+
* to seed the token after an out-of-band exchange (e.g. the OAuth
|
|
288
|
+
* code→token redirect) instead of writing to `localStorage` directly,
|
|
289
|
+
* which would violate the storage contract and make a stored bearer token
|
|
290
|
+
* JS-readable (XSS-exfiltratable). Pass `null` to clear it.
|
|
291
|
+
*
|
|
292
|
+
* Passing `null` does not by itself sign a signed-in client out: use
|
|
293
|
+
* {@link logout} to end a session, or {@link setUser} with `null` for
|
|
294
|
+
* local-only sign-out. A non-null token on a client that is not signed in is
|
|
295
|
+
* the first or second half of the app's own sign-in pair: together with
|
|
296
|
+
* {@link setUser} it adopts the session (see there). Prefer {@link setSession}
|
|
297
|
+
* with the token and user, or {@link login} / {@link register} for a
|
|
298
|
+
* credential exchange.
|
|
299
|
+
*/
|
|
182
300
|
setAccessToken(token: string | null): void
|
|
183
301
|
|
|
184
|
-
/**
|
|
302
|
+
/**
|
|
303
|
+
* Adopts a session an out-of-band exchange already established: stores the
|
|
304
|
+
* access token (and the refresh token when given), caches the user, and
|
|
305
|
+
* sets the COMPLETE state — `initialized`, `authenticated`, `status:
|
|
306
|
+
* 'authenticated'`, no error — in one update, with one subscriber
|
|
307
|
+
* notification. Every hook reading the shared client sees the user as
|
|
308
|
+
* signed in immediately.
|
|
309
|
+
*
|
|
310
|
+
* This is the way to seed an OAuth/custom sign-in. The field-setter pair
|
|
311
|
+
* ({@link setAccessToken} then {@link setUser}, or the reverse) on a client
|
|
312
|
+
* that is not signed in adopts the session the same way.
|
|
313
|
+
*/
|
|
185
314
|
setSession(session: AuthSessionSeed<T>): void
|
|
186
315
|
|
|
187
|
-
/**
|
|
316
|
+
/**
|
|
317
|
+
* Gets the refresh token.
|
|
318
|
+
*/
|
|
188
319
|
getRefreshToken(): string | null
|
|
189
320
|
|
|
190
|
-
/**
|
|
321
|
+
/**
|
|
322
|
+
* Logs in with credentials.
|
|
323
|
+
*/
|
|
191
324
|
login(credentials: LoginCredentials): Promise<AuthResult<T>>
|
|
192
325
|
|
|
193
|
-
/**
|
|
326
|
+
/**
|
|
327
|
+
* Logs out the current user. The server request is best-effort: a missing
|
|
328
|
+
* logout route (404), any other HTTP failure, or a network error never makes
|
|
329
|
+
* this method reject. It always clears the access token, refresh token and
|
|
330
|
+
* cached user, stops automatic refresh, and publishes one settled
|
|
331
|
+
* `authenticated: false`, `status: 'unauthenticated'` transition. Every pending
|
|
332
|
+
* session operation loses ownership; a persistent marker prevents reload from
|
|
333
|
+
* restoring an older session, and late credentials are revoked best-effort.
|
|
334
|
+
*
|
|
335
|
+
* When the API has no logout route, set {@link AuthClientConfigOptions.logoutEndpoint}
|
|
336
|
+
* to `null` (or `''`) to skip the request. Local sign-out still happens.
|
|
337
|
+
*/
|
|
194
338
|
logout(): Promise<void>
|
|
195
339
|
|
|
196
|
-
/**
|
|
340
|
+
/**
|
|
341
|
+
* Registers a new user. Accepts the base fields plus the app's own fields
|
|
342
|
+
* (`TRegister`) at the top level — see {@link RegisterData}.
|
|
343
|
+
*/
|
|
197
344
|
register(data: RegisterData<TRegister>): Promise<AuthResult<T>>
|
|
198
345
|
|
|
199
|
-
/**
|
|
346
|
+
/**
|
|
347
|
+
* Exchanges a stored refresh token, or re-reads `currentUserEndpoint` with the
|
|
348
|
+
* existing access token/session cookie when the API has no refresh credential.
|
|
349
|
+
* That fallback maps, stores and publishes the server user without renewing
|
|
350
|
+
* the access token. Failures reject. A 401/403 ends the session, as does an
|
|
351
|
+
* additional {@link AuthClientConfigOptions.currentUserRejectionStatuses}
|
|
352
|
+
* code from the fallback. Transient failures retain it as unavailable. Use {@link updateProfile} for a profile
|
|
353
|
+
* save, or {@link setUser} with the canonical row from an app-owned mutation.
|
|
354
|
+
*/
|
|
200
355
|
refresh(): Promise<AuthResult<T>>
|
|
201
356
|
|
|
202
|
-
/**
|
|
357
|
+
/**
|
|
358
|
+
* Requests a password reset.
|
|
359
|
+
*/
|
|
203
360
|
requestPasswordReset(data: PasswordResetRequest): Promise<void>
|
|
204
361
|
|
|
205
|
-
/**
|
|
362
|
+
/**
|
|
363
|
+
* Confirms a password reset.
|
|
364
|
+
*/
|
|
206
365
|
confirmPasswordReset(data: PasswordResetConfirm): Promise<void>
|
|
207
366
|
|
|
208
|
-
/**
|
|
367
|
+
/**
|
|
368
|
+
* Updates the current user's profile.
|
|
369
|
+
* Returns the saved profile: the answer applied onto the signed-in user field
|
|
370
|
+
* by field, with or without an `id` — a field it carries replaces the value
|
|
371
|
+
* (`null` clears it), one it omits or leaves `undefined` is kept, so a field
|
|
372
|
+
* cleared by omission must arrive as `null`. A non-object answer is returned
|
|
373
|
+
* as it came. An answer for a replaced or ended session leaves the current one
|
|
374
|
+
* untouched.
|
|
375
|
+
*/
|
|
209
376
|
updateProfile(data: Partial<T>): Promise<T>
|
|
210
377
|
|
|
211
|
-
/**
|
|
378
|
+
/**
|
|
379
|
+
* Changes the current user's password.
|
|
380
|
+
*/
|
|
212
381
|
changePassword(oldPassword: string, newPassword: string): Promise<void>
|
|
213
382
|
|
|
214
383
|
/** Initializes auth state (e.g., from stored tokens). */
|
|
@@ -220,24 +389,48 @@ interface AuthClient<
|
|
|
220
389
|
/** Resolves when the session restore started by `initialize()` has settled — the point after which the client knows whether this visitor is signed in. */
|
|
221
390
|
whenRestored?(): Promise<void>
|
|
222
391
|
|
|
223
|
-
/**
|
|
392
|
+
/**
|
|
393
|
+
* Subscribes to auth state changes.
|
|
394
|
+
*/
|
|
224
395
|
subscribe(callback: (state: AuthState<T>) => void): () => void
|
|
225
396
|
|
|
226
|
-
/**
|
|
397
|
+
/**
|
|
398
|
+
* Subscribes to auth state changes (alias for subscribe).
|
|
399
|
+
*/
|
|
227
400
|
onAuthChange(callback: (state: AuthState<T>) => void): () => void
|
|
228
401
|
|
|
229
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* Gets the current access token (alias for getAccessToken).
|
|
404
|
+
*/
|
|
230
405
|
getToken?(): string | null
|
|
231
406
|
|
|
232
|
-
/**
|
|
407
|
+
/**
|
|
408
|
+
* Adds an auth event listener.
|
|
409
|
+
*
|
|
410
|
+
* The listener is typed by this client's profile: one signature,
|
|
411
|
+
* `AuthEventListener<T>`, so an inline arrow is contextually typed and `event`
|
|
412
|
+
* is never implicitly `any`. A client whose profile extends
|
|
413
|
+
* {@link UserProfile} also accepts a default {@link AuthEventListener}: when
|
|
414
|
+
* `T` extends `UserProfile`, `AuthEvent<T>` is assignable to
|
|
415
|
+
* `AuthEvent<UserProfile>`, so a listener that takes the wider default event
|
|
416
|
+
* accepts every event this client emits and keeps compiling. (`UserProfile`
|
|
417
|
+
* is the wider type here — it has fewer required fields — and the assignable
|
|
418
|
+
* direction runs from the client's `AuthEvent<T>` to the listener's
|
|
419
|
+
* `AuthEvent<UserProfile>`.) A profile that does not extend `UserProfile`
|
|
420
|
+
* (no `id`) rejects the default listener: an `AuthEvent<UserProfile>` would
|
|
421
|
+
* promise an `id` the runtime user does not have, and the narrower-typed
|
|
422
|
+
* event is not assignable to it.
|
|
423
|
+
*/
|
|
233
424
|
addEventListener(listener: AuthEventListener<T>): () => void
|
|
234
425
|
|
|
235
|
-
/**
|
|
426
|
+
/**
|
|
427
|
+
* Destroys the auth client.
|
|
428
|
+
*/
|
|
236
429
|
destroy(): void
|
|
237
430
|
}
|
|
238
431
|
```
|
|
239
432
|
|
|
240
|
-
_(
|
|
433
|
+
_(The 4 longest member comments are shortened to their first sentence to fit; the full declaration is in `node_modules/@molecule/app-auth/dist/types.d.ts`.)_
|
|
241
434
|
|
|
242
435
|
#### `FormController`
|
|
243
436
|
|
|
@@ -424,6 +617,15 @@ interface FormOptions<T extends FormValuesConstraint<T>> {
|
|
|
424
617
|
HTTP client interface.
|
|
425
618
|
|
|
426
619
|
All HTTP providers must implement this interface.
|
|
620
|
+
An explicit text, blob or arraybuffer parser determines the data type even when
|
|
621
|
+
a JSON generic is supplied. Keep JSON as the default for mutations returning a
|
|
622
|
+
record. A successful DELETE with no body already resolves with null data.
|
|
623
|
+
|
|
624
|
+
Every verb also takes a URL alone, through a signature with the same three parameters on every
|
|
625
|
+
verb, so a verb chosen at runtime (`client[verb](url)`) type-checks and a wrapper can implement
|
|
626
|
+
a verb with an arrow (`get: (url, config) => inner.get(url, config)`). With a body or a config,
|
|
627
|
+
choose the verb through `request({ method, url, data })` instead: the second argument is the
|
|
628
|
+
body for post/put/patch but the config for get/delete, so one call cannot serve both.
|
|
427
629
|
|
|
428
630
|
```typescript
|
|
429
631
|
interface HttpClient {
|
|
@@ -441,11 +643,33 @@ interface HttpClient {
|
|
|
441
643
|
* Makes a generic HTTP request. `data` is a field of THIS config object — the same body
|
|
442
644
|
* `post(url, data, config)` takes as its second argument.
|
|
443
645
|
*/
|
|
646
|
+
request<T = unknown>(
|
|
647
|
+
config: FullRequestConfig & { responseType: 'text' },
|
|
648
|
+
): Promise<HttpResponse<string>>
|
|
649
|
+
request<T = unknown>(
|
|
650
|
+
config: FullRequestConfig & { responseType: 'blob' },
|
|
651
|
+
): Promise<HttpResponse<Blob>>
|
|
652
|
+
request<T = unknown>(
|
|
653
|
+
config: FullRequestConfig & { responseType: 'arraybuffer' },
|
|
654
|
+
): Promise<HttpResponse<ArrayBuffer>>
|
|
444
655
|
request<T = unknown>(config: FullRequestConfig): Promise<HttpResponse<T>>
|
|
445
656
|
|
|
446
657
|
/**
|
|
447
658
|
* Makes a GET request.
|
|
448
659
|
*/
|
|
660
|
+
get<T = unknown>(
|
|
661
|
+
url: string,
|
|
662
|
+
config: RequestConfig & { responseType: 'text' },
|
|
663
|
+
): Promise<HttpResponse<string>>
|
|
664
|
+
get<T = unknown>(
|
|
665
|
+
url: string,
|
|
666
|
+
config: RequestConfig & { responseType: 'blob' },
|
|
667
|
+
): Promise<HttpResponse<Blob>>
|
|
668
|
+
get<T = unknown>(
|
|
669
|
+
url: string,
|
|
670
|
+
config: RequestConfig & { responseType: 'arraybuffer' },
|
|
671
|
+
): Promise<HttpResponse<ArrayBuffer>>
|
|
672
|
+
get<T = unknown>(url: string, config?: undefined, unused?: undefined): Promise<HttpResponse<T>>
|
|
449
673
|
get<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
450
674
|
|
|
451
675
|
/**
|
|
@@ -453,23 +677,84 @@ interface HttpClient {
|
|
|
453
677
|
* `data` itself, so `post(url, { data: body })` sends `{"data":body}` — pass `body` directly.
|
|
454
678
|
* A config (headers, params) is the THIRD argument.
|
|
455
679
|
*/
|
|
680
|
+
post<T = unknown>(
|
|
681
|
+
url: string,
|
|
682
|
+
data: unknown,
|
|
683
|
+
config: RequestConfig & { responseType: 'text' },
|
|
684
|
+
): Promise<HttpResponse<string>>
|
|
685
|
+
post<T = unknown>(
|
|
686
|
+
url: string,
|
|
687
|
+
data: unknown,
|
|
688
|
+
config: RequestConfig & { responseType: 'blob' },
|
|
689
|
+
): Promise<HttpResponse<Blob>>
|
|
690
|
+
post<T = unknown>(
|
|
691
|
+
url: string,
|
|
692
|
+
data: unknown,
|
|
693
|
+
config: RequestConfig & { responseType: 'arraybuffer' },
|
|
694
|
+
): Promise<HttpResponse<ArrayBuffer>>
|
|
695
|
+
post<T = unknown>(url: string, data?: undefined, config?: undefined): Promise<HttpResponse<T>>
|
|
456
696
|
post<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
457
697
|
|
|
458
698
|
/**
|
|
459
699
|
* Makes a PUT request. `data` is the request BODY (second argument) — never `{ data: body }`,
|
|
460
700
|
* which sends `{"data":body}`; a config is the THIRD argument.
|
|
461
701
|
*/
|
|
702
|
+
put<T = unknown>(
|
|
703
|
+
url: string,
|
|
704
|
+
data: unknown,
|
|
705
|
+
config: RequestConfig & { responseType: 'text' },
|
|
706
|
+
): Promise<HttpResponse<string>>
|
|
707
|
+
put<T = unknown>(
|
|
708
|
+
url: string,
|
|
709
|
+
data: unknown,
|
|
710
|
+
config: RequestConfig & { responseType: 'blob' },
|
|
711
|
+
): Promise<HttpResponse<Blob>>
|
|
712
|
+
put<T = unknown>(
|
|
713
|
+
url: string,
|
|
714
|
+
data: unknown,
|
|
715
|
+
config: RequestConfig & { responseType: 'arraybuffer' },
|
|
716
|
+
): Promise<HttpResponse<ArrayBuffer>>
|
|
717
|
+
put<T = unknown>(url: string, data?: undefined, config?: undefined): Promise<HttpResponse<T>>
|
|
462
718
|
put<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
463
719
|
|
|
464
720
|
/**
|
|
465
721
|
* Makes a PATCH request. `data` is the request BODY (second argument) — never `{ data: body }`,
|
|
466
722
|
* which sends `{"data":body}`; a config is the THIRD argument.
|
|
467
723
|
*/
|
|
724
|
+
patch<T = unknown>(
|
|
725
|
+
url: string,
|
|
726
|
+
data: unknown,
|
|
727
|
+
config: RequestConfig & { responseType: 'text' },
|
|
728
|
+
): Promise<HttpResponse<string>>
|
|
729
|
+
patch<T = unknown>(
|
|
730
|
+
url: string,
|
|
731
|
+
data: unknown,
|
|
732
|
+
config: RequestConfig & { responseType: 'blob' },
|
|
733
|
+
): Promise<HttpResponse<Blob>>
|
|
734
|
+
patch<T = unknown>(
|
|
735
|
+
url: string,
|
|
736
|
+
data: unknown,
|
|
737
|
+
config: RequestConfig & { responseType: 'arraybuffer' },
|
|
738
|
+
): Promise<HttpResponse<ArrayBuffer>>
|
|
739
|
+
patch<T = unknown>(url: string, data?: undefined, config?: undefined): Promise<HttpResponse<T>>
|
|
468
740
|
patch<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
469
741
|
|
|
470
742
|
/**
|
|
471
743
|
* Makes a DELETE request.
|
|
472
744
|
*/
|
|
745
|
+
delete<T = unknown>(
|
|
746
|
+
url: string,
|
|
747
|
+
config: RequestConfig & { responseType: 'text' },
|
|
748
|
+
): Promise<HttpResponse<string>>
|
|
749
|
+
delete<T = unknown>(
|
|
750
|
+
url: string,
|
|
751
|
+
config: RequestConfig & { responseType: 'blob' },
|
|
752
|
+
): Promise<HttpResponse<Blob>>
|
|
753
|
+
delete<T = unknown>(
|
|
754
|
+
url: string,
|
|
755
|
+
config: RequestConfig & { responseType: 'arraybuffer' },
|
|
756
|
+
): Promise<HttpResponse<ArrayBuffer>>
|
|
757
|
+
delete<T = unknown>(url: string, config?: undefined, unused?: undefined): Promise<HttpResponse<T>>
|
|
473
758
|
delete<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
|
|
474
759
|
|
|
475
760
|
/**
|
|
@@ -508,46 +793,21 @@ interface HttpClient {
|
|
|
508
793
|
*/
|
|
509
794
|
getAuthToken(): string | null
|
|
510
795
|
|
|
511
|
-
/**
|
|
512
|
-
* Registers the LIVE token resolver every request of this client reads, or clears it with
|
|
513
|
-
* `null`.
|
|
514
|
-
*
|
|
515
|
-
* `@molecule/app-http`'s `setAuthTokenSource()` calls this on every client it bonds, and the
|
|
516
|
-
* client MUST consult the resolver again each time it assembles a request (and report it from
|
|
517
|
-
* `getAuthToken()`). A session can change with no auth event and no observable state change —
|
|
518
|
-
* `authClient.setSession()` with the same profile data, or the OAuth callback's
|
|
519
|
-
* `setAccessToken()` — so a token pushed only at bond time or on `login`/`logout` events
|
|
520
|
-
* leaves every later request carrying the PREVIOUS session's bearer while the UI shows the
|
|
521
|
-
* new one.
|
|
522
|
-
*
|
|
523
|
-
* The resolved token takes the static token's place, with the same precedence: an
|
|
524
|
-
* `Authorization` header passed per request or in the client's default headers wins over it
|
|
525
|
-
* exactly where it won over a static token in this transport.
|
|
526
|
-
*
|
|
527
|
-
* A resolver that returns `null` (or `undefined`) means "this session has no body token": the
|
|
528
|
-
* request carries no `Authorization` header of the client's own. A cookie-session API issues
|
|
529
|
-
* no bearer, and the server prefers the header over the fresh cookie, so a kept bearer
|
|
530
|
-
* authenticates as the prior — possibly deleted — session.
|
|
531
|
-
*
|
|
532
|
-
* Optional, so an implementation written against the previous interface still conforms.
|
|
533
|
-
* `setAuthTokenSource()` follows such a client through a request interceptor instead, pushing
|
|
534
|
-
* the source with `setAuthToken` before each request: that request carries the change only
|
|
535
|
-
* when the transport applies its token after running its interceptors, so a transport that
|
|
536
|
-
* applies it earlier sends a session adopted mid-page from the following request on.
|
|
537
|
-
*
|
|
538
|
-
* @param resolver - Returns the current access token (or null/undefined), or `null` to clear.
|
|
539
|
-
*/
|
|
796
|
+
/** Registers the LIVE token resolver every request of this client reads, or clears it with `null`. */
|
|
540
797
|
setAuthTokenResolver?(resolver: AuthTokenResolver | null): void
|
|
541
798
|
|
|
542
799
|
/**
|
|
543
|
-
* Registers a handler for authentication errors (401).
|
|
800
|
+
* Registers a handler for authentication errors (401), with the rejected request's metadata.
|
|
544
801
|
*
|
|
802
|
+
* @param handler - Receives the method, URL and credential state of the rejected request.
|
|
545
803
|
* @returns An unsubscribe function.
|
|
546
804
|
*/
|
|
547
|
-
onAuthError(handler: () => void): () => void
|
|
805
|
+
onAuthError(handler: (event: HttpAuthErrorEvent) => void): () => void
|
|
548
806
|
}
|
|
549
807
|
```
|
|
550
808
|
|
|
809
|
+
_(The longest member comment is shortened to its first sentence to fit; the full declaration is in `node_modules/@molecule/app-http/dist/client.d.ts`.)_
|
|
810
|
+
|
|
551
811
|
#### `I18nProvider`
|
|
552
812
|
|
|
553
813
|
i18n provider interface.
|
|
@@ -976,6 +1236,16 @@ interface Router {
|
|
|
976
1236
|
*/
|
|
977
1237
|
generatePath(name: string, params?: RouteParams, query?: QueryParams): string
|
|
978
1238
|
|
|
1239
|
+
/**
|
|
1240
|
+
* The `href` an anchor to the in-app `path` carries, as the native router's own link
|
|
1241
|
+
* writes it (its base path prefixed, or `#/…` under a hash history), so a middle-click,
|
|
1242
|
+
* a new tab or a copied link opens the same page a click does.
|
|
1243
|
+
*
|
|
1244
|
+
* @param path - Pathname with optional query string and hash, as passed to `navigate`.
|
|
1245
|
+
* @returns The `href`.
|
|
1246
|
+
*/
|
|
1247
|
+
createHref(path: string): string
|
|
1248
|
+
|
|
979
1249
|
/**
|
|
980
1250
|
* Subscribes to route changes.
|
|
981
1251
|
*/
|
|
@@ -1224,7 +1494,10 @@ Result returned by `useAIModels`.
|
|
|
1224
1494
|
|
|
1225
1495
|
```typescript
|
|
1226
1496
|
interface UseAIModelsResult {
|
|
1227
|
-
/**
|
|
1497
|
+
/**
|
|
1498
|
+
* Available models, or an empty array while loading or after a failed fetch, as a readable store. The list
|
|
1499
|
+
* keeps its identity until the catalog changes, the empty one included.
|
|
1500
|
+
*/
|
|
1228
1501
|
models: Readable<AppModelDefinition[]>
|
|
1229
1502
|
/**
|
|
1230
1503
|
* Per-mode server default model ids for the requester's tier, or `undefined`
|
|
@@ -2036,6 +2309,18 @@ interface UseStoreOptions<T, S> {
|
|
|
2036
2309
|
}
|
|
2037
2310
|
```
|
|
2038
2311
|
|
|
2312
|
+
#### `SelectingStoreOptions`
|
|
2313
|
+
|
|
2314
|
+
Options for {@link useStore} that pick part of the store: a selector is
|
|
2315
|
+
required, so the selected type `S` always comes from it.
|
|
2316
|
+
|
|
2317
|
+
```typescript
|
|
2318
|
+
interface SelectingStoreOptions<T, S> extends UseStoreOptions<T, S> {
|
|
2319
|
+
/** Picks the value the hook returns from the store's state. */
|
|
2320
|
+
selector: (state: T) => S
|
|
2321
|
+
}
|
|
2322
|
+
```
|
|
2323
|
+
|
|
2039
2324
|
#### `UseThemeResult`
|
|
2040
2325
|
|
|
2041
2326
|
What {@link useTheme} returns.
|
|
@@ -2204,7 +2489,7 @@ Props for `Link`. Every other anchor attribute (`class`, `target`, `rel`,
|
|
|
2204
2489
|
|
|
2205
2490
|
```typescript
|
|
2206
2491
|
interface LinkProps extends Omit<HTMLAnchorAttributes, 'href' | 'children'> {
|
|
2207
|
-
/** Destination: an app path (`/settings?tab=billing#plan`) or a URL.
|
|
2492
|
+
/** Destination: an app path (`/settings?tab=billing#plan`) or a URL. An app path's `href` is the one the router writes for it (`routerLinkHref`), base path included. */
|
|
2208
2493
|
to: string
|
|
2209
2494
|
/**
|
|
2210
2495
|
* Replace the current history entry instead of pushing one. When omitted, a
|
|
@@ -2216,6 +2501,8 @@ interface LinkProps extends Omit<HTMLAnchorAttributes, 'href' | 'children'> {
|
|
|
2216
2501
|
state?: unknown
|
|
2217
2502
|
/** The link's content. */
|
|
2218
2503
|
children?: Snippet
|
|
2504
|
+
/** The rendered anchor (`bind:ref`), as React's `ref` receives it. */
|
|
2505
|
+
ref?: HTMLAnchorElement | null
|
|
2219
2506
|
}
|
|
2220
2507
|
```
|
|
2221
2508
|
|
|
@@ -2309,8 +2596,8 @@ interface PasswordResetStores {
|
|
|
2309
2596
|
Promise store with action methods.
|
|
2310
2597
|
|
|
2311
2598
|
```typescript
|
|
2312
|
-
interface PromiseStore<T> extends Readable<PromiseState<T>> {
|
|
2313
|
-
call: (...args:
|
|
2599
|
+
interface PromiseStore<T, A extends unknown[] = unknown[]> extends Readable<PromiseState<T>> {
|
|
2600
|
+
call: (...args: A) => Promise<T>
|
|
2314
2601
|
cancel: (message?: string) => void
|
|
2315
2602
|
reset: () => void
|
|
2316
2603
|
}
|
|
@@ -2537,7 +2824,7 @@ type CapacitorAppStore = Readable<CapacitorAppState> & {
|
|
|
2537
2824
|
Change password store type.
|
|
2538
2825
|
|
|
2539
2826
|
```typescript
|
|
2540
|
-
type ChangePasswordStore = PromiseStore<void>
|
|
2827
|
+
type ChangePasswordStore = PromiseStore<void, [string, string]>
|
|
2541
2828
|
```
|
|
2542
2829
|
|
|
2543
2830
|
#### `UseChatOptions`
|
|
@@ -2572,7 +2859,7 @@ type UseChatResult = {
|
|
|
2572
2859
|
Login store type.
|
|
2573
2860
|
|
|
2574
2861
|
```typescript
|
|
2575
|
-
type LoginStore<T = unknown> = PromiseStore<AuthResult<T
|
|
2862
|
+
type LoginStore<T = unknown> = PromiseStore<AuthResult<T>, [LoginCredentials]>
|
|
2576
2863
|
```
|
|
2577
2864
|
|
|
2578
2865
|
#### `SignupStore`
|
|
@@ -2580,7 +2867,7 @@ type LoginStore<T = unknown> = PromiseStore<AuthResult<T>>
|
|
|
2580
2867
|
Signup store type.
|
|
2581
2868
|
|
|
2582
2869
|
```typescript
|
|
2583
|
-
type SignupStore<T = unknown> = PromiseStore<AuthResult<T
|
|
2870
|
+
type SignupStore<T = unknown> = PromiseStore<AuthResult<T>, [RegisterData]>
|
|
2584
2871
|
```
|
|
2585
2872
|
|
|
2586
2873
|
### Functions
|
|
@@ -3165,13 +3452,13 @@ a readable store of the field's current value.
|
|
|
3165
3452
|
|
|
3166
3453
|
```typescript
|
|
3167
3454
|
function useWatch<T extends FormValuesConstraint<T>, K extends keyof T>(
|
|
3168
|
-
form: FormController<T
|
|
3169
|
-
name: K
|
|
3455
|
+
form: MaybeReadable<FormController<T>>,
|
|
3456
|
+
name: MaybeReadable<K>,
|
|
3170
3457
|
): Readable<T[K]>
|
|
3171
3458
|
```
|
|
3172
3459
|
|
|
3173
|
-
- `form` — Form controller
|
|
3174
|
-
- `name` — Field name to watch
|
|
3460
|
+
- `form` — Form controller, or a readable store of one
|
|
3461
|
+
- `name` — Field name to watch, or a readable store of one
|
|
3175
3462
|
|
|
3176
3463
|
**Returns:** A readable store of the current field value
|
|
3177
3464
|
|
|
@@ -3182,13 +3469,13 @@ readable store of the field's state.
|
|
|
3182
3469
|
|
|
3183
3470
|
```typescript
|
|
3184
3471
|
function useFieldState<T extends FormValuesConstraint<T>>(
|
|
3185
|
-
form: FormController<T
|
|
3186
|
-
name: keyof T
|
|
3472
|
+
form: MaybeReadable<FormController<T>>,
|
|
3473
|
+
name: MaybeReadable<keyof T>,
|
|
3187
3474
|
): Readable<FieldState<T[keyof T]>>
|
|
3188
3475
|
```
|
|
3189
3476
|
|
|
3190
|
-
- `form` — Form controller
|
|
3191
|
-
- `name` — Field name
|
|
3477
|
+
- `form` — Form controller, or a readable store of one
|
|
3478
|
+
- `name` — Field name, or a readable store of one
|
|
3192
3479
|
|
|
3193
3480
|
**Returns:** A readable store of the field state (value, error, touched, dirty, valid, validating)
|
|
3194
3481
|
|
|
@@ -3798,10 +4085,10 @@ The selector and equality function run with the same cadence as React's
|
|
|
3798
4085
|
every render; {@link useSyncExternalStore} documents the cadence.
|
|
3799
4086
|
|
|
3800
4087
|
```typescript
|
|
3801
|
-
function useStore<T
|
|
4088
|
+
function useStore<T>(
|
|
3802
4089
|
store: MaybeReadable<Store<T>>,
|
|
3803
|
-
options?: MaybeReadable<UseStoreOptions<T,
|
|
3804
|
-
): Readable<
|
|
4090
|
+
options?: MaybeReadable<UseStoreOptions<T, T> | undefined>,
|
|
4091
|
+
): Readable<T>
|
|
3805
4092
|
```
|
|
3806
4093
|
|
|
3807
4094
|
- `store` — The store to subscribe to (or a readable store of it).
|
|
@@ -4432,9 +4719,9 @@ function createPlatformStores(): {
|
|
|
4432
4719
|
Creates a store that tracks async function state.
|
|
4433
4720
|
|
|
4434
4721
|
```typescript
|
|
4435
|
-
function createPromiseStore<T extends
|
|
4436
|
-
asyncFn: T
|
|
4437
|
-
): PromiseStore<
|
|
4722
|
+
function createPromiseStore<T, A extends unknown[]>(
|
|
4723
|
+
asyncFn: (...args: A) => Promise<T>,
|
|
4724
|
+
): PromiseStore<T, A>
|
|
4438
4725
|
```
|
|
4439
4726
|
|
|
4440
4727
|
- `asyncFn` — The async function to track
|
|
@@ -4763,7 +5050,7 @@ Peer dependencies:
|
|
|
4763
5050
|
- `@molecule/app-logger` ^1.0.1
|
|
4764
5051
|
- `@molecule/app-platform` ^1.0.1
|
|
4765
5052
|
- `@molecule/app-push` ^1.0.1
|
|
4766
|
-
- `@molecule/app-routing` ^1.
|
|
5053
|
+
- `@molecule/app-routing` ^1.4.0
|
|
4767
5054
|
- `@molecule/app-state` ^1.2.0
|
|
4768
5055
|
- `@molecule/app-storage` ^1.1.1
|
|
4769
5056
|
- `@molecule/app-theme` ^1.0.1
|