@molecule/app-bonds-default 0.0.0-stage → 1.2.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 (42) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +478 -2
  3. package/dist/auth.d.ts +156 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +258 -0
  6. package/dist/index.d.ts +116 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +115 -0
  9. package/dist/optional/charts-chartjs.d.ts +15 -0
  10. package/dist/optional/charts-chartjs.d.ts.map +1 -0
  11. package/dist/optional/charts-chartjs.js +20 -0
  12. package/dist/optional/client-search-minisearch.d.ts +12 -0
  13. package/dist/optional/client-search-minisearch.d.ts.map +1 -0
  14. package/dist/optional/client-search-minisearch.js +17 -0
  15. package/dist/optional/code-editor-monaco.d.ts +12 -0
  16. package/dist/optional/code-editor-monaco.d.ts.map +1 -0
  17. package/dist/optional/code-editor-monaco.js +17 -0
  18. package/dist/optional/command-palette-cmdk.d.ts +12 -0
  19. package/dist/optional/command-palette-cmdk.d.ts.map +1 -0
  20. package/dist/optional/command-palette-cmdk.js +17 -0
  21. package/dist/optional/drag-drop-dndkit.d.ts +12 -0
  22. package/dist/optional/drag-drop-dndkit.d.ts.map +1 -0
  23. package/dist/optional/drag-drop-dndkit.js +17 -0
  24. package/dist/optional/keyboard-shortcuts-hotkeys.d.ts +12 -0
  25. package/dist/optional/keyboard-shortcuts-hotkeys.d.ts.map +1 -0
  26. package/dist/optional/keyboard-shortcuts-hotkeys.js +17 -0
  27. package/dist/optional/maps-leaflet.d.ts +19 -0
  28. package/dist/optional/maps-leaflet.d.ts.map +1 -0
  29. package/dist/optional/maps-leaflet.js +24 -0
  30. package/dist/optional/realtime-socketio.d.ts +24 -0
  31. package/dist/optional/realtime-socketio.d.ts.map +1 -0
  32. package/dist/optional/realtime-socketio.js +29 -0
  33. package/dist/optional/video-hls.d.ts +12 -0
  34. package/dist/optional/video-hls.d.ts.map +1 -0
  35. package/dist/optional/video-hls.js +17 -0
  36. package/dist/optional/virtual-scroll-tanstack.d.ts +12 -0
  37. package/dist/optional/virtual-scroll-tanstack.d.ts.map +1 -0
  38. package/dist/optional/virtual-scroll-tanstack.js +17 -0
  39. package/dist/setup.d.ts +65 -0
  40. package/dist/setup.d.ts.map +1 -0
  41. package/dist/setup.js +113 -0
  42. package/package.json +178 -4
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,479 @@
1
- # Temporary Holding Version
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-11-16T05:58:33.777Z
7
+ -->
2
8
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
9
+ # @molecule/app-bonds-default
10
+
11
+ `@molecule/app-bonds-default` — the framework-neutral half of the default
12
+ app-side bond wirings, shared unchanged by the per-framework packages
13
+ (`@molecule/app-bonds-default-react`, `-vue`, `-solid`, `-svelte`,
14
+ `-angular`), which re-export everything here and add their routing setup,
15
+ `setupAllDefaultBonds()` and `bootstrapApp()`. Switching framework means
16
+ changing the package name in the imports — every export below keeps its name.
17
+
18
+ - The eight universal neutral setups — `setupAppStateSimple` (the vanilla
19
+ `simpleProvider`, so `createStore()` works from the first render — the
20
+ documented `createStore()` + `useStore()` pattern needs a provider bonded
21
+ and nothing else in a scaffold wires one), `setupAppFontsArimo`,
22
+ `setupAppStorageLocalstorage`, `setupAppStylingTailwind` (registers the
23
+ tailwind-merge class merger), `setupAppThemeCssVariables` (light + dark via
24
+ `getDefaultThemeProvider()`), `setupAppUiTailwind` ClassMap,
25
+ `setupAppIconsMolecule`, `setupAppClipboardWeb` (the browser Clipboard API
26
+ with a selection-and-copy fallback, so `copyTextWithFallback()` and
27
+ `writeText()` from `@molecule/app-clipboard` work wherever a copy can).
28
+ Routing is framework-specific and lives in the
29
+ per-framework packages.
30
+ - **Optional provider wirings live behind subpaths**, one module per pair:
31
+ `@molecule/app-bonds-default/optional/<pair>.js` — `realtime-socketio`,
32
+ `keyboard-shortcuts-hotkeys`, `command-palette-cmdk`, `client-search-minisearch`, `code-editor-monaco`,
33
+ `virtual-scroll-tanstack`, `drag-drop-dndkit`, `charts-chartjs`,
34
+ `maps-leaflet`, `video-hls`. Import ONLY the ones the app installs.
35
+ - Auth/http factories — `createDefaultAuthClient(authConfig)` returns
36
+ `{ authClient, setupAuthDefault }`; the `...WithHttpSync` /
37
+ `...WithFetchClient` variants also keep the bonded http client's bearer
38
+ token in sync with auth events. All three accept any JSON object profile
39
+ (`createDefaultAuthClient<SessionUser>(config)` for an API whose user has no
40
+ `id`) and fall back to `UserProfile` — with its `id: string` — when no type
41
+ argument is given. The profile is never inferred from `authConfig`, so an
42
+ untyped call keeps the default contract.
43
+
44
+ **What this client already handles**
45
+
46
+ - `getAccessToken()` returns a stored token during restore; only 401/403 ends
47
+ the session, while network/5xx failures retain it.
48
+ - `tokenKey`/`storagePrefix`, `authScheme`, `mapAuthResponse`,
49
+ `currentUserEndpoint`, and `profileEndpoint`/`profileUpdateMethod` adapt the API.
50
+ - `logout()` settles local sign-out; `refresh()` uses a stored refresh token.
51
+
52
+ This factory adds no render gate: `AuthProvider` renders children immediately.
53
+ The HTTP-sync variants gate requests during restore, not rendering.
54
+
55
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
56
+ > It is written to be read by coding agents as much as by people, and is generated from this
57
+ > package's source — edit `src/index.ts` JSDoc, not this file.
58
+
59
+ ## Quick Start
60
+
61
+ ```ts
62
+ // bonds/index.ts — any framework
63
+ import { createDefaultAuthClientWithHttpSync } from '@molecule/app-bonds-default'
64
+ // Optional providers come from their own subpath — see @remarks.
65
+ import { setupAppCodeEditorMonaco } from '@molecule/app-bonds-default/optional/code-editor-monaco.js'
66
+ import { authConfig } from '../config.js'
67
+
68
+ export const { authClient, setupAuthDefault } = createDefaultAuthClientWithHttpSync(authConfig)
69
+
70
+ // Async so optional async bonds are AWAITED before the first render.
71
+ export const setupProviders = async () => {
72
+ setupAllDefaultBonds() // from @molecule/app-bonds-default-<framework>
73
+ setupAuthDefault()
74
+ await setupAppCodeEditorMonaco() // only if the app uses the code editor
75
+ }
76
+ ```
77
+
78
+ Adapt a nested token and `Token` header without another session store.
79
+
80
+ ```ts
81
+ import { createDefaultAuthClient } from '@molecule/app-bonds-default'
82
+
83
+ const { authClient, setupAuthDefault } = createDefaultAuthClient({
84
+ tokenKey: 'app.jwt',
85
+ authScheme: 'Token',
86
+ currentUserEndpoint: '/user',
87
+ profileEndpoint: '/user',
88
+ profileUpdateMethod: 'PUT',
89
+ mapAuthResponse: (data) => {
90
+ const { token, ...user } = (data as { user: { token: string; id: string } }).user
91
+ return { accessToken: token, user }
92
+ },
93
+ })
94
+ ```
95
+
96
+ ## Type
97
+
98
+ `feature`
99
+
100
+ ## Installation
101
+
102
+ ```bash
103
+ npm install @molecule/app-bonds-default @molecule/app-auth @molecule/app-charts @molecule/app-charts-chartjs @molecule/app-client-search @molecule/app-client-search-minisearch @molecule/app-clipboard @molecule/app-clipboard-web @molecule/app-code-editor @molecule/app-code-editor-monaco @molecule/app-command-palette @molecule/app-command-palette-cmdk @molecule/app-drag-drop @molecule/app-drag-drop-dndkit @molecule/app-fonts @molecule/app-fonts-arimo @molecule/app-http @molecule/app-icons @molecule/app-icons-molecule @molecule/app-keyboard-shortcuts @molecule/app-keyboard-shortcuts-hotkeys @molecule/app-maps @molecule/app-maps-leaflet @molecule/app-realtime @molecule/app-realtime-socketio @molecule/app-routing @molecule/app-state @molecule/app-storage @molecule/app-storage-localstorage @molecule/app-styling-tailwind @molecule/app-theme @molecule/app-theme-css-variables @molecule/app-ui @molecule/app-ui-tailwind @molecule/app-video @molecule/app-video-hls @molecule/app-virtual-scroll @molecule/app-virtual-scroll-tanstack
104
+ ```
105
+
106
+ ## API
107
+
108
+ ### Functions
109
+
110
+ #### `createDefaultHttpClient(baseURL)`
111
+
112
+ Builds the default fetch-based HTTP client + wires it into
113
+ `@molecule/app-http`. Replaces the per-app `bonds/http-default.ts`
114
+ shipped by ~52 fleet apps.
115
+
116
+ ```typescript
117
+ function createDefaultHttpClient(baseURL: string): {
118
+ httpClient: HttpClient
119
+ setupHttpDefault: () => void
120
+ }
121
+ ```
122
+
123
+ #### `createDefaultHttpClientWithAuthBearer(opts)`
124
+
125
+ Variant of `createDefaultHttpClient` that adds a request interceptor
126
+ injecting the JWT bearer token from the auth client AND (optionally)
127
+ stripping a leading `/api/` from request URLs.
128
+
129
+ Replaces ~20 per-app `bonds/http-default.ts` files that hand-roll
130
+ this same wiring. Pass `stripApiPrefix: true` when the app uses
131
+ `baseURL: '/api'` to handle pages that pass `/api/`-prefixed paths
132
+ (would otherwise resolve to `/api/api/...` and 404). Pass `authScheme`
133
+ when the API reads another scheme than `Bearer`: it is an option of THIS
134
+ constructor (`createDefaultHttpClientWithAuthBearer({ authScheme: 'Token', … })`,
135
+ or `createFetchClient({ baseURL, authScheme: 'Token' })` directly), never a
136
+ property of the client it returns. The client is built with the same scheme, so
137
+ a token the client also holds — the one a default auth bond's token sync gives
138
+ it — is sent with that scheme too, not as `Bearer`.
139
+
140
+ ```typescript
141
+ function createDefaultHttpClientWithAuthBearer(opts: {
142
+ baseURL: string
143
+ withCredentials?: boolean
144
+ stripApiPrefix?: boolean
145
+ getToken: () => string | null | undefined
146
+ /**
147
+ * The scheme of the `Authorization` header the token from `getToken()` is sent
148
+ * with: `Bearer` (default), or what the API expects, e.g. `Token` for an API
149
+ * that reads `Authorization: Token <jwt>`. Pass it to this constructor — the
150
+ * same option `@molecule/app-http`'s client config calls `authScheme`, and not
151
+ * a property of the client that comes back.
152
+ */
153
+ authScheme?: string
154
+ }): {
155
+ httpClient: HttpClient
156
+ setupHttpDefault: () => void
157
+ }
158
+ ```
159
+
160
+ #### `createDefaultAuthClient(authConfig)`
161
+
162
+ Builds the default JWT auth client + wires it into `@molecule/app-auth`.
163
+ Apps pass their own `authConfig` (which lives in `src/config.ts`).
164
+
165
+ `TUser` is the profile the app's pages read, and may be any JSON object type —
166
+ including a profile with NO `id` (`{ username, email, bio, image }`), as in the
167
+ factory it wraps. Never add a synthetic `id` to satisfy a type: nothing in the
168
+ client reads it, and the fabricated value then travels into storage, `getUser()`
169
+ and every page. Omit the type parameter and the default is `UserProfile`, whose
170
+ `id: string` stays required — the profile is never inferred from `authConfig`
171
+ (not even from an annotated config variable), so an untyped wrapper call keeps
172
+ the default contract.
173
+
174
+ Type the config with the SAME type (`const authConfig: AuthClientConfig<MyUser> = { … }`)
175
+ so its `mapAuthResponse` is checked against `MyUser`, and name that type at the
176
+ call (`createDefaultAuthClient<MyUser>(authConfig)`): a mapper that omits a
177
+ required custom field then fails at that call instead of shipping a signed-in
178
+ page that reads `undefined`. An annotated config alone does not supply the type
179
+ argument — that is a 1.8 caller shape this major changes (see
180
+ `AuthClientConfig`'s migration note in `@molecule/app-auth`).
181
+
182
+ `TRegister` is the app's own extra registration fields (for example
183
+ `{ username: string }`), passed on to `@molecule/app-auth`'s factory so
184
+ `authClient.register({ username, email, password })` type-checks with no cast.
185
+ See the module guidance for the lifecycle and API adaptations already included.
186
+
187
+ ```typescript
188
+ function createDefaultAuthClient<
189
+ TUser extends AuthProfileConstraint<TUser> = UserProfile,
190
+ TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
191
+ >(
192
+ authConfig: NoInfer<AuthClientConfigOptions<TUser>>,
193
+ ): {
194
+ authClient: AuthClient<TUser, TRegister>
195
+ setupAuthDefault: () => void
196
+ }
197
+ ```
198
+
199
+ #### `createDefaultAuthClientWithHttpSync(authConfig)`
200
+
201
+ Variant of `createDefaultAuthClient` that also keeps the bonded
202
+ `@molecule/app-http` client's bearer token in sync with the auth client's session.
203
+ Required by apps whose http client must carry the JWT on every request — without
204
+ this wiring, authed endpoints return 401 after page reloads or token refresh.
205
+
206
+ The sync is a LIVE read: `@molecule/app-http`'s `setAuthTokenSource` registers the auth
207
+ client's token, and every client the app bonds, before or after this setup, reads it on
208
+ each request — so the order of the `setup*()` calls in `bonds/index.ts` does not matter
209
+ and never needs changing for auth. A session adopted with no
210
+ auth event (`useAuth().setSession()`, an OAuth callback's `setAccessToken()`, the same
211
+ profile under a new token) is therefore sent by the next request, not the previous
212
+ account's bearer. A transport without `setAuthTokenResolver` is followed through a request
213
+ interceptor (see `setAuthTokenSource` for which request first carries the change), and
214
+ auth events still push the token to it.
215
+
216
+ A cookie session (no body token) resolves to `null`, so the request carries NO
217
+ `Authorization` header — a kept bearer would answer as the PRIOR session.
218
+ Requests also wait for the session restore, so a page that fetches viewer data on mount
219
+ cannot race it (see {@link registerAuthGate}).
220
+
221
+ The profile type is `createDefaultAuthClient`'s: a JSON object type of named
222
+ fields (see `AuthProfileShape`), including an app profile with no `id`.
223
+
224
+ ```typescript
225
+ function createDefaultAuthClientWithHttpSync<
226
+ TUser extends AuthProfileConstraint<TUser> = UserProfile,
227
+ TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
228
+ >(
229
+ authConfig: NoInfer<AuthClientConfigOptions<TUser>>,
230
+ ): {
231
+ authClient: AuthClient<TUser, TRegister>
232
+ setupAuthDefault: () => void
233
+ }
234
+ ```
235
+
236
+ #### `createDefaultAuthClientWithFetchClient(authConfig, fetchClientOptions)`
237
+
238
+ Most aggressive variant — bonds a fetch-based HTTP client with the
239
+ given `baseURL` (so molecule pkg `useGet('/path')` calls hit
240
+ `${baseURL}/path` instead of the SPA's catch-all route), AND keeps
241
+ its bearer token in sync with the auth client's session, read on every
242
+ request: a session adopted with no auth event (`setSession()`,
243
+ `setAccessToken()`) is sent by the next request. The token uses the auth
244
+ config's `authScheme` (default `Bearer`); a client bonded after this setup
245
+ gets the same source and auth events.
246
+
247
+ The auth client restores a stored token AND user SYNCHRONOUSLY, so the first
248
+ render is the signed-in UI — do not gate a protected page (or a provider of
249
+ yours) on a current-user request. This bond registers `whenRestored()` as the
250
+ HTTP gate, so requests still wait for the background restore/verification to
251
+ settle; only `useAuth().status === 'loading'` means "no decision yet"
252
+ (a page that waits on its own `/me` pays a round trip on every navigation).
253
+
254
+ Used by apps where molecule packages render pricing / billing /
255
+ other authed JSON-fetching screens that need both behaviors.
256
+
257
+ Requests are also held until the session restore settles (see
258
+ {@link registerAuthGate}), so a page that fetches viewer-dependent data on
259
+ mount cannot race it and answer for an anonymous viewer.
260
+
261
+ The profile type is `createDefaultAuthClient`'s: a JSON object type of named
262
+ fields (see `AuthProfileShape`), including an app profile with no `id`.
263
+
264
+ ```typescript
265
+ function createDefaultAuthClientWithFetchClient<
266
+ TUser extends AuthProfileConstraint<TUser> = UserProfile,
267
+ TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
268
+ >(
269
+ authConfig: NoInfer<AuthClientConfigOptions<TUser>>,
270
+ fetchClientOptions: { baseURL: string; withCredentials?: boolean },
271
+ ): {
272
+ authClient: AuthClient<TUser, TRegister>
273
+ setupAuthDefault: () => void
274
+ }
275
+ ```
276
+
277
+ #### `getDefaultThemeProvider()`
278
+
279
+ Returns (and lazily constructs) the shared default CSS-variables theme provider.
280
+
281
+ ```typescript
282
+ function getDefaultThemeProvider(): ReturnType<typeof createCSSVariablesThemeProvider>
283
+ ```
284
+
285
+ #### `setupAppClipboardWeb()`
286
+
287
+ Wires `@molecule/app-clipboard-web` to `@molecule/app-clipboard`: the browser's
288
+ Clipboard API, falling back to a selection-and-copy where that API is missing
289
+ or refuses (a plain-HTTP page, an iframe without the clipboard-write
290
+ permission, a document that lost focus).
291
+
292
+ WITHOUT this, `writeText()` throws "No provider set" and
293
+ `copyTextWithFallback()` only tries the legacy copy command, so a copy button
294
+ built on them works in fewer places than a raw `navigator.clipboard` call.
295
+
296
+ ```typescript
297
+ function setupAppClipboardWeb(): void
298
+ ```
299
+
300
+ #### `setupAppFontsArimo()`
301
+
302
+ Wires `@molecule/app-fonts-arimo` to `@molecule/app-fonts`.
303
+
304
+ ```typescript
305
+ function setupAppFontsArimo(): void
306
+ ```
307
+
308
+ #### `setupAppIconsMolecule()`
309
+
310
+ Wires `@molecule/app-icons-molecule` to `@molecule/app-icons`.
311
+
312
+ ```typescript
313
+ function setupAppIconsMolecule(): void
314
+ ```
315
+
316
+ #### `setupAppStateSimple()`
317
+
318
+ Wires the framework-agnostic `simpleProvider` from `@molecule/app-state` as
319
+ the active state provider.
320
+
321
+ WITHOUT this, `createStore()` throws
322
+ `@molecule/app-state: No provider set. Call setProvider() first` — nothing
323
+ else in a scaffolded app wires the `state` bond, so the documented
324
+ `createStore()` + `useStore()` pattern failed at the first render and every
325
+ page came up blank while `tsc` passed.
326
+
327
+ ```typescript
328
+ function setupAppStateSimple(): void
329
+ ```
330
+
331
+ #### `setupAppStorageLocalstorage()`
332
+
333
+ Wires `@molecule/app-storage-localstorage` to `@molecule/app-storage`.
334
+
335
+ ```typescript
336
+ function setupAppStorageLocalstorage(): void
337
+ ```
338
+
339
+ #### `setupAppStylingTailwind()`
340
+
341
+ Wires `@molecule/app-styling-tailwind`: registers `tailwind-merge` as the
342
+ class merger for `@molecule/app-styling`'s `cn()`, so conflicting Tailwind
343
+ utilities resolve (last wins). Tailwind itself is configured via env vars +
344
+ the Vite plugin; this is the one runtime hook the framework-agnostic styling
345
+ core needs so it carries no Tailwind dependency of its own.
346
+
347
+ ```typescript
348
+ function setupAppStylingTailwind(): void
349
+ ```
350
+
351
+ #### `setupAppThemeCssVariables()`
352
+
353
+ Wires the default light + dark CSS-variables theme provider to `@molecule/app-theme`.
354
+
355
+ ```typescript
356
+ function setupAppThemeCssVariables(): void
357
+ ```
358
+
359
+ #### `setupAppUiTailwind()`
360
+
361
+ Wires `@molecule/app-ui-tailwind` `classMap` to `@molecule/app-ui`.
362
+
363
+ ```typescript
364
+ function setupAppUiTailwind(): void
365
+ ```
366
+
367
+ ## Injection Notes
368
+
369
+ ### Requirements
370
+
371
+ Peer dependencies:
372
+
373
+ - `@molecule/app-auth` ^3.0.0
374
+ - `@molecule/app-charts` ^1.0.1
375
+ - `@molecule/app-charts-chartjs` ^1.0.1
376
+ - `@molecule/app-client-search` ^1.0.0
377
+ - `@molecule/app-client-search-minisearch` ^1.0.0
378
+ - `@molecule/app-clipboard` ^1.0.1
379
+ - `@molecule/app-clipboard-web` ^1.0.1
380
+ - `@molecule/app-code-editor` ^1.0.1
381
+ - `@molecule/app-code-editor-monaco` ^1.0.1
382
+ - `@molecule/app-command-palette` ^1.0.1
383
+ - `@molecule/app-command-palette-cmdk` ^1.0.1
384
+ - `@molecule/app-drag-drop` ^1.0.1
385
+ - `@molecule/app-drag-drop-dndkit` ^1.0.1 || ^2.0.0
386
+ - `@molecule/app-fonts` ^1.0.1
387
+ - `@molecule/app-fonts-arimo` ^1.0.1
388
+ - `@molecule/app-http` ^1.5.0
389
+ - `@molecule/app-icons` ^1.0.1
390
+ - `@molecule/app-icons-molecule` ^1.0.1
391
+ - `@molecule/app-keyboard-shortcuts` ^1.0.1
392
+ - `@molecule/app-keyboard-shortcuts-hotkeys` ^1.0.1
393
+ - `@molecule/app-maps` ^1.0.1
394
+ - `@molecule/app-maps-leaflet` ^1.0.1
395
+ - `@molecule/app-realtime` ^1.0.1
396
+ - `@molecule/app-realtime-socketio` ^1.0.1
397
+ - `@molecule/app-routing` ^1.0.1
398
+ - `@molecule/app-state` ^1.0.1
399
+ - `@molecule/app-storage` ^1.0.1
400
+ - `@molecule/app-storage-localstorage` ^1.0.1
401
+ - `@molecule/app-styling-tailwind` ^1.0.1
402
+ - `@molecule/app-theme` ^1.0.1
403
+ - `@molecule/app-theme-css-variables` ^1.0.1
404
+ - `@molecule/app-ui` ^1.0.1
405
+ - `@molecule/app-ui-tailwind` ^1.0.1
406
+ - `@molecule/app-video` ^1.0.1
407
+ - `@molecule/app-video-hls` ^1.0.1
408
+ - `@molecule/app-virtual-scroll` ^1.0.1
409
+ - `@molecule/app-virtual-scroll-tanstack` ^1.0.1
410
+
411
+ ### Runtime Dependencies
412
+
413
+ - `@molecule/app-auth`
414
+ - `@molecule/app-charts`
415
+ - `@molecule/app-charts-chartjs`
416
+ - `@molecule/app-client-search`
417
+ - `@molecule/app-client-search-minisearch`
418
+ - `@molecule/app-clipboard`
419
+ - `@molecule/app-clipboard-web`
420
+ - `@molecule/app-code-editor`
421
+ - `@molecule/app-code-editor-monaco`
422
+ - `@molecule/app-command-palette`
423
+ - `@molecule/app-command-palette-cmdk`
424
+ - `@molecule/app-drag-drop`
425
+ - `@molecule/app-drag-drop-dndkit`
426
+ - `@molecule/app-fonts`
427
+ - `@molecule/app-fonts-arimo`
428
+ - `@molecule/app-http`
429
+ - `@molecule/app-icons`
430
+ - `@molecule/app-icons-molecule`
431
+ - `@molecule/app-keyboard-shortcuts`
432
+ - `@molecule/app-keyboard-shortcuts-hotkeys`
433
+ - `@molecule/app-maps`
434
+ - `@molecule/app-maps-leaflet`
435
+ - `@molecule/app-realtime`
436
+ - `@molecule/app-realtime-socketio`
437
+ - `@molecule/app-routing`
438
+ - `@molecule/app-state`
439
+ - `@molecule/app-storage`
440
+ - `@molecule/app-storage-localstorage`
441
+ - `@molecule/app-styling-tailwind`
442
+ - `@molecule/app-theme`
443
+ - `@molecule/app-theme-css-variables`
444
+ - `@molecule/app-ui`
445
+ - `@molecule/app-ui-tailwind`
446
+ - `@molecule/app-video`
447
+ - `@molecule/app-video-hls`
448
+ - `@molecule/app-virtual-scroll`
449
+ - `@molecule/app-virtual-scroll-tanstack`
450
+
451
+ - **Optional setups are NOT exported from the package root.** Import each from
452
+ its own subpath — `@molecule/app-bonds-default/optional/maps-leaflet.js`,
453
+ not `from '@molecule/app-bonds-default'`. A bundler must RESOLVE every
454
+ `import()` in a module it pulls into the graph, before tree-shaking can drop
455
+ anything, so while these lived in the barrel every app inherited all 18
456
+ optional providers and any app that had not installed all of them failed to
457
+ build with `Rolldown failed to resolve import "@molecule/app-maps"`. Only
458
+ import a subpath whose provider pair the app actually installs.
459
+ - `setupAllDefaultBonds()` is per-framework (it also wires that framework's
460
+ routing bond) and is exported by `@molecule/app-bonds-default-<framework>`,
461
+ not here. The optional bonds are NOT part of it either way: they ship as
462
+ separate ASYNC setups — `setupAppRealtimeSocketio`,
463
+ `setupAppKeyboardShortcutsHotkeys`, `setupAppCommandPaletteCmdk`,
464
+ `setupAppCodeEditorMonaco`, `setupAppVirtualScrollTanstack`,
465
+ `setupAppDragDropDndkit`, `setupAppChartsChartjs`, `setupAppMapsLeaflet`,
466
+ `setupAppVideoHls` — and MUST be awaited inside `setupProviders`
467
+ (make it async). `bootstrapApp` awaits `setupProviders()` before mounting
468
+ so bonded providers exist by a component's first effect; a fire-and-forget
469
+ async setup races the mount and intermittently loses.
470
+ - Plain `createDefaultAuthClient` does NOT attach the JWT to the bonded
471
+ http client. If molecule packages call authed `/api` endpoints, use
472
+ `createDefaultAuthClientWithHttpSync` (or `...WithFetchClient` to also
473
+ bond a fetch client with a `baseURL`) — otherwise those endpoints return
474
+ 401 after a page reload or token refresh.
475
+ - `getDefaultThemeProvider()` constructs lazily because the CSS-variables
476
+ theme provider touches `localStorage` at construction — importing this
477
+ package is SSR/test-safe, but only CALL it in a DOM environment. Apps
478
+ with custom themes build their own provider and skip
479
+ `setupAppThemeCssVariables()`.