@brendanbank/atrium-host-bundle-utils 0.15.0 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -20
- package/dist/react/index.d.ts +11 -12
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +19 -21
- package/dist/react/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,26 +20,16 @@ reg.registerHomeWidget({
|
|
|
20
20
|
|
|
21
21
|
## Installation
|
|
22
22
|
|
|
23
|
-
The package is published on **GitHub Packages**, not the public npm
|
|
24
|
-
registry. Add an `.npmrc` to your host project that points the
|
|
25
|
-
`@brendanbank` scope at GitHub Packages and supplies a token with
|
|
26
|
-
`read:packages` scope:
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
# .npmrc
|
|
30
|
-
@brendanbank:registry=https://npm.pkg.github.com
|
|
31
|
-
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
In CI, `GITHUB_TOKEN` is provided automatically by Actions; locally,
|
|
35
|
-
generate a [classic PAT](https://github.com/settings/tokens) with
|
|
36
|
-
`read:packages` and export it. Then:
|
|
37
|
-
|
|
38
23
|
```bash
|
|
39
24
|
pnpm add @brendanbank/atrium-host-bundle-utils \
|
|
40
25
|
@brendanbank/atrium-host-types
|
|
41
26
|
```
|
|
42
27
|
|
|
28
|
+
The package is published on the public npm registry. No `.npmrc`,
|
|
29
|
+
no auth token, no PAT. If you adopted atrium before v0.15.1 and
|
|
30
|
+
have an `@brendanbank:registry=https://npm.pkg.github.com` line in
|
|
31
|
+
your `.npmrc`, delete it — npmjs.org is the default registry.
|
|
32
|
+
|
|
43
33
|
## Three subpath entry-points
|
|
44
34
|
|
|
45
35
|
| Import | What you get |
|
|
@@ -89,7 +79,7 @@ function CommissionsPage() {
|
|
|
89
79
|
function App() {
|
|
90
80
|
return (
|
|
91
81
|
<QueryClientProvider client={hostQueryClient}>
|
|
92
|
-
<AtriumProvider
|
|
82
|
+
<AtriumProvider>
|
|
93
83
|
<CommissionsPage />
|
|
94
84
|
</AtriumProvider>
|
|
95
85
|
</QueryClientProvider>
|
|
@@ -97,10 +87,13 @@ function App() {
|
|
|
97
87
|
}
|
|
98
88
|
```
|
|
99
89
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
90
|
+
The hooks fetch atrium's fixed same-origin `/users/me/context`
|
|
91
|
+
endpoint — no path is configurable, since a host bundle loads inside
|
|
92
|
+
atrium's SPA and hits the same origin. `<AtriumProvider>` reads from
|
|
93
|
+
your existing `<QueryClientProvider>` by default — no second
|
|
94
|
+
QueryClient. Pass `client={hostQueryClient}` to wrap one inline; pass
|
|
95
|
+
`fetchUserContext={...}` to inject a custom fetcher (useful for tests
|
|
96
|
+
or hosts that want axios-shaped retry).
|
|
104
97
|
|
|
105
98
|
## Versioning
|
|
106
99
|
|
package/dist/react/index.d.ts
CHANGED
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
* One TanStack Query subscription serves the whole host tree:
|
|
5
5
|
* `useMe()` fetches `/users/me/context` once and shares the result
|
|
6
6
|
* with every `usePerm()`, `useRole()`, and `useUserContext()` caller.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* The endpoint path is fixed by atrium — it's mounted at the SPA root
|
|
9
|
+
* by `app.include_router(me_context_router)` and served from the same
|
|
10
|
+
* origin as the bundle. There's no `apiBase` prop because there's
|
|
11
|
+
* nothing for the host to configure: a host bundle that loads inside
|
|
12
|
+
* atrium's SPA fetches a same-origin relative path. Hosts that want
|
|
13
|
+
* to layer their own retry / headers / mock can pass `fetchUserContext`.
|
|
10
14
|
*
|
|
11
15
|
* The hooks reuse the host's enclosing `<QueryClientProvider>` if one
|
|
12
16
|
* is already mounted; pass `client={hostQueryClient}` to
|
|
@@ -21,14 +25,9 @@ import type { UserContext } from '@brendanbank/atrium-host-types';
|
|
|
21
25
|
export type { UserContext } from '@brendanbank/atrium-host-types';
|
|
22
26
|
export { __atrium_t__ } from '../i18n';
|
|
23
27
|
interface AtriumContextValue {
|
|
24
|
-
apiBase: string;
|
|
25
28
|
fetchUserContext: () => Promise<UserContext | null>;
|
|
26
29
|
}
|
|
27
30
|
export interface AtriumProviderProps {
|
|
28
|
-
/** API base URL the hooks prefix on every fetch. Default `'/api'` —
|
|
29
|
-
* matches atrium's convention of mounting the API behind `/api/*`
|
|
30
|
-
* on the same origin as the SPA. */
|
|
31
|
-
apiBase?: string;
|
|
32
31
|
/** Optional TanStack QueryClient. When supplied the provider wraps
|
|
33
32
|
* children in a `<QueryClientProvider>`; otherwise the hooks
|
|
34
33
|
* inherit the caller's enclosing one. Use this only when the host
|
|
@@ -41,11 +40,11 @@ export interface AtriumProviderProps {
|
|
|
41
40
|
fetchUserContext?: () => Promise<UserContext | null>;
|
|
42
41
|
children: ReactNode;
|
|
43
42
|
}
|
|
44
|
-
/** Provider that supplies
|
|
45
|
-
*
|
|
46
|
-
* `<QueryClientProvider>` can omit `client` — the hooks use the
|
|
43
|
+
/** Provider that supplies the atrium hooks below with their fetcher
|
|
44
|
+
* and (optionally) a QueryClient. Hosts that already wrap their tree
|
|
45
|
+
* in `<QueryClientProvider>` can omit `client` — the hooks use the
|
|
47
46
|
* caller's existing QueryClient. */
|
|
48
|
-
export declare function AtriumProvider({
|
|
47
|
+
export declare function AtriumProvider({ client, fetchUserContext, children, }: AtriumProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<AtriumContextValue | null>> | import("react").FunctionComponentElement<import("@tanstack/react-query").QueryClientProviderProps>;
|
|
49
48
|
/** Stable cache key for the `/users/me/context` query. Exported so
|
|
50
49
|
* hosts can `queryClient.invalidateQueries({ queryKey: ME_QUERY_KEY })`
|
|
51
50
|
* after a flow that changed the user's roles or permissions. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAElE,YAAY,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,UAAU,kBAAkB;IAC1B,gBAAgB,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CACrD;AAmBD,MAAM,WAAW,mBAAmB;IAClC;;;kDAG8C;IAC9C,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;sBAGkB;IAClB,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACrD,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;qCAGqC;AACrC,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,gBAAgB,EAChB,QAAQ,GACT,EAAE,mBAAmB,2MAYrB;AAED;;iEAEiE;AACjE,eAAO,MAAM,YAAY,2BAA4B,CAAC;AAmBtD;;;;;;;;8BAQ8B;AAC9B,wBAAgB,KAAK,IAAI,cAAc,CAAC,WAAW,GAAG,IAAI,CAAC,CAQ1D;AAED;;iBAEiB;AACjB,wBAAgB,cAAc,IAAI,cAAc,CAAC,WAAW,GAAG,IAAI,CAAC,CAEnE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAMnD;AAED;sEACsE;AACtE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG7C"}
|
package/dist/react/index.js
CHANGED
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
* One TanStack Query subscription serves the whole host tree:
|
|
7
7
|
* `useMe()` fetches `/users/me/context` once and shares the result
|
|
8
8
|
* with every `usePerm()`, `useRole()`, and `useUserContext()` caller.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* The endpoint path is fixed by atrium — it's mounted at the SPA root
|
|
11
|
+
* by `app.include_router(me_context_router)` and served from the same
|
|
12
|
+
* origin as the bundle. There's no `apiBase` prop because there's
|
|
13
|
+
* nothing for the host to configure: a host bundle that loads inside
|
|
14
|
+
* atrium's SPA fetches a same-origin relative path. Hosts that want
|
|
15
|
+
* to layer their own retry / headers / mock can pass `fetchUserContext`.
|
|
12
16
|
*
|
|
13
17
|
* The hooks reuse the host's enclosing `<QueryClientProvider>` if one
|
|
14
18
|
* is already mounted; pass `client={hostQueryClient}` to
|
|
@@ -20,9 +24,9 @@
|
|
|
20
24
|
import { createContext, createElement, useCallback, useContext, useMemo, } from 'react';
|
|
21
25
|
import { QueryClientProvider, useQuery, } from '@tanstack/react-query';
|
|
22
26
|
export { __atrium_t__ } from '../i18n';
|
|
23
|
-
const
|
|
24
|
-
async function defaultFetchUserContext(
|
|
25
|
-
const res = await fetch(
|
|
27
|
+
const ME_CONTEXT_PATH = '/users/me/context';
|
|
28
|
+
async function defaultFetchUserContext() {
|
|
29
|
+
const res = await fetch(ME_CONTEXT_PATH, {
|
|
26
30
|
credentials: 'include',
|
|
27
31
|
headers: { Accept: 'application/json' },
|
|
28
32
|
});
|
|
@@ -30,20 +34,17 @@ async function defaultFetchUserContext(apiBase) {
|
|
|
30
34
|
return null;
|
|
31
35
|
if (!res.ok) {
|
|
32
36
|
const body = await res.text().catch(() => '');
|
|
33
|
-
throw new Error(
|
|
37
|
+
throw new Error(`${ME_CONTEXT_PATH}: ${res.status} ${body}`.trim());
|
|
34
38
|
}
|
|
35
39
|
return (await res.json());
|
|
36
40
|
}
|
|
37
41
|
const AtriumContext = createContext(null);
|
|
38
|
-
/** Provider that supplies
|
|
39
|
-
*
|
|
40
|
-
* `<QueryClientProvider>` can omit `client` — the hooks use the
|
|
42
|
+
/** Provider that supplies the atrium hooks below with their fetcher
|
|
43
|
+
* and (optionally) a QueryClient. Hosts that already wrap their tree
|
|
44
|
+
* in `<QueryClientProvider>` can omit `client` — the hooks use the
|
|
41
45
|
* caller's existing QueryClient. */
|
|
42
|
-
export function AtriumProvider({
|
|
43
|
-
const value = useMemo(() => {
|
|
44
|
-
const fetcher = fetchUserContext ?? (() => defaultFetchUserContext(apiBase));
|
|
45
|
-
return { apiBase, fetchUserContext: fetcher };
|
|
46
|
-
}, [apiBase, fetchUserContext]);
|
|
46
|
+
export function AtriumProvider({ client, fetchUserContext, children, }) {
|
|
47
|
+
const value = useMemo(() => ({ fetchUserContext: fetchUserContext ?? defaultFetchUserContext }), [fetchUserContext]);
|
|
47
48
|
const inner = createElement(AtriumContext.Provider, { value }, children);
|
|
48
49
|
if (client) {
|
|
49
50
|
return createElement(QueryClientProvider, { client }, inner);
|
|
@@ -56,15 +57,12 @@ export function AtriumProvider({ apiBase = DEFAULT_API_BASE, client, fetchUserCo
|
|
|
56
57
|
export const ME_QUERY_KEY = ['atrium', 'me'];
|
|
57
58
|
// Module-level fallback so hooks work without an explicit
|
|
58
59
|
// `<AtriumProvider>` — convenient for hosts that don't need to
|
|
59
|
-
// override the
|
|
60
|
-
//
|
|
60
|
+
// override the fetcher. Lazily-allocated so the import has no side
|
|
61
|
+
// effects.
|
|
61
62
|
let DEFAULT_CTX = null;
|
|
62
63
|
function defaultCtx() {
|
|
63
64
|
if (!DEFAULT_CTX) {
|
|
64
|
-
DEFAULT_CTX = {
|
|
65
|
-
apiBase: DEFAULT_API_BASE,
|
|
66
|
-
fetchUserContext: () => defaultFetchUserContext(DEFAULT_API_BASE),
|
|
67
|
-
};
|
|
65
|
+
DEFAULT_CTX = { fetchUserContext: defaultFetchUserContext };
|
|
68
66
|
}
|
|
69
67
|
return DEFAULT_CTX;
|
|
70
68
|
}
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,wCAAwC;AAExC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,wCAAwC;AAExC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAO,GAER,MAAM,OAAO,CAAC;AACf,OAAO,EACL,mBAAmB,EACnB,QAAQ,GAGT,MAAM,uBAAuB,CAAC;AAK/B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAMvC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAE5C,KAAK,UAAU,uBAAuB;IACpC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,eAAe,EAAE;QACvC,WAAW,EAAE,SAAS;QACtB,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;KACxC,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IAC1D,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,GAAG,eAAe,KAAK,GAAG,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAA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ACtB,OAAO,EAAE,gBAAgB;QACzB,SAAS,EAAE,MAAM;QACjB,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;AACL,CAAC;AAED;;iBAEiB;AACjB,MAAM,UAAU,cAAc;IAC5B,OAAO,KAAK,EAAE,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC;IAC7B,OAAO,WAAW,CAChB,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EACxD,CAAC,EAAE,EAAE,WAAW,CAAC,CAClB,CAAC;AACJ,CAAC;AAED;sEACsE;AACtE,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brendanbank/atrium-host-bundle-utils",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "Runtime helpers, Vite preset, and React hooks for atrium host bundles. Wraps the dual-tree mount pattern, the host-bundle Vite library config, and the /users/me/context hook so a host's main.tsx is ~10 lines of registration calls.",
|
|
5
5
|
"license": "BSD-2-Clause",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@brendanbank/atrium-host-types": "0.15.
|
|
28
|
+
"@brendanbank/atrium-host-types": "0.15.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@tanstack/react-query": "^5.0.0",
|