@molecule/app-bonds-default 0.0.0-stage → 0.0.1-stage
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +456 -2
- package/dist/auth.d.ts +156 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +258 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +112 -0
- package/dist/optional/charts-chartjs.d.ts +15 -0
- package/dist/optional/charts-chartjs.d.ts.map +1 -0
- package/dist/optional/charts-chartjs.js +20 -0
- package/dist/optional/client-search-minisearch.d.ts +12 -0
- package/dist/optional/client-search-minisearch.d.ts.map +1 -0
- package/dist/optional/client-search-minisearch.js +17 -0
- package/dist/optional/code-editor-monaco.d.ts +12 -0
- package/dist/optional/code-editor-monaco.d.ts.map +1 -0
- package/dist/optional/code-editor-monaco.js +17 -0
- package/dist/optional/command-palette-cmdk.d.ts +12 -0
- package/dist/optional/command-palette-cmdk.d.ts.map +1 -0
- package/dist/optional/command-palette-cmdk.js +17 -0
- package/dist/optional/drag-drop-dndkit.d.ts +12 -0
- package/dist/optional/drag-drop-dndkit.d.ts.map +1 -0
- package/dist/optional/drag-drop-dndkit.js +17 -0
- package/dist/optional/keyboard-shortcuts-hotkeys.d.ts +12 -0
- package/dist/optional/keyboard-shortcuts-hotkeys.d.ts.map +1 -0
- package/dist/optional/keyboard-shortcuts-hotkeys.js +17 -0
- package/dist/optional/maps-leaflet.d.ts +19 -0
- package/dist/optional/maps-leaflet.d.ts.map +1 -0
- package/dist/optional/maps-leaflet.js +24 -0
- package/dist/optional/realtime-socketio.d.ts +24 -0
- package/dist/optional/realtime-socketio.d.ts.map +1 -0
- package/dist/optional/realtime-socketio.js +29 -0
- package/dist/optional/video-hls.d.ts +12 -0
- package/dist/optional/video-hls.d.ts.map +1 -0
- package/dist/optional/video-hls.js +17 -0
- package/dist/optional/virtual-scroll-tanstack.d.ts +12 -0
- package/dist/optional/virtual-scroll-tanstack.d.ts.map +1 -0
- package/dist/optional/virtual-scroll-tanstack.js +17 -0
- package/dist/setup.d.ts +53 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +97 -0
- package/package.json +174 -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,457 @@
|
|
|
1
|
-
|
|
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-15T07:33:17.270Z
|
|
7
|
+
-->
|
|
2
8
|
|
|
3
|
-
|
|
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 seven 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`. Routing is framework-specific and lives in the
|
|
26
|
+
per-framework packages.
|
|
27
|
+
- **Optional provider wirings live behind subpaths**, one module per pair:
|
|
28
|
+
`@molecule/app-bonds-default/optional/<pair>.js` — `realtime-socketio`,
|
|
29
|
+
`keyboard-shortcuts-hotkeys`, `command-palette-cmdk`, `client-search-minisearch`, `code-editor-monaco`,
|
|
30
|
+
`virtual-scroll-tanstack`, `drag-drop-dndkit`, `charts-chartjs`,
|
|
31
|
+
`maps-leaflet`, `video-hls`. Import ONLY the ones the app installs.
|
|
32
|
+
- Auth/http factories — `createDefaultAuthClient(authConfig)` returns
|
|
33
|
+
`{ authClient, setupAuthDefault }`; the `...WithHttpSync` /
|
|
34
|
+
`...WithFetchClient` variants also keep the bonded http client's bearer
|
|
35
|
+
token in sync with auth events. All three accept any JSON object profile
|
|
36
|
+
(`createDefaultAuthClient<SessionUser>(config)` for an API whose user has no
|
|
37
|
+
`id`) and fall back to `UserProfile` — with its `id: string` — when no type
|
|
38
|
+
argument is given. The profile is never inferred from `authConfig`, so an
|
|
39
|
+
untyped call keeps the default contract.
|
|
40
|
+
|
|
41
|
+
**What this client already handles**
|
|
42
|
+
|
|
43
|
+
- `getAccessToken()` returns a stored token during restore; only 401/403 ends
|
|
44
|
+
the session, while network/5xx failures retain it.
|
|
45
|
+
- `tokenKey`/`storagePrefix`, `authScheme`, `mapAuthResponse`,
|
|
46
|
+
`currentUserEndpoint`, and `profileEndpoint`/`profileUpdateMethod` adapt the API.
|
|
47
|
+
- `logout()` settles local sign-out; `refresh()` uses a stored refresh token.
|
|
48
|
+
|
|
49
|
+
This factory adds no render gate: `AuthProvider` renders children immediately.
|
|
50
|
+
The HTTP-sync variants gate requests during restore, not rendering.
|
|
51
|
+
|
|
52
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
53
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
54
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// bonds/index.ts — any framework
|
|
60
|
+
import { createDefaultAuthClientWithHttpSync } from '@molecule/app-bonds-default'
|
|
61
|
+
// Optional providers come from their own subpath — see @remarks.
|
|
62
|
+
import { setupAppCodeEditorMonaco } from '@molecule/app-bonds-default/optional/code-editor-monaco.js'
|
|
63
|
+
import { authConfig } from '../config.js'
|
|
64
|
+
|
|
65
|
+
export const { authClient, setupAuthDefault } = createDefaultAuthClientWithHttpSync(authConfig)
|
|
66
|
+
|
|
67
|
+
// Async so optional async bonds are AWAITED before the first render.
|
|
68
|
+
export const setupProviders = async () => {
|
|
69
|
+
setupAllDefaultBonds() // from @molecule/app-bonds-default-<framework>
|
|
70
|
+
setupAuthDefault()
|
|
71
|
+
await setupAppCodeEditorMonaco() // only if the app uses the code editor
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Adapt a nested token and `Token` header without another session store.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { createDefaultAuthClient } from '@molecule/app-bonds-default'
|
|
79
|
+
|
|
80
|
+
const { authClient, setupAuthDefault } = createDefaultAuthClient({
|
|
81
|
+
tokenKey: 'app.jwt',
|
|
82
|
+
authScheme: 'Token',
|
|
83
|
+
currentUserEndpoint: '/user',
|
|
84
|
+
profileEndpoint: '/user',
|
|
85
|
+
profileUpdateMethod: 'PUT',
|
|
86
|
+
mapAuthResponse: (data) => {
|
|
87
|
+
const { token, ...user } = (data as { user: { token: string; id: string } }).user
|
|
88
|
+
return { accessToken: token, user }
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Type
|
|
94
|
+
|
|
95
|
+
`feature`
|
|
96
|
+
|
|
97
|
+
## Installation
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
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-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
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## API
|
|
104
|
+
|
|
105
|
+
### Functions
|
|
106
|
+
|
|
107
|
+
#### `createDefaultHttpClient(baseURL)`
|
|
108
|
+
|
|
109
|
+
Builds the default fetch-based HTTP client + wires it into
|
|
110
|
+
`@molecule/app-http`. Replaces the per-app `bonds/http-default.ts`
|
|
111
|
+
shipped by ~52 fleet apps.
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
function createDefaultHttpClient(baseURL: string): {
|
|
115
|
+
httpClient: HttpClient
|
|
116
|
+
setupHttpDefault: () => void
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### `createDefaultHttpClientWithAuthBearer(opts)`
|
|
121
|
+
|
|
122
|
+
Variant of `createDefaultHttpClient` that adds a request interceptor
|
|
123
|
+
injecting the JWT bearer token from the auth client AND (optionally)
|
|
124
|
+
stripping a leading `/api/` from request URLs.
|
|
125
|
+
|
|
126
|
+
Replaces ~20 per-app `bonds/http-default.ts` files that hand-roll
|
|
127
|
+
this same wiring. Pass `stripApiPrefix: true` when the app uses
|
|
128
|
+
`baseURL: '/api'` to handle pages that pass `/api/`-prefixed paths
|
|
129
|
+
(would otherwise resolve to `/api/api/...` and 404). Pass `authScheme`
|
|
130
|
+
when the API reads another scheme than `Bearer`: it is an option of THIS
|
|
131
|
+
constructor (`createDefaultHttpClientWithAuthBearer({ authScheme: 'Token', … })`,
|
|
132
|
+
or `createFetchClient({ baseURL, authScheme: 'Token' })` directly), never a
|
|
133
|
+
property of the client it returns. The client is built with the same scheme, so
|
|
134
|
+
a token the client also holds — the one a default auth bond's token sync gives
|
|
135
|
+
it — is sent with that scheme too, not as `Bearer`.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
function createDefaultHttpClientWithAuthBearer(opts: {
|
|
139
|
+
baseURL: string
|
|
140
|
+
withCredentials?: boolean
|
|
141
|
+
stripApiPrefix?: boolean
|
|
142
|
+
getToken: () => string | null | undefined
|
|
143
|
+
/**
|
|
144
|
+
* The scheme of the `Authorization` header the token from `getToken()` is sent
|
|
145
|
+
* with: `Bearer` (default), or what the API expects, e.g. `Token` for an API
|
|
146
|
+
* that reads `Authorization: Token <jwt>`. Pass it to this constructor — the
|
|
147
|
+
* same option `@molecule/app-http`'s client config calls `authScheme`, and not
|
|
148
|
+
* a property of the client that comes back.
|
|
149
|
+
*/
|
|
150
|
+
authScheme?: string
|
|
151
|
+
}): {
|
|
152
|
+
httpClient: HttpClient
|
|
153
|
+
setupHttpDefault: () => void
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### `createDefaultAuthClient(authConfig)`
|
|
158
|
+
|
|
159
|
+
Builds the default JWT auth client + wires it into `@molecule/app-auth`.
|
|
160
|
+
Apps pass their own `authConfig` (which lives in `src/config.ts`).
|
|
161
|
+
|
|
162
|
+
`TUser` is the profile the app's pages read, and may be any JSON object type —
|
|
163
|
+
including a profile with NO `id` (`{ username, email, bio, image }`), as in the
|
|
164
|
+
factory it wraps. Never add a synthetic `id` to satisfy a type: nothing in the
|
|
165
|
+
client reads it, and the fabricated value then travels into storage, `getUser()`
|
|
166
|
+
and every page. Omit the type parameter and the default is `UserProfile`, whose
|
|
167
|
+
`id: string` stays required — the profile is never inferred from `authConfig`
|
|
168
|
+
(not even from an annotated config variable), so an untyped wrapper call keeps
|
|
169
|
+
the default contract.
|
|
170
|
+
|
|
171
|
+
Type the config with the SAME type (`const authConfig: AuthClientConfig<MyUser> = { … }`)
|
|
172
|
+
so its `mapAuthResponse` is checked against `MyUser`, and name that type at the
|
|
173
|
+
call (`createDefaultAuthClient<MyUser>(authConfig)`): a mapper that omits a
|
|
174
|
+
required custom field then fails at that call instead of shipping a signed-in
|
|
175
|
+
page that reads `undefined`. An annotated config alone does not supply the type
|
|
176
|
+
argument — that is a 1.8 caller shape this major changes (see
|
|
177
|
+
`AuthClientConfig`'s migration note in `@molecule/app-auth`).
|
|
178
|
+
|
|
179
|
+
`TRegister` is the app's own extra registration fields (for example
|
|
180
|
+
`{ username: string }`), passed on to `@molecule/app-auth`'s factory so
|
|
181
|
+
`authClient.register({ username, email, password })` type-checks with no cast.
|
|
182
|
+
See the module guidance for the lifecycle and API adaptations already included.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
function createDefaultAuthClient<
|
|
186
|
+
TUser extends AuthProfileConstraint<TUser> = UserProfile,
|
|
187
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
188
|
+
>(
|
|
189
|
+
authConfig: NoInfer<AuthClientConfigOptions<TUser>>,
|
|
190
|
+
): {
|
|
191
|
+
authClient: AuthClient<TUser, TRegister>
|
|
192
|
+
setupAuthDefault: () => void
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### `createDefaultAuthClientWithHttpSync(authConfig)`
|
|
197
|
+
|
|
198
|
+
Variant of `createDefaultAuthClient` that also keeps the bonded
|
|
199
|
+
`@molecule/app-http` client's bearer token in sync with the auth client's session.
|
|
200
|
+
Required by apps whose http client must carry the JWT on every request — without
|
|
201
|
+
this wiring, authed endpoints return 401 after page reloads or token refresh.
|
|
202
|
+
|
|
203
|
+
The sync is a LIVE read: `@molecule/app-http`'s `setAuthTokenSource` registers the auth
|
|
204
|
+
client's token, and every client the app bonds, before or after this setup, reads it on
|
|
205
|
+
each request — so the order of the `setup*()` calls in `bonds/index.ts` does not matter
|
|
206
|
+
and never needs changing for auth. A session adopted with no
|
|
207
|
+
auth event (`useAuth().setSession()`, an OAuth callback's `setAccessToken()`, the same
|
|
208
|
+
profile under a new token) is therefore sent by the next request, not the previous
|
|
209
|
+
account's bearer. A transport without `setAuthTokenResolver` is followed through a request
|
|
210
|
+
interceptor (see `setAuthTokenSource` for which request first carries the change), and
|
|
211
|
+
auth events still push the token to it.
|
|
212
|
+
|
|
213
|
+
A cookie session (no body token) resolves to `null`, so the request carries NO
|
|
214
|
+
`Authorization` header — a kept bearer would answer as the PRIOR session.
|
|
215
|
+
Requests also wait for the session restore, so a page that fetches viewer data on mount
|
|
216
|
+
cannot race it (see {@link registerAuthGate}).
|
|
217
|
+
|
|
218
|
+
The profile type is `createDefaultAuthClient`'s: a JSON object type of named
|
|
219
|
+
fields (see `AuthProfileShape`), including an app profile with no `id`.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
function createDefaultAuthClientWithHttpSync<
|
|
223
|
+
TUser extends AuthProfileConstraint<TUser> = UserProfile,
|
|
224
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
225
|
+
>(
|
|
226
|
+
authConfig: NoInfer<AuthClientConfigOptions<TUser>>,
|
|
227
|
+
): {
|
|
228
|
+
authClient: AuthClient<TUser, TRegister>
|
|
229
|
+
setupAuthDefault: () => void
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### `createDefaultAuthClientWithFetchClient(authConfig, fetchClientOptions)`
|
|
234
|
+
|
|
235
|
+
Most aggressive variant — bonds a fetch-based HTTP client with the
|
|
236
|
+
given `baseURL` (so molecule pkg `useGet('/path')` calls hit
|
|
237
|
+
`${baseURL}/path` instead of the SPA's catch-all route), AND keeps
|
|
238
|
+
its bearer token in sync with the auth client's session, read on every
|
|
239
|
+
request: a session adopted with no auth event (`setSession()`,
|
|
240
|
+
`setAccessToken()`) is sent by the next request. The token uses the auth
|
|
241
|
+
config's `authScheme` (default `Bearer`); a client bonded after this setup
|
|
242
|
+
gets the same source and auth events.
|
|
243
|
+
|
|
244
|
+
The auth client restores a stored token AND user SYNCHRONOUSLY, so the first
|
|
245
|
+
render is the signed-in UI — do not gate a protected page (or a provider of
|
|
246
|
+
yours) on a current-user request. This bond registers `whenRestored()` as the
|
|
247
|
+
HTTP gate, so requests still wait for the background restore/verification to
|
|
248
|
+
settle; only `useAuth().status === 'loading'` means "no decision yet"
|
|
249
|
+
(a page that waits on its own `/me` pays a round trip on every navigation).
|
|
250
|
+
|
|
251
|
+
Used by apps where molecule packages render pricing / billing /
|
|
252
|
+
other authed JSON-fetching screens that need both behaviors.
|
|
253
|
+
|
|
254
|
+
Requests are also held until the session restore settles (see
|
|
255
|
+
{@link registerAuthGate}), so a page that fetches viewer-dependent data on
|
|
256
|
+
mount cannot race it and answer for an anonymous viewer.
|
|
257
|
+
|
|
258
|
+
The profile type is `createDefaultAuthClient`'s: a JSON object type of named
|
|
259
|
+
fields (see `AuthProfileShape`), including an app profile with no `id`.
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
function createDefaultAuthClientWithFetchClient<
|
|
263
|
+
TUser extends AuthProfileConstraint<TUser> = UserProfile,
|
|
264
|
+
TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
|
|
265
|
+
>(
|
|
266
|
+
authConfig: NoInfer<AuthClientConfigOptions<TUser>>,
|
|
267
|
+
fetchClientOptions: { baseURL: string; withCredentials?: boolean },
|
|
268
|
+
): {
|
|
269
|
+
authClient: AuthClient<TUser, TRegister>
|
|
270
|
+
setupAuthDefault: () => void
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
#### `getDefaultThemeProvider()`
|
|
275
|
+
|
|
276
|
+
Returns (and lazily constructs) the shared default CSS-variables theme provider.
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
function getDefaultThemeProvider(): ReturnType<typeof createCSSVariablesThemeProvider>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
#### `setupAppFontsArimo()`
|
|
283
|
+
|
|
284
|
+
Wires `@molecule/app-fonts-arimo` to `@molecule/app-fonts`.
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
function setupAppFontsArimo(): void
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
#### `setupAppIconsMolecule()`
|
|
291
|
+
|
|
292
|
+
Wires `@molecule/app-icons-molecule` to `@molecule/app-icons`.
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
function setupAppIconsMolecule(): void
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
#### `setupAppStateSimple()`
|
|
299
|
+
|
|
300
|
+
Wires the framework-agnostic `simpleProvider` from `@molecule/app-state` as
|
|
301
|
+
the active state provider.
|
|
302
|
+
|
|
303
|
+
WITHOUT this, `createStore()` throws
|
|
304
|
+
`@molecule/app-state: No provider set. Call setProvider() first` — nothing
|
|
305
|
+
else in a scaffolded app wires the `state` bond, so the documented
|
|
306
|
+
`createStore()` + `useStore()` pattern failed at the first render and every
|
|
307
|
+
page came up blank while `tsc` passed.
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
function setupAppStateSimple(): void
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
#### `setupAppStorageLocalstorage()`
|
|
314
|
+
|
|
315
|
+
Wires `@molecule/app-storage-localstorage` to `@molecule/app-storage`.
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
function setupAppStorageLocalstorage(): void
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### `setupAppStylingTailwind()`
|
|
322
|
+
|
|
323
|
+
Wires `@molecule/app-styling-tailwind`: registers `tailwind-merge` as the
|
|
324
|
+
class merger for `@molecule/app-styling`'s `cn()`, so conflicting Tailwind
|
|
325
|
+
utilities resolve (last wins). Tailwind itself is configured via env vars +
|
|
326
|
+
the Vite plugin; this is the one runtime hook the framework-agnostic styling
|
|
327
|
+
core needs so it carries no Tailwind dependency of its own.
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
function setupAppStylingTailwind(): void
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
#### `setupAppThemeCssVariables()`
|
|
334
|
+
|
|
335
|
+
Wires the default light + dark CSS-variables theme provider to `@molecule/app-theme`.
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
function setupAppThemeCssVariables(): void
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
#### `setupAppUiTailwind()`
|
|
342
|
+
|
|
343
|
+
Wires `@molecule/app-ui-tailwind` `classMap` to `@molecule/app-ui`.
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
function setupAppUiTailwind(): void
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Injection Notes
|
|
350
|
+
|
|
351
|
+
### Requirements
|
|
352
|
+
|
|
353
|
+
Peer dependencies:
|
|
354
|
+
|
|
355
|
+
- `@molecule/app-auth` ^3.0.0
|
|
356
|
+
- `@molecule/app-charts` ^1.0.1
|
|
357
|
+
- `@molecule/app-charts-chartjs` ^1.0.1
|
|
358
|
+
- `@molecule/app-client-search` ^1.0.0
|
|
359
|
+
- `@molecule/app-client-search-minisearch` ^1.0.0
|
|
360
|
+
- `@molecule/app-code-editor` ^1.0.1
|
|
361
|
+
- `@molecule/app-code-editor-monaco` ^1.0.1
|
|
362
|
+
- `@molecule/app-command-palette` ^1.0.1
|
|
363
|
+
- `@molecule/app-command-palette-cmdk` ^1.0.1
|
|
364
|
+
- `@molecule/app-drag-drop` ^1.0.1
|
|
365
|
+
- `@molecule/app-drag-drop-dndkit` ^1.0.1
|
|
366
|
+
- `@molecule/app-fonts` ^1.0.1
|
|
367
|
+
- `@molecule/app-fonts-arimo` ^1.0.1
|
|
368
|
+
- `@molecule/app-http` ^1.5.0
|
|
369
|
+
- `@molecule/app-icons` ^1.0.1
|
|
370
|
+
- `@molecule/app-icons-molecule` ^1.0.1
|
|
371
|
+
- `@molecule/app-keyboard-shortcuts` ^1.0.1
|
|
372
|
+
- `@molecule/app-keyboard-shortcuts-hotkeys` ^1.0.1
|
|
373
|
+
- `@molecule/app-maps` ^1.0.1
|
|
374
|
+
- `@molecule/app-maps-leaflet` ^1.0.1
|
|
375
|
+
- `@molecule/app-realtime` ^1.0.1
|
|
376
|
+
- `@molecule/app-realtime-socketio` ^1.0.1
|
|
377
|
+
- `@molecule/app-routing` ^1.0.1
|
|
378
|
+
- `@molecule/app-state` ^1.0.1
|
|
379
|
+
- `@molecule/app-storage` ^1.0.1
|
|
380
|
+
- `@molecule/app-storage-localstorage` ^1.0.1
|
|
381
|
+
- `@molecule/app-styling-tailwind` ^1.0.1
|
|
382
|
+
- `@molecule/app-theme` ^1.0.1
|
|
383
|
+
- `@molecule/app-theme-css-variables` ^1.0.1
|
|
384
|
+
- `@molecule/app-ui` ^1.0.1
|
|
385
|
+
- `@molecule/app-ui-tailwind` ^1.0.1
|
|
386
|
+
- `@molecule/app-video` ^1.0.1
|
|
387
|
+
- `@molecule/app-video-hls` ^1.0.1
|
|
388
|
+
- `@molecule/app-virtual-scroll` ^1.0.1
|
|
389
|
+
- `@molecule/app-virtual-scroll-tanstack` ^1.0.1
|
|
390
|
+
|
|
391
|
+
### Runtime Dependencies
|
|
392
|
+
|
|
393
|
+
- `@molecule/app-auth`
|
|
394
|
+
- `@molecule/app-charts`
|
|
395
|
+
- `@molecule/app-charts-chartjs`
|
|
396
|
+
- `@molecule/app-client-search`
|
|
397
|
+
- `@molecule/app-client-search-minisearch`
|
|
398
|
+
- `@molecule/app-code-editor`
|
|
399
|
+
- `@molecule/app-code-editor-monaco`
|
|
400
|
+
- `@molecule/app-command-palette`
|
|
401
|
+
- `@molecule/app-command-palette-cmdk`
|
|
402
|
+
- `@molecule/app-drag-drop`
|
|
403
|
+
- `@molecule/app-drag-drop-dndkit`
|
|
404
|
+
- `@molecule/app-fonts`
|
|
405
|
+
- `@molecule/app-fonts-arimo`
|
|
406
|
+
- `@molecule/app-http`
|
|
407
|
+
- `@molecule/app-icons`
|
|
408
|
+
- `@molecule/app-icons-molecule`
|
|
409
|
+
- `@molecule/app-keyboard-shortcuts`
|
|
410
|
+
- `@molecule/app-keyboard-shortcuts-hotkeys`
|
|
411
|
+
- `@molecule/app-maps`
|
|
412
|
+
- `@molecule/app-maps-leaflet`
|
|
413
|
+
- `@molecule/app-realtime`
|
|
414
|
+
- `@molecule/app-realtime-socketio`
|
|
415
|
+
- `@molecule/app-routing`
|
|
416
|
+
- `@molecule/app-state`
|
|
417
|
+
- `@molecule/app-storage`
|
|
418
|
+
- `@molecule/app-storage-localstorage`
|
|
419
|
+
- `@molecule/app-styling-tailwind`
|
|
420
|
+
- `@molecule/app-theme`
|
|
421
|
+
- `@molecule/app-theme-css-variables`
|
|
422
|
+
- `@molecule/app-ui`
|
|
423
|
+
- `@molecule/app-ui-tailwind`
|
|
424
|
+
- `@molecule/app-video`
|
|
425
|
+
- `@molecule/app-video-hls`
|
|
426
|
+
- `@molecule/app-virtual-scroll`
|
|
427
|
+
- `@molecule/app-virtual-scroll-tanstack`
|
|
428
|
+
|
|
429
|
+
- **Optional setups are NOT exported from the package root.** Import each from
|
|
430
|
+
its own subpath — `@molecule/app-bonds-default/optional/maps-leaflet.js`,
|
|
431
|
+
not `from '@molecule/app-bonds-default'`. A bundler must RESOLVE every
|
|
432
|
+
`import()` in a module it pulls into the graph, before tree-shaking can drop
|
|
433
|
+
anything, so while these lived in the barrel every app inherited all 18
|
|
434
|
+
optional providers and any app that had not installed all of them failed to
|
|
435
|
+
build with `Rolldown failed to resolve import "@molecule/app-maps"`. Only
|
|
436
|
+
import a subpath whose provider pair the app actually installs.
|
|
437
|
+
- `setupAllDefaultBonds()` is per-framework (it also wires that framework's
|
|
438
|
+
routing bond) and is exported by `@molecule/app-bonds-default-<framework>`,
|
|
439
|
+
not here. The optional bonds are NOT part of it either way: they ship as
|
|
440
|
+
separate ASYNC setups — `setupAppRealtimeSocketio`,
|
|
441
|
+
`setupAppKeyboardShortcutsHotkeys`, `setupAppCommandPaletteCmdk`,
|
|
442
|
+
`setupAppCodeEditorMonaco`, `setupAppVirtualScrollTanstack`,
|
|
443
|
+
`setupAppDragDropDndkit`, `setupAppChartsChartjs`, `setupAppMapsLeaflet`,
|
|
444
|
+
`setupAppVideoHls` — and MUST be awaited inside `setupProviders`
|
|
445
|
+
(make it async). `bootstrapApp` awaits `setupProviders()` before mounting
|
|
446
|
+
so bonded providers exist by a component's first effect; a fire-and-forget
|
|
447
|
+
async setup races the mount and intermittently loses.
|
|
448
|
+
- Plain `createDefaultAuthClient` does NOT attach the JWT to the bonded
|
|
449
|
+
http client. If molecule packages call authed `/api` endpoints, use
|
|
450
|
+
`createDefaultAuthClientWithHttpSync` (or `...WithFetchClient` to also
|
|
451
|
+
bond a fetch client with a `baseURL`) — otherwise those endpoints return
|
|
452
|
+
401 after a page reload or token refresh.
|
|
453
|
+
- `getDefaultThemeProvider()` constructs lazily because the CSS-variables
|
|
454
|
+
theme provider touches `localStorage` at construction — importing this
|
|
455
|
+
package is SSR/test-safe, but only CALL it in a DOM environment. Apps
|
|
456
|
+
with custom themes build their own provider and skip
|
|
457
|
+
`setupAppThemeCssVariables()`.
|