@molecule/app-svelte 1.0.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.
Files changed (103) hide show
  1. package/LICENSE +115 -0
  2. package/README.md +2032 -0
  3. package/dist/context.d.ts +126 -0
  4. package/dist/context.d.ts.map +1 -0
  5. package/dist/context.js +217 -0
  6. package/dist/context.js.map +1 -0
  7. package/dist/index.d.ts +60 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +60 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/stores/async-state.d.ts +47 -0
  12. package/dist/stores/async-state.d.ts.map +1 -0
  13. package/dist/stores/async-state.js +89 -0
  14. package/dist/stores/async-state.js.map +1 -0
  15. package/dist/stores/auth.d.ts +54 -0
  16. package/dist/stores/auth.d.ts.map +1 -0
  17. package/dist/stores/auth.js +93 -0
  18. package/dist/stores/auth.js.map +1 -0
  19. package/dist/stores/capacitor-app.d.ts +46 -0
  20. package/dist/stores/capacitor-app.d.ts.map +1 -0
  21. package/dist/stores/capacitor-app.js +59 -0
  22. package/dist/stores/capacitor-app.js.map +1 -0
  23. package/dist/stores/change-password.d.ts +17 -0
  24. package/dist/stores/change-password.d.ts.map +1 -0
  25. package/dist/stores/change-password.js +17 -0
  26. package/dist/stores/change-password.js.map +1 -0
  27. package/dist/stores/device.d.ts +39 -0
  28. package/dist/stores/device.d.ts.map +1 -0
  29. package/dist/stores/device.js +51 -0
  30. package/dist/stores/device.js.map +1 -0
  31. package/dist/stores/forms.d.ts +121 -0
  32. package/dist/stores/forms.d.ts.map +1 -0
  33. package/dist/stores/forms.js +178 -0
  34. package/dist/stores/forms.js.map +1 -0
  35. package/dist/stores/http.d.ts +119 -0
  36. package/dist/stores/http.d.ts.map +1 -0
  37. package/dist/stores/http.js +206 -0
  38. package/dist/stores/http.js.map +1 -0
  39. package/dist/stores/i18n.d.ts +50 -0
  40. package/dist/stores/i18n.d.ts.map +1 -0
  41. package/dist/stores/i18n.js +67 -0
  42. package/dist/stores/i18n.js.map +1 -0
  43. package/dist/stores/index.d.ts +27 -0
  44. package/dist/stores/index.d.ts.map +1 -0
  45. package/dist/stores/index.js +27 -0
  46. package/dist/stores/index.js.map +1 -0
  47. package/dist/stores/logger.d.ts +83 -0
  48. package/dist/stores/logger.d.ts.map +1 -0
  49. package/dist/stores/logger.js +104 -0
  50. package/dist/stores/logger.js.map +1 -0
  51. package/dist/stores/login.d.ts +33 -0
  52. package/dist/stores/login.d.ts.map +1 -0
  53. package/dist/stores/login.js +32 -0
  54. package/dist/stores/login.js.map +1 -0
  55. package/dist/stores/oauth.d.ts +74 -0
  56. package/dist/stores/oauth.d.ts.map +1 -0
  57. package/dist/stores/oauth.js +183 -0
  58. package/dist/stores/oauth.js.map +1 -0
  59. package/dist/stores/password-reset.d.ts +31 -0
  60. package/dist/stores/password-reset.d.ts.map +1 -0
  61. package/dist/stores/password-reset.js +26 -0
  62. package/dist/stores/password-reset.js.map +1 -0
  63. package/dist/stores/platform.d.ts +41 -0
  64. package/dist/stores/platform.d.ts.map +1 -0
  65. package/dist/stores/platform.js +44 -0
  66. package/dist/stores/platform.js.map +1 -0
  67. package/dist/stores/promise.d.ts +41 -0
  68. package/dist/stores/promise.d.ts.map +1 -0
  69. package/dist/stores/promise.js +76 -0
  70. package/dist/stores/promise.js.map +1 -0
  71. package/dist/stores/push.d.ts +41 -0
  72. package/dist/stores/push.d.ts.map +1 -0
  73. package/dist/stores/push.js +73 -0
  74. package/dist/stores/push.js.map +1 -0
  75. package/dist/stores/router.d.ts +74 -0
  76. package/dist/stores/router.d.ts.map +1 -0
  77. package/dist/stores/router.js +131 -0
  78. package/dist/stores/router.js.map +1 -0
  79. package/dist/stores/signup.d.ts +18 -0
  80. package/dist/stores/signup.d.ts.map +1 -0
  81. package/dist/stores/signup.js +17 -0
  82. package/dist/stores/signup.js.map +1 -0
  83. package/dist/stores/state.d.ts +62 -0
  84. package/dist/stores/state.d.ts.map +1 -0
  85. package/dist/stores/state.js +74 -0
  86. package/dist/stores/state.js.map +1 -0
  87. package/dist/stores/storage.d.ts +76 -0
  88. package/dist/stores/storage.d.ts.map +1 -0
  89. package/dist/stores/storage.js +159 -0
  90. package/dist/stores/storage.js.map +1 -0
  91. package/dist/stores/theme.d.ts +68 -0
  92. package/dist/stores/theme.d.ts.map +1 -0
  93. package/dist/stores/theme.js +119 -0
  94. package/dist/stores/theme.js.map +1 -0
  95. package/dist/stores/version.d.ts +44 -0
  96. package/dist/stores/version.d.ts.map +1 -0
  97. package/dist/stores/version.js +73 -0
  98. package/dist/stores/version.js.map +1 -0
  99. package/dist/types.d.ts +46 -0
  100. package/dist/types.d.ts.map +1 -0
  101. package/dist/types.js +7 -0
  102. package/dist/types.js.map +1 -0
  103. package/package.json +59 -0
package/README.md ADDED
@@ -0,0 +1,2032 @@
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-08-04T00:41:20.484Z
7
+ -->
8
+
9
+ # @molecule/app-svelte
10
+
11
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
+ > It is written to be read by coding agents as much as by people, and is generated from this
13
+ > package's source — edit `src/index.ts` JSDoc, not this file.
14
+
15
+ Svelte framework bindings for molecule.dev.
16
+
17
+ Provides Svelte stores and context utilities for all molecule core
18
+ interfaces: call `setMoleculeContext(config)` once in the root layout,
19
+ then consume services anywhere below via store factories
20
+ (`createAuthStores`, `createThemeStores`, `createI18nStores`, …).
21
+
22
+ ## Quick Start
23
+
24
+ ```svelte
25
+ <!-- +layout.svelte — wire providers ONCE, during component init -->
26
+ <script lang="ts">
27
+ import { setMoleculeContext } from '@molecule/app-svelte'
28
+ import { provider as stateProvider } from '@molecule/app-state-zustand'
29
+ import { provider as themeProvider } from '@molecule/app-theme-css-variables'
30
+ import { createJWTAuthClient } from '@molecule/app-auth'
31
+
32
+ setMoleculeContext({
33
+ state: stateProvider,
34
+ auth: createJWTAuthClient({ baseURL: '/api' }),
35
+ theme: themeProvider,
36
+ })
37
+ </script>
38
+
39
+ <slot />
40
+
41
+ <!-- Component.svelte — consume via stores -->
42
+ <script lang="ts">
43
+ import { createAuthStores, createThemeStores } from '@molecule/app-svelte'
44
+
45
+ const { user, isAuthenticated, logout } = createAuthStores<{ name?: string }>()
46
+ const { theme, toggleTheme, mode } = createThemeStores()
47
+ </script>
48
+
49
+ {#if $isAuthenticated}
50
+ <div style:background={$theme.colors.background}>
51
+ <h1>Welcome, {$user?.name}!</h1>
52
+ <button on:click={toggleTheme}>Toggle ({$mode})</button>
53
+ <button on:click={() => logout()}>Logout</button>
54
+ </div>
55
+ {/if}
56
+ ```
57
+
58
+ ## Type
59
+
60
+ `framework`
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ npm install @molecule/app-svelte @molecule/app-auth @molecule/app-device @molecule/app-forms @molecule/app-http @molecule/app-i18n @molecule/app-logger @molecule/app-platform @molecule/app-push @molecule/app-routing @molecule/app-state @molecule/app-storage @molecule/app-theme @molecule/app-ui @molecule/app-utilities @molecule/app-version svelte
66
+ ```
67
+
68
+ ## API
69
+
70
+ ### Interfaces
71
+
72
+ #### `AsyncStateStore`
73
+
74
+ Async state store.
75
+
76
+ ```typescript
77
+ interface AsyncStateStore<T> extends Writable<T> {
78
+ setState: (value: T | ((prev: T) => T) | Promise<T | ((prev: T) => T)>) => void
79
+ extendState: (
80
+ partial:
81
+ Partial<T> | ((prev: T) => Partial<T>) | Promise<Partial<T> | ((prev: T) => Partial<T>)>,
82
+ ) => void
83
+ }
84
+ ```
85
+
86
+ #### `AuthClient`
87
+
88
+ Auth client interface that all auth bond packages must implement.
89
+ Provides login/logout/register flows, token management, profile
90
+ updates, and auth state subscription.
91
+
92
+ ```typescript
93
+ interface AuthClient<T = UserProfile> {
94
+ /**
95
+ * Returns the current authentication state snapshot.
96
+ */
97
+ getState(): AuthState<T>
98
+ /**
99
+ * Returns whether the user is currently authenticated.
100
+ */
101
+ isAuthenticated(): boolean
102
+ /**
103
+ * Gets the current user.
104
+ */
105
+ getUser(): T | null
106
+ /**
107
+ * Updates the cached user object (state + persistent storage) without
108
+ * hitting the network. Intended for local refreshes after a per-app
109
+ * mutation (e.g., the user just PATCHed their own profile and the
110
+ * server returned the canonical row). Does NOT change tokens.
111
+ */
112
+ setUser(user: T | null): void
113
+ /**
114
+ * Gets the current access token.
115
+ */
116
+ getAccessToken(): string | null
117
+ /**
118
+ * Stores the access token in the configured token storage adapter (in-memory
119
+ * by default). Use this to seed the token after an out-of-band exchange (e.g.
120
+ * the OAuth code→token redirect) instead of writing to `localStorage` directly,
121
+ * which would violate the in-memory-default storage contract and make the bearer
122
+ * token JS-readable (XSS-exfiltratable). Pass `null` to clear it.
123
+ */
124
+ setAccessToken(token: string | null): void
125
+ /**
126
+ * Gets the refresh token.
127
+ */
128
+ getRefreshToken(): string | null
129
+ /**
130
+ * Logs in with credentials.
131
+ */
132
+ login(credentials: LoginCredentials): Promise<AuthResult<T>>
133
+ /**
134
+ * Logs out the current user.
135
+ */
136
+ logout(): Promise<void>
137
+ /**
138
+ * Registers a new user.
139
+ */
140
+ register(data: RegisterData): Promise<AuthResult<T>>
141
+ /**
142
+ * Refreshes the access token.
143
+ */
144
+ refresh(): Promise<AuthResult<T>>
145
+ /**
146
+ * Requests a password reset.
147
+ */
148
+ requestPasswordReset(data: PasswordResetRequest): Promise<void>
149
+ /**
150
+ * Confirms a password reset.
151
+ */
152
+ confirmPasswordReset(data: PasswordResetConfirm): Promise<void>
153
+ /**
154
+ * Updates the current user's profile.
155
+ */
156
+ updateProfile(data: Partial<T>): Promise<T>
157
+ /**
158
+ * Changes the current user's password.
159
+ */
160
+ changePassword(oldPassword: string, newPassword: string): Promise<void>
161
+ /**
162
+ * Initializes auth state (e.g., from stored tokens).
163
+ */
164
+ initialize(): Promise<void>
165
+ /**
166
+ * Subscribes to auth state changes.
167
+ */
168
+ subscribe(callback: (state: AuthState<T>) => void): () => void
169
+ /**
170
+ * Subscribes to auth state changes (alias for subscribe).
171
+ */
172
+ onAuthChange(callback: (state: AuthState<T>) => void): () => void
173
+ /**
174
+ * Gets the current access token (alias for getAccessToken).
175
+ */
176
+ getToken?(): string | null
177
+ /**
178
+ * Adds an auth event listener.
179
+ */
180
+ addEventListener(listener: AuthEventListener): () => void
181
+ /**
182
+ * Destroys the auth client.
183
+ */
184
+ destroy(): void
185
+ }
186
+ ```
187
+
188
+ #### `AuthState`
189
+
190
+ Reactive authentication state snapshot (initialized, authenticated, user, loading, and error).
191
+
192
+ ```typescript
193
+ interface AuthState<T = UserProfile> {
194
+ /**
195
+ * Whether auth state has been initialized.
196
+ */
197
+ initialized: boolean
198
+ /**
199
+ * Whether the user is authenticated.
200
+ */
201
+ authenticated: boolean
202
+ /**
203
+ * Current user (if authenticated).
204
+ */
205
+ user: T | null
206
+ /**
207
+ * Whether an auth operation is in progress.
208
+ */
209
+ loading: boolean
210
+ /**
211
+ * Last auth error (if any).
212
+ */
213
+ error: string | null
214
+ }
215
+ ```
216
+
217
+ #### `FormController`
218
+
219
+ Form controller interface.
220
+
221
+ All form providers must implement this interface.
222
+
223
+ ```typescript
224
+ interface FormController<T extends Record<string, unknown> = Record<string, unknown>> {
225
+ /**
226
+ * Gets the current form state.
227
+ */
228
+ getState(): FormState<T>
229
+ /**
230
+ * Gets the value of a specific field.
231
+ */
232
+ getValue(name: string): unknown
233
+ getValue<K extends keyof T>(name: K): T[K]
234
+ /**
235
+ * Gets all form values.
236
+ */
237
+ getValues(): T
238
+ /**
239
+ * Sets the value of a specific field.
240
+ */
241
+ setValue(
242
+ name: string,
243
+ value: unknown,
244
+ options?: {
245
+ shouldValidate?: boolean
246
+ shouldDirty?: boolean
247
+ shouldTouch?: boolean
248
+ },
249
+ ): void
250
+ /**
251
+ * Sets multiple values at once.
252
+ */
253
+ setValues(
254
+ values: Partial<T>,
255
+ options?: {
256
+ shouldValidate?: boolean
257
+ },
258
+ ): void
259
+ /**
260
+ * Gets the error for a specific field.
261
+ */
262
+ getError(name: string): string | undefined
263
+ /**
264
+ * Sets the error for a specific field.
265
+ */
266
+ setError(name: string, error: string | undefined): void
267
+ /**
268
+ * Clears the error for a specific field.
269
+ */
270
+ clearError<K extends keyof T>(name: K): void
271
+ /**
272
+ * Clears all errors.
273
+ */
274
+ clearErrors(): void
275
+ /**
276
+ * Gets the field state for a specific field.
277
+ */
278
+ getFieldState<K extends keyof T>(name: K): FieldState<T[K]>
279
+ /**
280
+ * Registers a field for form management.
281
+ */
282
+ register(nameOrOptions: string | RegisterOptions, options?: RegisterOptions): FieldRegistration
283
+ /**
284
+ * Unregisters a field.
285
+ */
286
+ unregister(name: string): void
287
+ /**
288
+ * Validates a specific field.
289
+ */
290
+ validateField<K extends keyof T>(name: K): Promise<boolean>
291
+ /**
292
+ * Validates all fields.
293
+ */
294
+ validate(): Promise<boolean>
295
+ /**
296
+ * Resets the form to initial values.
297
+ */
298
+ reset(values?: Partial<T>): void
299
+ /**
300
+ * Handles form submission.
301
+ */
302
+ handleSubmit(
303
+ onSubmit: (values: T) => void | Promise<void>,
304
+ onError?: (errors: Partial<Record<keyof T, string>>) => void,
305
+ ): (event?: { preventDefault?: () => void }) => Promise<void>
306
+ /**
307
+ * Sets focus to a field.
308
+ */
309
+ setFocus(name: keyof T): void
310
+ /**
311
+ * Subscribes to form state changes.
312
+ */
313
+ subscribe(callback: (state: FormState<T>) => void): () => void
314
+ /**
315
+ * Destroys the form controller.
316
+ */
317
+ destroy(): void
318
+ }
319
+ ```
320
+
321
+ #### `FormOptions`
322
+
323
+ Form creation options.
324
+
325
+ ```typescript
326
+ interface FormOptions<T extends Record<string, unknown>> {
327
+ /**
328
+ * Default values.
329
+ */
330
+ defaultValues?: Partial<T>
331
+ /**
332
+ * Validation mode.
333
+ */
334
+ mode?: 'onSubmit' | 'onChange' | 'onBlur' | 'all'
335
+ /**
336
+ * Revalidation mode.
337
+ */
338
+ reValidateMode?: 'onChange' | 'onBlur' | 'onSubmit'
339
+ /**
340
+ * Whether to focus the first error field on submit.
341
+ */
342
+ shouldFocusError?: boolean
343
+ /**
344
+ * Form-level validation function.
345
+ */
346
+ validate?: (
347
+ values: T,
348
+ ) => Partial<Record<keyof T, string>> | Promise<Partial<Record<keyof T, string>>>
349
+ }
350
+ ```
351
+
352
+ #### `HttpClient`
353
+
354
+ HTTP client interface.
355
+
356
+ All HTTP providers must implement this interface.
357
+
358
+ ```typescript
359
+ interface HttpClient {
360
+ /**
361
+ * Base URL for all requests.
362
+ */
363
+ baseURL: string
364
+ /**
365
+ * Default headers for all requests.
366
+ */
367
+ defaultHeaders: Record<string, string>
368
+ /**
369
+ * Makes a generic HTTP request.
370
+ */
371
+ request<T = unknown>(config: FullRequestConfig): Promise<HttpResponse<T>>
372
+ /**
373
+ * Makes a GET request.
374
+ */
375
+ get<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
376
+ /**
377
+ * Makes a POST request.
378
+ */
379
+ post<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
380
+ /**
381
+ * Makes a PUT request.
382
+ */
383
+ put<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
384
+ /**
385
+ * Makes a PATCH request.
386
+ */
387
+ patch<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
388
+ /**
389
+ * Makes a DELETE request.
390
+ */
391
+ delete<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
392
+ /**
393
+ * Adds a request interceptor.
394
+ * Returns a function to remove the interceptor.
395
+ */
396
+ addRequestInterceptor(interceptor: RequestInterceptor): () => void
397
+ /**
398
+ * Adds a response interceptor.
399
+ * Returns a function to remove the interceptor.
400
+ */
401
+ addResponseInterceptor(interceptor: ResponseInterceptor): () => void
402
+ /**
403
+ * Adds an error interceptor.
404
+ * Returns a function to remove the interceptor.
405
+ */
406
+ addErrorInterceptor(interceptor: ErrorInterceptor): () => void
407
+ /**
408
+ * Sets the authorization token.
409
+ */
410
+ setAuthToken(token: string | null): void
411
+ /**
412
+ * Returns the current authorization token, or `null` if not set.
413
+ */
414
+ getAuthToken(): string | null
415
+ /**
416
+ * Registers a handler for authentication errors (401).
417
+ *
418
+ * @returns An unsubscribe function.
419
+ */
420
+ onAuthError(handler: () => void): () => void
421
+ }
422
+ ```
423
+
424
+ #### `HttpState`
425
+
426
+ State for async HTTP operations.
427
+
428
+ ```typescript
429
+ interface HttpState<T> {
430
+ data: T | null
431
+ loading: boolean
432
+ error: Error | null
433
+ }
434
+ ```
435
+
436
+ #### `I18nProvider`
437
+
438
+ i18n provider interface.
439
+
440
+ All i18n providers must implement this interface.
441
+
442
+ ```typescript
443
+ interface I18nProvider {
444
+ /**
445
+ * Gets the current locale.
446
+ */
447
+ getLocale(): string
448
+ /**
449
+ * Sets the current locale.
450
+ *
451
+ * **Fleet contract:** every conformant provider (the core simple provider,
452
+ * `@molecule/api-i18n-simple`, `@molecule/app-i18n-i18next`, and
453
+ * `@molecule/app-i18n-react-i18next`) MUST throw `Error('Locale "<code>"
454
+ * not found')` when `locale` is not registered — via the constructor's
455
+ * `initialLocales`/`locales` config, `addLocale()`, or `addTranslations()`
456
+ * (all three register a locale). It must NOT silently degrade to
457
+ * fallback-locale text while `getLocale()` reports the unregistered code —
458
+ * that divergence makes a misconfigured locale switch indistinguishable
459
+ * from a working one until a user notices the wrong language on screen.
460
+ */
461
+ setLocale(locale: string): Promise<void>
462
+ /**
463
+ * Gets all available locales.
464
+ */
465
+ getLocales(): LocaleConfig[]
466
+ /**
467
+ * Adds a locale.
468
+ */
469
+ addLocale(config: LocaleConfig): void
470
+ /**
471
+ * Removes a locale by code, notifying subscribers so language pickers
472
+ * built on `onLocaleChange` re-render their list. If the removed locale
473
+ * is currently active, the caller is responsible for switching to a
474
+ * fallback (e.g. `'en'`) BEFORE calling this — the provider will not
475
+ * auto-fall-back on its own.
476
+ *
477
+ * Returns `true` if the locale was registered and removed, `false`
478
+ * otherwise.
479
+ */
480
+ removeLocale(code: string): boolean
481
+ /**
482
+ * Adds translations to a locale. Auto-creates the locale if it doesn't exist.
483
+ *
484
+ * **Fleet contract:** merges are DEEP, not a shallow spread — registering
485
+ * two calls (e.g. two modules) that share a top-level namespace key merges
486
+ * their subtrees instead of the second call clobbering the first's nested
487
+ * translations wholesale. `@molecule/api-i18n-simple` implements the same
488
+ * contract on the API side.
489
+ */
490
+ addTranslations(locale: string, translations: Translations, namespace?: string): void
491
+ /**
492
+ * Translates a key with optional interpolation values and pluralization.
493
+ *
494
+ * **Fleet plural contract (matches i18next's own key resolution order):**
495
+ * when `options.count` is provided, the plural-suffixed key
496
+ * (`` `${key}_${pluralForm}` ``, e.g. `item_one`/`item_few`/…, falling back
497
+ * to `` `${key}_other` ``) is looked up FIRST and wins over the base `key`
498
+ * if BOTH are registered. Only when no plural-suffixed key exists at all
499
+ * does resolution fall back to the base key. A catalog that ships both
500
+ * `item` and `item_one`/`item_other` therefore pluralizes identically
501
+ * whichever provider is bonded.
502
+ *
503
+ * @returns The translated string, or the default value / key if not found.
504
+ */
505
+ t(
506
+ key: string,
507
+ values?: InterpolationValues,
508
+ options?: {
509
+ defaultValue?: string
510
+ count?: number
511
+ },
512
+ ): string
513
+ /**
514
+ * Checks if a translation key exists.
515
+ *
516
+ * **Fleet contract:** follows the SAME locale-resolution chain as `t()` —
517
+ * the active locale, then the English fallback — so `exists(key) === true`
518
+ * whenever `t(key)` would render real translated text (not the raw key or
519
+ * an inline `defaultValue`). Do not narrow this to "only the active
520
+ * locale's own catalog"; that made `exists()` return `false` for keys `t()`
521
+ * happily rendered via the English fallback, and the answer differed by
522
+ * provider.
523
+ *
524
+ * @returns `true` if the key has a translation.
525
+ */
526
+ exists(key: string): boolean
527
+ /**
528
+ * Formats a number according to the current locale.
529
+ *
530
+ * @returns The locale-formatted number string.
531
+ */
532
+ formatNumber(value: number, options?: NumberFormatOptions): string
533
+ /**
534
+ * Formats a date according to the current locale.
535
+ *
536
+ * @returns The locale-formatted date string.
537
+ */
538
+ formatDate(value: Date | number | string, options?: DateFormatOptions): string
539
+ /**
540
+ * Formats a relative time (e.g. "2 hours ago").
541
+ *
542
+ * @returns The locale-formatted relative time string.
543
+ */
544
+ formatRelativeTime(
545
+ value: Date | number,
546
+ options?: {
547
+ unit?: Intl.RelativeTimeFormatUnit
548
+ },
549
+ ): string
550
+ /**
551
+ * Formats a list (e.g. "A, B, and C").
552
+ *
553
+ * @returns The locale-formatted list string.
554
+ */
555
+ formatList(
556
+ values: string[],
557
+ options?: {
558
+ type?: 'conjunction' | 'disjunction' | 'unit'
559
+ },
560
+ ): string
561
+ /**
562
+ * Subscribes to locale changes.
563
+ *
564
+ * @returns An unsubscribe function.
565
+ */
566
+ onLocaleChange(listener: (locale: string) => void): () => void
567
+ /**
568
+ * Gets the text direction for the current locale.
569
+ *
570
+ * @returns `'ltr'` or `'rtl'`.
571
+ */
572
+ getDirection(): 'ltr' | 'rtl'
573
+ /**
574
+ * Checks if a translation key exists (alias for exists).
575
+ */
576
+ hasKey?(key: string): boolean
577
+ /**
578
+ * Checks if the provider is ready.
579
+ */
580
+ isReady?(): boolean
581
+ /**
582
+ * Registers a callback for when the provider is ready.
583
+ */
584
+ onReady?(callback: () => void): () => void
585
+ /**
586
+ * Registers a lazily-loaded content module for automatic reload on locale changes.
587
+ * All registered content is reloaded during `setLocale()` before listeners fire,
588
+ * ensuring content is available on the first re-render with no flash.
589
+ *
590
+ * Idempotent: registering the same module name twice is a no-op.
591
+ */
592
+ registerContent?(module: string, loader: (locale: string) => Promise<void>): void
593
+ }
594
+ ```
595
+
596
+ #### `Logger`
597
+
598
+ Logger instance with leveled logging methods, child logger creation,
599
+ and transport management.
600
+
601
+ ```typescript
602
+ interface Logger {
603
+ /**
604
+ * Logs a trace message.
605
+ */
606
+ trace(message: string, ...args: unknown[]): void
607
+ /**
608
+ * Logs a debug message.
609
+ */
610
+ debug(message: string, ...args: unknown[]): void
611
+ /**
612
+ * Logs an info message.
613
+ */
614
+ info(message: string, ...args: unknown[]): void
615
+ /**
616
+ * Logs a warning message.
617
+ */
618
+ warn(message: string, ...args: unknown[]): void
619
+ /**
620
+ * Logs an error message.
621
+ */
622
+ error(message: string | Error, ...args: unknown[]): void
623
+ /**
624
+ * Sets the log level.
625
+ */
626
+ setLevel(level: LogLevel): void
627
+ /**
628
+ * Gets the current log level.
629
+ */
630
+ getLevel(): LogLevel
631
+ /**
632
+ * Creates a child logger with a namespace.
633
+ */
634
+ child(name: string, context?: Record<string, unknown>): Logger
635
+ /**
636
+ * Adds additional context to the logger.
637
+ */
638
+ withContext(context: Record<string, unknown>): Logger
639
+ /**
640
+ * Adds a transport.
641
+ */
642
+ addTransport(transport: LogTransport): () => void
643
+ /**
644
+ * Removes a transport.
645
+ */
646
+ removeTransport(transport: LogTransport): void
647
+ }
648
+ ```
649
+
650
+ #### `LoggerProvider`
651
+
652
+ Logger provider interface that all logger bond packages must implement.
653
+ Creates and manages logger instances and global log configuration.
654
+
655
+ ```typescript
656
+ interface LoggerProvider {
657
+ /**
658
+ * Gets a logger by name, or the root logger if no name given.
659
+ */
660
+ getLogger(name?: string): Logger
661
+ /**
662
+ * Creates a named logger.
663
+ */
664
+ createLogger(nameOrConfig: string | LoggerConfig, config?: LoggerConfig): Logger
665
+ /**
666
+ * Sets the global log level.
667
+ */
668
+ setLevel(level: LogLevel): void
669
+ /**
670
+ * Gets the global log level.
671
+ */
672
+ getLevel(): LogLevel
673
+ /**
674
+ * Adds a global transport.
675
+ */
676
+ addTransport(transport: LogTransport): () => void
677
+ /**
678
+ * Enables logging.
679
+ */
680
+ enable(): void
681
+ /**
682
+ * Disables logging.
683
+ */
684
+ disable(): void
685
+ /**
686
+ * Checks if logging is enabled.
687
+ *
688
+ * @returns `true` if logging is currently enabled.
689
+ */
690
+ isEnabled(): boolean
691
+ }
692
+ ```
693
+
694
+ #### `MoleculeConfig`
695
+
696
+ Configuration for molecule Svelte context.
697
+
698
+ ```typescript
699
+ interface MoleculeConfig {
700
+ state?: StateProvider
701
+ auth?: AuthClient<unknown>
702
+ theme?: ThemeProvider
703
+ router?: Router
704
+ i18n?: I18nProvider
705
+ http?: HttpClient
706
+ storage?: StorageProvider
707
+ logger?: LoggerProvider
708
+ }
709
+ ```
710
+
711
+ #### `MoleculeStore`
712
+
713
+ Reactive state container with getState, setState, subscribe, and destroy.
714
+
715
+ All state management providers must implement this interface.
716
+
717
+ ```typescript
718
+ interface Store<T> {
719
+ /**
720
+ * Gets the current state.
721
+ */
722
+ getState(): T
723
+ /**
724
+ * Sets the state (partial or via updater function).
725
+ */
726
+ setState(partial: Partial<T> | ((state: T) => Partial<T>)): void
727
+ /**
728
+ * Subscribes to state changes.
729
+ * Returns an unsubscribe function.
730
+ */
731
+ subscribe(listener: StateListener<T>): () => void
732
+ /**
733
+ * Destroys the store and cleans up subscriptions.
734
+ */
735
+ destroy(): void
736
+ }
737
+ ```
738
+
739
+ #### `OAuthHelpers`
740
+
741
+ OAuth helpers returned by {@link createOAuthHelpers}.
742
+
743
+ ```typescript
744
+ interface OAuthHelpers {
745
+ /** Readable store of available OAuth provider names. */
746
+ providers: Readable<string[]>
747
+ /** Builds the OAuth initiation URL for a provider. */
748
+ getOAuthUrl: (provider: string) => string
749
+ /** Full-page redirect to the provider's OAuth initiation endpoint. */
750
+ redirect: (provider: string) => void
751
+ /**
752
+ * Handles an OAuth callback: when the current URL carries a `code` param and
753
+ * a provider was stashed by {@link redirect}, exchanges the code for a
754
+ * session. A guarded no-op otherwise. Runs automatically when
755
+ * {@link createOAuthHelpers} is called in a browser; exposed for manual
756
+ * invocation (e.g. tests or custom callback screens).
757
+ */
758
+ handleCallback: () => Promise<void>
759
+ }
760
+ ```
761
+
762
+ #### `OAuthOptions`
763
+
764
+ OAuth configuration options.
765
+
766
+ ```typescript
767
+ interface OAuthOptions {
768
+ /** Base URL for the API server (e.g. `https://api.example.com`). */
769
+ baseURL?: string
770
+ /** List of supported OAuth provider names (e.g. `['google', 'github']`). */
771
+ oauthProviders?: string[]
772
+ /** Path prefix for OAuth initiation routes. Defaults to `/oauth`. */
773
+ oauthEndpoint?: string
774
+ /** Path for the OAuth login POST endpoint. Defaults to `/users/log-in/oauth`. */
775
+ loginEndpoint?: string
776
+ /** Callback fired after a successful OAuth login. */
777
+ onSuccess?: () => void
778
+ /** Callback fired with an error message when the OAuth login fails. */
779
+ onError?: (error: string) => void
780
+ /**
781
+ * Explicit auth client used to establish the session after the callback
782
+ * exchange. Defaults to the client in Svelte context (only resolvable when
783
+ * called during component initialization) — pass one explicitly for
784
+ * callers/tests outside a component/context.
785
+ */
786
+ authClient?: AuthClient<unknown>
787
+ }
788
+ ```
789
+
790
+ #### `PasswordResetStores`
791
+
792
+ Password reset stores.
793
+
794
+ ```typescript
795
+ interface PasswordResetStores {
796
+ request: Readable<PromiseState<void>> & {
797
+ call: (data: PasswordResetRequest) => Promise<void>
798
+ cancel: (message?: string) => void
799
+ reset: () => void
800
+ }
801
+ confirm: Readable<PromiseState<void>> & {
802
+ call: (data: PasswordResetConfirm) => Promise<void>
803
+ cancel: (message?: string) => void
804
+ reset: () => void
805
+ }
806
+ resetAll: () => void
807
+ }
808
+ ```
809
+
810
+ #### `PromiseStore`
811
+
812
+ Promise store with action methods.
813
+
814
+ ```typescript
815
+ interface PromiseStore<T> extends Readable<PromiseState<T>> {
816
+ call: (...args: any[]) => Promise<T>
817
+ cancel: (message?: string) => void
818
+ reset: () => void
819
+ }
820
+ ```
821
+
822
+ #### `Readable`
823
+
824
+ Readable interface for subscribing.
825
+
826
+ ```typescript
827
+ interface Readable<T> {
828
+ /**
829
+ * Subscribe on value changes.
830
+ * @param run subscription callback
831
+ * @param invalidate cleanup callback
832
+ */
833
+ subscribe(this: void, run: Subscriber<T>, invalidate?: () => void): Unsubscriber
834
+ }
835
+ ```
836
+
837
+ #### `RouteLocation`
838
+
839
+ Current URL decomposed into pathname, search string, hash, navigation state, and unique key.
840
+
841
+ ```typescript
842
+ interface RouteLocation {
843
+ /**
844
+ * Current pathname.
845
+ */
846
+ pathname: string
847
+ /**
848
+ * Query string (including leading ?).
849
+ */
850
+ search: string
851
+ /**
852
+ * Hash (including leading #).
853
+ */
854
+ hash: string
855
+ /**
856
+ * State data passed with navigation.
857
+ */
858
+ state?: unknown
859
+ /**
860
+ * Unique key for this location.
861
+ */
862
+ key?: string
863
+ }
864
+ ```
865
+
866
+ #### `Router`
867
+
868
+ Client-side router providing navigation, guards, route matching, and history control.
869
+
870
+ All routing providers must implement this interface.
871
+
872
+ ```typescript
873
+ interface Router {
874
+ /**
875
+ * Returns the current route location (pathname, search, hash, state).
876
+ */
877
+ getLocation(): RouteLocation
878
+ /**
879
+ * Gets the current route params.
880
+ */
881
+ getParams<T extends RouteParams = RouteParams>(): T
882
+ /**
883
+ * Gets the current query params.
884
+ */
885
+ getQuery(): QueryParams
886
+ /**
887
+ * Gets a specific query parameter.
888
+ */
889
+ getQueryParam(key: string): string | undefined
890
+ /**
891
+ * Gets the current hash.
892
+ */
893
+ getHash(): string
894
+ /**
895
+ * Navigates to a path.
896
+ */
897
+ navigate(path: string, options?: NavigateOptions): void
898
+ /**
899
+ * Navigates to a named route.
900
+ */
901
+ navigateTo(
902
+ name: string,
903
+ params?: RouteParams,
904
+ query?: QueryParams,
905
+ options?: NavigateOptions,
906
+ ): void
907
+ /**
908
+ * Goes back in history.
909
+ */
910
+ back(): void
911
+ /**
912
+ * Goes forward in history.
913
+ */
914
+ forward(): void
915
+ /**
916
+ * Goes to a specific point in history.
917
+ */
918
+ go(delta: number): void
919
+ /**
920
+ * Updates the current query params.
921
+ */
922
+ setQuery(params: QueryParams, options?: NavigateOptions): void
923
+ /**
924
+ * Updates a specific query parameter.
925
+ */
926
+ setQueryParam(key: string, value: string | undefined, options?: NavigateOptions): void
927
+ /**
928
+ * Updates the current hash.
929
+ */
930
+ setHash(hash: string, options?: NavigateOptions): void
931
+ /**
932
+ * Checks if a path matches the current location.
933
+ *
934
+ * @returns `true` if the path matches the current route.
935
+ */
936
+ isActive(path: string, exact?: boolean): boolean
937
+ /**
938
+ * Matches a path pattern against a pathname.
939
+ */
940
+ matchPath<Params extends RouteParams = RouteParams>(
941
+ pattern: string,
942
+ pathname: string,
943
+ ): RouteMatch<Params> | null
944
+ /**
945
+ * Generates a URL from a named route.
946
+ */
947
+ generatePath(name: string, params?: RouteParams, query?: QueryParams): string
948
+ /**
949
+ * Subscribes to route changes.
950
+ */
951
+ subscribe(listener: RouteChangeListener): () => void
952
+ /**
953
+ * Adds a navigation guard.
954
+ */
955
+ addGuard(guard: NavigationGuard): () => void
956
+ /**
957
+ * Registers route definitions.
958
+ */
959
+ registerRoutes(routes: RouteDefinition[]): void
960
+ /**
961
+ * Gets all registered routes.
962
+ */
963
+ getRoutes(): RouteDefinition[]
964
+ /**
965
+ * Destroys the router.
966
+ */
967
+ destroy(): void
968
+ }
969
+ ```
970
+
971
+ #### `StateProvider`
972
+
973
+ State provider interface that all state management bond packages
974
+ must implement. Provides the store creation factory.
975
+
976
+ ```typescript
977
+ interface StateProvider {
978
+ /**
979
+ * Creates a new store.
980
+ */
981
+ createStore<T>(config: StoreConfig<T>): Store<T>
982
+ }
983
+ ```
984
+
985
+ #### `StorageProvider`
986
+
987
+ Storage provider interface.
988
+
989
+ All storage providers must implement this interface.
990
+
991
+ ```typescript
992
+ interface StorageProvider {
993
+ /**
994
+ * Gets a value from storage.
995
+ */
996
+ get<T = unknown>(key: string): Promise<T | null>
997
+ /**
998
+ * Sets a value in storage.
999
+ */
1000
+ set<T = unknown>(key: string, value: T): Promise<void>
1001
+ /**
1002
+ * Removes a value from storage.
1003
+ */
1004
+ remove(key: string): Promise<void>
1005
+ /**
1006
+ * Clears all values from storage.
1007
+ */
1008
+ clear(): Promise<void>
1009
+ /**
1010
+ * Gets all keys in storage.
1011
+ */
1012
+ keys(): Promise<string[]>
1013
+ /**
1014
+ * Gets multiple values from storage.
1015
+ */
1016
+ getMany?<T = unknown>(keys: string[]): Promise<Map<string, T | null>>
1017
+ /**
1018
+ * Sets multiple values in storage.
1019
+ */
1020
+ setMany?<T = unknown>(entries: Array<[string, T]>): Promise<void>
1021
+ /**
1022
+ * Removes multiple values from storage.
1023
+ */
1024
+ removeMany?(keys: string[]): Promise<void>
1025
+ }
1026
+ ```
1027
+
1028
+ #### `StorageValueState`
1029
+
1030
+ State for async storage values.
1031
+
1032
+ ```typescript
1033
+ interface StorageValueState<T> {
1034
+ value: T | undefined
1035
+ loading: boolean
1036
+ error: Error | null
1037
+ }
1038
+ ```
1039
+
1040
+ #### `StoreConfig`
1041
+
1042
+ Configuration for creating a store (initial state, optional name, and middleware chain).
1043
+
1044
+ ```typescript
1045
+ interface StoreConfig<T> {
1046
+ /**
1047
+ * Initial state value.
1048
+ */
1049
+ initialState: T
1050
+ /**
1051
+ * Optional name for debugging.
1052
+ */
1053
+ name?: string
1054
+ /**
1055
+ * Optional middleware functions.
1056
+ */
1057
+ middleware?: StoreMiddleware<T>[]
1058
+ }
1059
+ ```
1060
+
1061
+ #### `Theme`
1062
+
1063
+ Complete theme definition.
1064
+
1065
+ ```typescript
1066
+ interface Theme {
1067
+ name: string
1068
+ mode: 'light' | 'dark'
1069
+ colors: ThemeColors
1070
+ breakpoints: ThemeBreakpoints
1071
+ spacing: ThemeSpacing
1072
+ typography: ThemeTypography
1073
+ borderRadius: ThemeBorderRadius
1074
+ shadows: ThemeShadows
1075
+ transitions: ThemeTransitions
1076
+ zIndex: ThemeZIndex
1077
+ }
1078
+ ```
1079
+
1080
+ #### `ThemeProvider`
1081
+
1082
+ Manages theme state including the active theme, mode toggling,
1083
+ and change subscriptions.
1084
+
1085
+ ```typescript
1086
+ interface ThemeProvider {
1087
+ /**
1088
+ * Returns the currently active theme.
1089
+ */
1090
+ getTheme(): Theme
1091
+ /**
1092
+ * Sets the active theme by reference or by name.
1093
+ *
1094
+ * @param theme - A `Theme` object or a theme name string to activate.
1095
+ */
1096
+ setTheme(theme: Theme | string): void
1097
+ /**
1098
+ * Toggles between light and dark mode for the active theme.
1099
+ */
1100
+ toggleMode(): void
1101
+ /**
1102
+ * Subscribes to theme changes. The callback fires whenever
1103
+ * `setTheme()` or `toggleMode()` is called.
1104
+ *
1105
+ * @param callback - Invoked with the new theme after each change.
1106
+ * @returns An unsubscribe function.
1107
+ */
1108
+ subscribe(callback: (theme: Theme) => void): () => void
1109
+ /**
1110
+ * Returns all registered themes. Optional — not all providers
1111
+ * support multiple themes.
1112
+ */
1113
+ getThemes?(): Theme[]
1114
+ }
1115
+ ```
1116
+
1117
+ #### `Writable`
1118
+
1119
+ Writable interface for both updating and subscribing.
1120
+
1121
+ ```typescript
1122
+ interface Writable<T> extends Readable<T> {
1123
+ /**
1124
+ * Set value and inform subscribers.
1125
+ * @param value to set
1126
+ */
1127
+ set(this: void, value: T): void
1128
+
1129
+ /**
1130
+ * Update value using callback and inform subscribers.
1131
+ * @param updater callback
1132
+ */
1133
+ update(this: void, updater: Updater<T>): void
1134
+ }
1135
+ ```
1136
+
1137
+ ### Types
1138
+
1139
+ #### `CapacitorAppStore`
1140
+
1141
+ Return type for the Capacitor app store.
1142
+
1143
+ ```typescript
1144
+ type CapacitorAppStore = Readable<CapacitorAppState> & {
1145
+ initialize: () => Promise<void>
1146
+ }
1147
+ ```
1148
+
1149
+ #### `ChangePasswordStore`
1150
+
1151
+ Change password store type.
1152
+
1153
+ ```typescript
1154
+ type ChangePasswordStore = PromiseStore<void>
1155
+ ```
1156
+
1157
+ #### `LoginStore`
1158
+
1159
+ Login store type.
1160
+
1161
+ ```typescript
1162
+ type LoginStore<T = unknown> = PromiseStore<AuthResult<T>>
1163
+ ```
1164
+
1165
+ #### `QueryParams`
1166
+
1167
+ URL query string parameter map (single values or arrays for repeated keys).
1168
+
1169
+ ```typescript
1170
+ type QueryParams = Record<string, string | string[] | undefined>
1171
+ ```
1172
+
1173
+ #### `RouteParams`
1174
+
1175
+ URL path parameter key-value map extracted from dynamic route segments (e.g. `{ id: '123' }`).
1176
+
1177
+ ```typescript
1178
+ type RouteParams = Record<string, string>
1179
+ ```
1180
+
1181
+ #### `SignupStore`
1182
+
1183
+ Signup store type.
1184
+
1185
+ ```typescript
1186
+ type SignupStore<T = unknown> = PromiseStore<AuthResult<T>>
1187
+ ```
1188
+
1189
+ ### Functions
1190
+
1191
+ #### `createAsyncState(initialValue)`
1192
+
1193
+ Creates a writable store with async-capable setState and extendState.
1194
+
1195
+ ```typescript
1196
+ function createAsyncState(initialValue: T): AsyncStateStore<T>
1197
+ ```
1198
+
1199
+ - `initialValue` — The initial state value
1200
+
1201
+ **Returns:** The created instance.
1202
+
1203
+ #### `createAuthStores()`
1204
+
1205
+ Create auth stores from the auth client in context.
1206
+
1207
+ ```typescript
1208
+ function createAuthStores(): AuthStores<T> & { error: Readable<string | null> }
1209
+ ```
1210
+
1211
+ **Returns:** Auth stores and actions
1212
+
1213
+ #### `createAuthStoresFromClient(client)`
1214
+
1215
+ Create auth stores from a specific auth client.
1216
+
1217
+ Use this when you don't want to use context.
1218
+
1219
+ ```typescript
1220
+ function createAuthStoresFromClient(client: AuthClient<T>): AuthStores<T>
1221
+ ```
1222
+
1223
+ - `client` — Auth client
1224
+
1225
+ **Returns:** Auth stores and actions
1226
+
1227
+ #### `createCapacitorAppStore(options)`
1228
+
1229
+ Create a Svelte store wrapping the Capacitor app coordinator.
1230
+
1231
+ Creates a CapacitorApp instance, subscribes to state changes,
1232
+ and auto-initializes. The returned store is readable and also
1233
+ exposes an `initialize` method for manual re-initialization.
1234
+
1235
+ ```typescript
1236
+ function createCapacitorAppStore(options?: CapacitorAppOptions): CapacitorAppStore
1237
+ ```
1238
+
1239
+ - `options` — Capacitor app options
1240
+
1241
+ **Returns:** A readable store of CapacitorAppState with an initialize method
1242
+
1243
+ #### `createChangePasswordStore()`
1244
+
1245
+ Creates a change password store with async state tracking.
1246
+
1247
+ ```typescript
1248
+ function createChangePasswordStore(): ChangePasswordStore
1249
+ ```
1250
+
1251
+ **Returns:** Change password promise store
1252
+
1253
+ #### `createDeleteStore(url, config)`
1254
+
1255
+ Creates a DELETE request store.
1256
+
1257
+ ```typescript
1258
+ function createDeleteStore(url: string, config?: RequestConfig): HttpStore<T>
1259
+ ```
1260
+
1261
+ - `url` — The request endpoint URL.
1262
+ - `config` — Optional request configuration such as headers or params.
1263
+
1264
+ **Returns:** A subscribable HTTP store for the DELETE request with execute and reset methods.
1265
+
1266
+ #### `createDeviceStores()`
1267
+
1268
+ Create device stores from the module-level device provider.
1269
+
1270
+ Device information is static (no reactive subscription needed),
1271
+ so this returns plain values rather than Svelte stores.
1272
+
1273
+ ```typescript
1274
+ function createDeviceStores(): {
1275
+ deviceInfo: DeviceInfo
1276
+ screenInfo: ScreenInfo
1277
+ hardwareInfo: HardwareInfo
1278
+ featureSupport: FeatureSupport
1279
+ supports: (feature: keyof FeatureSupport) => boolean
1280
+ isOnline: () => boolean
1281
+ isStandalone: () => boolean
1282
+ language: string
1283
+ languages: string[]
1284
+ }
1285
+ ```
1286
+
1287
+ **Returns:** Device information and utility functions
1288
+
1289
+ #### `createFieldStore(controller, name)`
1290
+
1291
+ Create a readable store that tracks a single field's state.
1292
+
1293
+ ```typescript
1294
+ function createFieldStore(controller: FormController<T>, name: K): Readable<FieldState<T[K]>>
1295
+ ```
1296
+
1297
+ - `controller` — Form controller
1298
+ - `name` — Field name to track
1299
+
1300
+ **Returns:** Readable store of the field state
1301
+
1302
+ #### `createFormStores(provider, options)`
1303
+
1304
+ Create form stores from a form provider and options.
1305
+
1306
+ ```typescript
1307
+ function createFormStores(provider: FormProvider, options: FormOptions<T>): FormStores<T>
1308
+ ```
1309
+
1310
+ - `provider` — Form provider instance
1311
+ - `options` — Form creation options
1312
+
1313
+ **Returns:** Form stores and actions
1314
+
1315
+ #### `createGetStore(url, config)`
1316
+
1317
+ Creates a GET request store.
1318
+
1319
+ ```typescript
1320
+ function createGetStore(url: string, config?: RequestConfig): HttpStore<T>
1321
+ ```
1322
+
1323
+ - `url` — The request endpoint URL.
1324
+ - `config` — Optional request configuration such as headers or params.
1325
+
1326
+ **Returns:** A subscribable HTTP store for the GET request with execute and reset methods.
1327
+
1328
+ #### `createHttpStore(method, url, config)`
1329
+
1330
+ Create an HTTP request store.
1331
+
1332
+ ```typescript
1333
+ function createHttpStore(
1334
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
1335
+ url: string,
1336
+ config?: RequestConfig,
1337
+ ): HttpStore<T>
1338
+ ```
1339
+
1340
+ - `method` — HTTP method
1341
+ - `url` — Request URL
1342
+ - `config` — Request configuration
1343
+
1344
+ **Returns:** Store with state and actions
1345
+
1346
+ #### `createHttpStoresFromClient(client)`
1347
+
1348
+ Creates HTTP store factory methods bound to a specific client instance.
1349
+
1350
+ ```typescript
1351
+ function createHttpStoresFromClient(client: HttpClient): HttpStoreFactory
1352
+ ```
1353
+
1354
+ - `client` — The HTTP client to use for all created stores.
1355
+
1356
+ **Returns:** An object with get, post, put, patch, and delete factory methods.
1357
+
1358
+ #### `createI18nStores()`
1359
+
1360
+ Create i18n stores from the i18n provider in context.
1361
+
1362
+ ```typescript
1363
+ function createI18nStores(): I18nStores
1364
+ ```
1365
+
1366
+ **Returns:** I18n stores and actions
1367
+
1368
+ #### `createI18nStoresFromProvider(provider)`
1369
+
1370
+ Create i18n stores from a specific provider.
1371
+
1372
+ ```typescript
1373
+ function createI18nStoresFromProvider(provider: I18nProvider): I18nStores
1374
+ ```
1375
+
1376
+ - `provider` — I18n provider
1377
+
1378
+ **Returns:** I18n stores and actions
1379
+
1380
+ #### `createIsActiveStore(location, router, path, exact)`
1381
+
1382
+ Create a derived store that checks if a path is active.
1383
+
1384
+ ```typescript
1385
+ function createIsActiveStore(
1386
+ location: Readable<RouteLocation>,
1387
+ router: Router,
1388
+ path: string,
1389
+ exact?: boolean,
1390
+ ): Readable<boolean>
1391
+ ```
1392
+
1393
+ - `location` — A readable location store (from createRouterStores or createRouterStoresFromRouter)
1394
+ - `router` — Router instance (for isActive check)
1395
+ - `path` — Path to check
1396
+ - `exact` — Whether to require exact match (default: false)
1397
+
1398
+ **Returns:** Readable store of whether the path is active
1399
+
1400
+ #### `createLogger(config)`
1401
+
1402
+ Create a logger with custom configuration.
1403
+
1404
+ ```typescript
1405
+ function createLogger(config: LoggerConfig): Logger
1406
+ ```
1407
+
1408
+ - `config` — Logger configuration
1409
+
1410
+ **Returns:** Logger instance
1411
+
1412
+ #### `createLoggerHelpers()`
1413
+
1414
+ Create logger helpers from context.
1415
+
1416
+ ```typescript
1417
+ function createLoggerHelpers(): LoggerHelpers
1418
+ ```
1419
+
1420
+ **Returns:** Logger helper functions
1421
+
1422
+ #### `createLoggerHelpersFromProvider(provider)`
1423
+
1424
+ Create logger helpers from a specific provider.
1425
+
1426
+ ```typescript
1427
+ function createLoggerHelpersFromProvider(provider: LoggerProvider): LoggerHelpers
1428
+ ```
1429
+
1430
+ - `provider` — Logger provider
1431
+
1432
+ **Returns:** Logger helper functions
1433
+
1434
+ #### `createLoginStore()`
1435
+
1436
+ Creates a login store with async state tracking.
1437
+
1438
+ ```typescript
1439
+ function createLoginStore(): LoginStore<T>
1440
+ ```
1441
+
1442
+ **Returns:** Login promise store
1443
+
1444
+ #### `createOAuthHelpers(options)`
1445
+
1446
+ Creates OAuth helpers for provider-based authentication flows.
1447
+
1448
+ When created in a browser, automatically handles OAuth callbacks by
1449
+ detecting `code` and `state` URL parameters and exchanging them for a
1450
+ session (a guarded no-op when there is no callback code in the URL).
1451
+
1452
+ Session establishment: the exchange result is applied to the resolved auth
1453
+ client (an explicit `options.authClient`, else the Svelte-context client
1454
+ when created during component initialization). When NO client is available,
1455
+ the server has already established the httpOnly-cookie session via the
1456
+ exchange, so a user-carrying response still counts as success —
1457
+ `options.onSuccess` fires; a response with no user fires `options.onError`.
1458
+
1459
+ ```typescript
1460
+ function createOAuthHelpers(options?: OAuthOptions): OAuthHelpers
1461
+ ```
1462
+
1463
+ - `options` — OAuth configuration (base URL, providers, endpoint paths, callbacks, auth client).
1464
+
1465
+ **Returns:** An object containing a readable providers store, URL builder, redirect function, and callback handler.
1466
+
1467
+ #### `createPasswordResetStores()`
1468
+
1469
+ Creates password reset stores with async state tracking.
1470
+
1471
+ ```typescript
1472
+ function createPasswordResetStores(): PasswordResetStores
1473
+ ```
1474
+
1475
+ **Returns:** Password reset stores for request and confirm steps
1476
+
1477
+ #### `createPatchStore(url, config)`
1478
+
1479
+ Creates a PATCH request store.
1480
+
1481
+ ```typescript
1482
+ function createPatchStore(url: string, config?: RequestConfig): HttpStore<T>
1483
+ ```
1484
+
1485
+ - `url` — The request endpoint URL.
1486
+ - `config` — Optional request configuration such as headers or body data.
1487
+
1488
+ **Returns:** A subscribable HTTP store for the PATCH request with execute and reset methods.
1489
+
1490
+ #### `createPlatformStores()`
1491
+
1492
+ Create platform stores from the module-level platform info.
1493
+
1494
+ Platform information is static (no reactive subscription needed),
1495
+ so this returns plain values rather than Svelte stores.
1496
+
1497
+ ```typescript
1498
+ function createPlatformStores(): {
1499
+ platform: Platform
1500
+ isNative: boolean
1501
+ isMobile: boolean
1502
+ isDesktop: boolean
1503
+ isWeb: boolean
1504
+ isDevelopment: boolean
1505
+ isProduction: boolean
1506
+ isPlatform: (...platforms: Platform[]) => boolean
1507
+ }
1508
+ ```
1509
+
1510
+ **Returns:** Platform information and utility functions
1511
+
1512
+ #### `createPostStore(url, config)`
1513
+
1514
+ Creates a POST request store.
1515
+
1516
+ ```typescript
1517
+ function createPostStore(url: string, config?: RequestConfig): HttpStore<T>
1518
+ ```
1519
+
1520
+ - `url` — The request endpoint URL.
1521
+ - `config` — Optional request configuration such as headers or body data.
1522
+
1523
+ **Returns:** A subscribable HTTP store for the POST request with execute and reset methods.
1524
+
1525
+ #### `createPromiseStore(asyncFn)`
1526
+
1527
+ Creates a store that tracks async function state.
1528
+
1529
+ ```typescript
1530
+ function createPromiseStore(asyncFn: T): PromiseStore<Awaited<ReturnType<T>>>
1531
+ ```
1532
+
1533
+ - `asyncFn` — The async function to track
1534
+
1535
+ **Returns:** Promise store with subscribe, call, cancel, and reset
1536
+
1537
+ #### `createPushStores()`
1538
+
1539
+ Create push notification stores from the module-level push provider.
1540
+
1541
+ ```typescript
1542
+ function createPushStores(): {
1543
+ permission: Readable<PermissionStatus | null>
1544
+ token: Readable<PushToken | null>
1545
+ checkPermission: () => Promise<PermissionStatus>
1546
+ requestPermission: () => Promise<PermissionStatus>
1547
+ register: (options?: PushRegisterOptions) => Promise<PushToken>
1548
+ unregister: () => Promise<void>
1549
+ onNotificationReceived: (listener: NotificationReceivedListener) => () => void
1550
+ onNotificationAction: (listener: NotificationActionListener) => () => void
1551
+ onTokenChange: (listener: TokenChangeListener) => () => void
1552
+ setBadge: (count: number) => Promise<void>
1553
+ clearBadge: () => Promise<void>
1554
+ }
1555
+ ```
1556
+
1557
+ **Returns:** Push notification stores and actions
1558
+
1559
+ #### `createPutStore(url, config)`
1560
+
1561
+ Creates a PUT request store.
1562
+
1563
+ ```typescript
1564
+ function createPutStore(url: string, config?: RequestConfig): HttpStore<T>
1565
+ ```
1566
+
1567
+ - `url` — The request endpoint URL.
1568
+ - `config` — Optional request configuration such as headers or body data.
1569
+
1570
+ **Returns:** A subscribable HTTP store for the PUT request with execute and reset methods.
1571
+
1572
+ #### `createRouterStores()`
1573
+
1574
+ Create router stores from the router in context.
1575
+
1576
+ ```typescript
1577
+ function createRouterStores(): RouterStores
1578
+ ```
1579
+
1580
+ **Returns:** Router stores and actions
1581
+
1582
+ #### `createRouterStoresFromRouter(router)`
1583
+
1584
+ Create router stores from a specific router.
1585
+
1586
+ ```typescript
1587
+ function createRouterStoresFromRouter(router: Router): RouterStores
1588
+ ```
1589
+
1590
+ - `router` — Router instance
1591
+
1592
+ **Returns:** Router stores and actions
1593
+
1594
+ #### `createSignupStore()`
1595
+
1596
+ Creates a signup store with async state tracking.
1597
+
1598
+ ```typescript
1599
+ function createSignupStore(): SignupStore<T>
1600
+ ```
1601
+
1602
+ **Returns:** Signup promise store
1603
+
1604
+ #### `createStorageHelpers()`
1605
+
1606
+ Create storage helper functions from context.
1607
+
1608
+ ```typescript
1609
+ function createStorageHelpers(): StorageHelpers
1610
+ ```
1611
+
1612
+ **Returns:** Storage functions
1613
+
1614
+ #### `createStorageStore(key, defaultValue)`
1615
+
1616
+ Create a storage value store.
1617
+
1618
+ ```typescript
1619
+ function createStorageStore(key: string, defaultValue?: T): StorageStore<T>
1620
+ ```
1621
+
1622
+ - `key` — Storage key
1623
+ - `defaultValue` — Default value if not found
1624
+
1625
+ **Returns:** Store with value and actions
1626
+
1627
+ #### `createStorageStoreFromProvider(storage, key, defaultValue)`
1628
+
1629
+ Create storage store from a specific provider.
1630
+
1631
+ ```typescript
1632
+ function createStorageStoreFromProvider(
1633
+ storage: StorageProvider,
1634
+ key: string,
1635
+ defaultValue?: T,
1636
+ ): StorageStore<T>
1637
+ ```
1638
+
1639
+ - `storage` — Storage provider
1640
+ - `key` — Storage key
1641
+ - `defaultValue` — Default value
1642
+
1643
+ **Returns:** Store with value and actions
1644
+
1645
+ #### `createStoreAction(store, action)`
1646
+
1647
+ Create a bound action for a store.
1648
+
1649
+ ```typescript
1650
+ function createStoreAction(
1651
+ store: MoleculeStore<T>,
1652
+ action: (
1653
+ setState: MoleculeStore<T>['setState'],
1654
+ getState: MoleculeStore<T>['getState'],
1655
+ ) => (...args: Args) => R,
1656
+ ): (...args: Args) => R
1657
+ ```
1658
+
1659
+ - `store` — The store
1660
+ - `action` — Action creator function
1661
+
1662
+ **Returns:** Bound action
1663
+
1664
+ #### `createStoreReadable(store)`
1665
+
1666
+ Create a readable Svelte store from a molecule store.
1667
+
1668
+ ```typescript
1669
+ function createStoreReadable(store: MoleculeStore<T>): Readable<T>
1670
+ ```
1671
+
1672
+ - `store` — The molecule store
1673
+
1674
+ **Returns:** Readable Svelte store
1675
+
1676
+ #### `createStoreSelector(store, selector)`
1677
+
1678
+ Create a derived Svelte store with a selector.
1679
+
1680
+ ```typescript
1681
+ function createStoreSelector(store: MoleculeStore<T>, selector: (state: T) => S): Readable<S>
1682
+ ```
1683
+
1684
+ - `store` — The molecule store
1685
+ - `selector` — Selector function
1686
+
1687
+ **Returns:** Derived Svelte store
1688
+
1689
+ #### `createThemeColorsStore(theme)`
1690
+
1691
+ Create a derived store that returns just the theme colors.
1692
+
1693
+ ```typescript
1694
+ function createThemeColorsStore(theme: Readable<Theme>): Readable<ThemeColors>
1695
+ ```
1696
+
1697
+ - `theme` — A readable theme store (from createThemeStores or createThemeStoresFromProvider)
1698
+
1699
+ **Returns:** Readable store of theme colors
1700
+
1701
+ #### `createThemeStores()`
1702
+
1703
+ Create theme stores from the theme provider in context.
1704
+
1705
+ ```typescript
1706
+ function createThemeStores(): ThemeStores & { colors: Readable<Theme['colors']> }
1707
+ ```
1708
+
1709
+ **Returns:** Theme stores and actions
1710
+
1711
+ #### `createThemeStoresFromProvider(provider)`
1712
+
1713
+ Create theme stores from a specific theme provider.
1714
+
1715
+ ```typescript
1716
+ function createThemeStoresFromProvider(provider: ThemeProvider): ThemeStores
1717
+ ```
1718
+
1719
+ - `provider` — Theme provider
1720
+
1721
+ **Returns:** Theme stores and actions
1722
+
1723
+ #### `createVersionStores()`
1724
+
1725
+ Create version stores from the module-level version provider.
1726
+
1727
+ ```typescript
1728
+ function createVersionStores(): {
1729
+ state: Readable<VersionState>
1730
+ isUpdateAvailable: Readable<boolean>
1731
+ isChecking: Readable<boolean>
1732
+ isServiceWorkerWaiting: Readable<boolean>
1733
+ newVersion: Readable<string | undefined>
1734
+ checkForUpdates: () => Promise<boolean>
1735
+ applyUpdate: (options?: { force?: boolean }) => void
1736
+ dismissUpdate: () => void
1737
+ startPeriodicChecks: (options?: UpdateCheckOptions) => void
1738
+ stopPeriodicChecks: () => void
1739
+ }
1740
+ ```
1741
+
1742
+ **Returns:** Version stores and actions
1743
+
1744
+ #### `createWatchStore(controller, name)`
1745
+
1746
+ Create a readable store that tracks a single field's value.
1747
+
1748
+ ```typescript
1749
+ function createWatchStore(controller: FormController<T>, name: K): Readable<T[K]>
1750
+ ```
1751
+
1752
+ - `controller` — Form controller
1753
+ - `name` — Field name to watch
1754
+
1755
+ **Returns:** Readable store of the field value
1756
+
1757
+ #### `getAuthClient()`
1758
+
1759
+ Gets the auth client from Svelte context.
1760
+
1761
+ ```typescript
1762
+ function getAuthClient(): AuthClient<T>
1763
+ ```
1764
+
1765
+ **Returns:** The auth client instance.
1766
+
1767
+ #### `getChildLogger(name, context)`
1768
+
1769
+ Create a child logger with additional context.
1770
+
1771
+ ```typescript
1772
+ function getChildLogger(name: string, context: Record<string, unknown>): Logger
1773
+ ```
1774
+
1775
+ - `name` — Parent logger name
1776
+ - `context` — Additional context
1777
+
1778
+ **Returns:** Child logger instance
1779
+
1780
+ #### `getHttpClient()`
1781
+
1782
+ Gets the HTTP client from Svelte context.
1783
+
1784
+ ```typescript
1785
+ function getHttpClient(): HttpClient
1786
+ ```
1787
+
1788
+ **Returns:** The HTTP client instance.
1789
+
1790
+ #### `getI18nProvider()`
1791
+
1792
+ Gets the i18n provider from Svelte context.
1793
+
1794
+ ```typescript
1795
+ function getI18nProvider(): I18nProvider
1796
+ ```
1797
+
1798
+ **Returns:** The i18n provider instance.
1799
+
1800
+ #### `getLogger(name)`
1801
+
1802
+ Get a logger instance.
1803
+
1804
+ ```typescript
1805
+ function getLogger(name?: string): Logger
1806
+ ```
1807
+
1808
+ - `name` — Logger name
1809
+
1810
+ **Returns:** Logger instance
1811
+
1812
+ #### `getLoggerProvider()`
1813
+
1814
+ Gets the logger provider from Svelte context.
1815
+
1816
+ ```typescript
1817
+ function getLoggerProvider(): LoggerProvider
1818
+ ```
1819
+
1820
+ **Returns:** The logger provider instance.
1821
+
1822
+ #### `getRootLogger()`
1823
+
1824
+ Get the root logger.
1825
+
1826
+ ```typescript
1827
+ function getRootLogger(): Logger
1828
+ ```
1829
+
1830
+ **Returns:** Root logger instance
1831
+
1832
+ #### `getRouter()`
1833
+
1834
+ Gets the router from Svelte context.
1835
+
1836
+ ```typescript
1837
+ function getRouter(): Router
1838
+ ```
1839
+
1840
+ **Returns:** The router instance.
1841
+
1842
+ #### `getSetStore(store)`
1843
+
1844
+ Get the setState function from a molecule store.
1845
+
1846
+ ```typescript
1847
+ function getSetStore(
1848
+ store: MoleculeStore<T>,
1849
+ ): (partial: Partial<T> | ((state: T) => Partial<T>)) => void
1850
+ ```
1851
+
1852
+ - `store` — The molecule store
1853
+
1854
+ **Returns:** setState function
1855
+
1856
+ #### `getStateProvider()`
1857
+
1858
+ Gets the state provider from Svelte context.
1859
+
1860
+ ```typescript
1861
+ function getStateProvider(): StateProvider
1862
+ ```
1863
+
1864
+ **Returns:** The state provider instance.
1865
+
1866
+ #### `getStorageProvider()`
1867
+
1868
+ Gets the storage provider from Svelte context.
1869
+
1870
+ ```typescript
1871
+ function getStorageProvider(): StorageProvider
1872
+ ```
1873
+
1874
+ **Returns:** The storage provider instance.
1875
+
1876
+ #### `getThemeProvider()`
1877
+
1878
+ Gets the theme provider from Svelte context.
1879
+
1880
+ ```typescript
1881
+ function getThemeProvider(): ThemeProvider
1882
+ ```
1883
+
1884
+ **Returns:** The theme provider instance.
1885
+
1886
+ #### `setAuthContext(client)`
1887
+
1888
+ Sets the auth context.
1889
+
1890
+ ```typescript
1891
+ function setAuthContext(client: AuthClient<T>): void
1892
+ ```
1893
+
1894
+ - `client` — The auth client to store in Svelte context.
1895
+
1896
+ #### `setHttpContext(client)`
1897
+
1898
+ Sets the HTTP context.
1899
+
1900
+ ```typescript
1901
+ function setHttpContext(client: HttpClient): void
1902
+ ```
1903
+
1904
+ - `client` — The HTTP client to store in Svelte context.
1905
+
1906
+ #### `setI18nContext(provider)`
1907
+
1908
+ Sets the i18n context.
1909
+
1910
+ ```typescript
1911
+ function setI18nContext(provider: I18nProvider): void
1912
+ ```
1913
+
1914
+ - `provider` — The i18n provider to store in Svelte context.
1915
+
1916
+ #### `setLoggerContext(provider)`
1917
+
1918
+ Sets the logger context.
1919
+
1920
+ ```typescript
1921
+ function setLoggerContext(provider: LoggerProvider): void
1922
+ ```
1923
+
1924
+ - `provider` — The logger provider to store in Svelte context.
1925
+
1926
+ #### `setMoleculeContext(config)`
1927
+
1928
+ Set all molecule providers in Svelte context.
1929
+
1930
+ Call this in your root layout/component.
1931
+
1932
+ ```typescript
1933
+ function setMoleculeContext(config: MoleculeConfig): void
1934
+ ```
1935
+
1936
+ - `config` — Provider instances to register (state, auth, theme, router, i18n, http, storage, logger).
1937
+
1938
+ #### `setRouterContext(router)`
1939
+
1940
+ Sets the router context.
1941
+
1942
+ ```typescript
1943
+ function setRouterContext(router: Router): void
1944
+ ```
1945
+
1946
+ - `router` — The router instance to store in Svelte context.
1947
+
1948
+ #### `setStateContext(provider)`
1949
+
1950
+ Sets the state context.
1951
+
1952
+ ```typescript
1953
+ function setStateContext(provider: StateProvider): void
1954
+ ```
1955
+
1956
+ - `provider` — The state provider to store in Svelte context.
1957
+
1958
+ #### `setStorageContext(provider)`
1959
+
1960
+ Sets the storage context.
1961
+
1962
+ ```typescript
1963
+ function setStorageContext(provider: StorageProvider): void
1964
+ ```
1965
+
1966
+ - `provider` — The storage provider to store in Svelte context.
1967
+
1968
+ #### `setThemeContext(provider)`
1969
+
1970
+ Sets the theme context.
1971
+
1972
+ ```typescript
1973
+ function setThemeContext(provider: ThemeProvider): void
1974
+ ```
1975
+
1976
+ - `provider` — The theme provider to store in Svelte context.
1977
+
1978
+ ## Injection Notes
1979
+
1980
+ ### Requirements
1981
+
1982
+ Peer dependencies:
1983
+
1984
+ - `@molecule/app-auth` ^1.0.0
1985
+ - `@molecule/app-device` ^1.0.0
1986
+ - `@molecule/app-forms` ^1.0.0
1987
+ - `@molecule/app-http` ^1.0.0
1988
+ - `@molecule/app-i18n` ^1.0.0
1989
+ - `@molecule/app-logger` ^1.0.0
1990
+ - `@molecule/app-platform` ^1.0.0
1991
+ - `@molecule/app-push` ^1.0.0
1992
+ - `@molecule/app-routing` ^1.0.0
1993
+ - `@molecule/app-state` ^1.0.0
1994
+ - `@molecule/app-storage` ^1.0.0
1995
+ - `@molecule/app-theme` ^1.0.0
1996
+ - `@molecule/app-ui` ^1.0.0
1997
+ - `@molecule/app-utilities` ^1.0.0
1998
+ - `@molecule/app-version` ^1.0.0
1999
+ - `svelte` ^4.0.0 || ^5.0.0
2000
+
2001
+ ### Runtime Dependencies
2002
+
2003
+ - `@molecule/app-auth`
2004
+ - `@molecule/app-device`
2005
+ - `@molecule/app-forms`
2006
+ - `@molecule/app-http`
2007
+ - `@molecule/app-i18n`
2008
+ - `@molecule/app-logger`
2009
+ - `@molecule/app-platform`
2010
+ - `@molecule/app-push`
2011
+ - `@molecule/app-routing`
2012
+ - `@molecule/app-state`
2013
+ - `@molecule/app-storage`
2014
+ - `@molecule/app-theme`
2015
+ - `@molecule/app-ui`
2016
+ - `@molecule/app-utilities`
2017
+ - `@molecule/app-version`
2018
+ - `svelte`
2019
+
2020
+ - **`setMoleculeContext` and every `create*Stores` factory use Svelte context — they are only
2021
+ legal during component initialization** (the top level of a component `<script>`), never in
2022
+ module scope, after `onMount`, in event handlers, or in async callbacks. Wire the context in
2023
+ the ROOT layout so every route inherits it.
2024
+ - **Factories throw per missing service**: the context carries ONLY the services you passed —
2025
+ `createAuthStores()` under a context without `auth` throws. Fix the `setMoleculeContext`
2026
+ config; don't wrap in try/catch.
2027
+ - Results are Svelte stores — read them with the `$` prefix (`$isAuthenticated`, `$theme`);
2028
+ actions (`logout`, `toggleTheme`, `setTheme`) are plain functions.
2029
+
2030
+ ## Translations
2031
+
2032
+ Translation strings are provided by `@molecule/app-locales-svelte`.