@w6w/react 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -24
- package/dist/mod.d.ts +5 -5
- package/dist/mod.js +5 -5
- package/dist/src/{W6wProvider.d.ts → W6WProvider.d.ts} +14 -14
- package/dist/src/{W6wProvider.d.ts.map → W6WProvider.d.ts.map} +1 -1
- package/dist/src/{W6wProvider.js → W6WProvider.js} +16 -16
- package/dist/src/{W6wProvider.js.map → W6WProvider.js.map} +1 -1
- package/dist/src/adapter.d.ts +9 -9
- package/dist/src/adapter.js +8 -8
- package/dist/src/hooks.d.ts +1 -1
- package/dist/src/hooks.js +17 -17
- package/dist/src/version.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @w6w/react
|
|
2
2
|
|
|
3
|
-
React bindings for [`@w6w/sdk`](../node) — a `<
|
|
4
|
-
`
|
|
3
|
+
React bindings for [`@w6w/sdk`](../node) — a `<W6WProvider>` that holds one memoized
|
|
4
|
+
`W6WClient` with per-request token freshness, a small hook set over the SDK's public
|
|
5
5
|
surface (`me`, `documents`, `vars`, `connections`, `workflows`, `run`), and
|
|
6
|
-
`
|
|
7
|
-
[`@w6w/ui`](https://github.com/w6w-io/w6w-ui)'s `
|
|
6
|
+
`createW6WUiAdapter`, a structural bridge from a `W6WClient` to
|
|
7
|
+
[`@w6w/ui`](https://github.com/w6w-io/w6w-ui)'s `W6WApi` contract.
|
|
8
8
|
|
|
9
9
|
License: MIT · Version: 0.3.0
|
|
10
10
|
|
|
@@ -18,7 +18,7 @@ re-verify against the wire contract; verify `@w6w/sdk` instead.
|
|
|
18
18
|
npm install @w6w/react react
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
`react-dom` is not a dependency of this package — `<
|
|
21
|
+
`react-dom` is not a dependency of this package — `<W6WProvider>`'s only JSX is a
|
|
22
22
|
context wrapper (`<Ctx.Provider>`), never a DOM element of its own. Your app already
|
|
23
23
|
depends on `react-dom` to mount itself; nothing extra is needed here.
|
|
24
24
|
|
|
@@ -27,13 +27,13 @@ depends on `react-dom` to mount itself; nothing extra is needed here.
|
|
|
27
27
|
Wrap your app root once:
|
|
28
28
|
|
|
29
29
|
```tsx
|
|
30
|
-
import {
|
|
30
|
+
import { W6WProvider } from "@w6w/react";
|
|
31
31
|
|
|
32
32
|
function App() {
|
|
33
33
|
return (
|
|
34
|
-
<
|
|
34
|
+
<W6WProvider baseUrl="https://api.example.com" token={() => getCurrentJwt()}>
|
|
35
35
|
<YourApp />
|
|
36
|
-
</
|
|
36
|
+
</W6WProvider>
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
```
|
|
@@ -41,13 +41,13 @@ function App() {
|
|
|
41
41
|
`token` accepts a literal string, or a supplier function called fresh on every
|
|
42
42
|
request — pass a supplier when your token rotates (e.g. a short-lived JWT read from
|
|
43
43
|
an auth SDK) and the client will pick up the new value on the very next call, with no
|
|
44
|
-
teardown/rebuild of the underlying `
|
|
44
|
+
teardown/rebuild of the underlying `W6WClient`. See `src/W6WProvider.tsx`'s module
|
|
45
45
|
header for the exact mechanism (the C-4 shim).
|
|
46
46
|
|
|
47
47
|
Then, anywhere under the provider:
|
|
48
48
|
|
|
49
49
|
```tsx
|
|
50
|
-
import { useDocuments,
|
|
50
|
+
import { useDocuments, useW6WClient } from "@w6w/react";
|
|
51
51
|
|
|
52
52
|
function DocList() {
|
|
53
53
|
const { data, loading, error, refetch } = useDocuments();
|
|
@@ -64,41 +64,41 @@ function DocList() {
|
|
|
64
64
|
## Using this package with `@w6w/ui`
|
|
65
65
|
|
|
66
66
|
`@w6w/ui`'s components (e.g. `AppPicker`, `ActionTestForm`, the flow editor) take a
|
|
67
|
-
`
|
|
68
|
-
`@w6w/react` client with `
|
|
67
|
+
`W6WApi` object through their own `<W6WUIProvider api={...}>`. Build one from your
|
|
68
|
+
`@w6w/react` client with `createW6WUiAdapter`:
|
|
69
69
|
|
|
70
70
|
```tsx
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
71
|
+
import { createW6WUiAdapter, useW6WClient, W6WProvider } from "@w6w/react";
|
|
72
|
+
import { W6WUIProvider, AppPicker } from "@w6w/ui";
|
|
73
73
|
|
|
74
74
|
function UiBridge({ children }: { children: React.ReactNode }) {
|
|
75
|
-
const client =
|
|
76
|
-
const api = useMemo(() =>
|
|
77
|
-
return <
|
|
75
|
+
const client = useW6WClient();
|
|
76
|
+
const api = useMemo(() => createW6WUiAdapter(client), [client]);
|
|
77
|
+
return <W6WUIProvider api={api}>{children}</W6WUIProvider>;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
function App() {
|
|
81
81
|
return (
|
|
82
|
-
<
|
|
82
|
+
<W6WProvider baseUrl="https://api.example.com" token={jwtSupplier}>
|
|
83
83
|
<UiBridge>
|
|
84
84
|
<AppPicker onPick={(appId) => console.log(appId)} />
|
|
85
85
|
</UiBridge>
|
|
86
|
-
</
|
|
86
|
+
</W6WProvider>
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
**`@w6w/ui` is not on npm today.** The `@w6w` scope holds only `@w6w/sdk` and
|
|
92
92
|
`@w6w/cli` at the time of writing (`npm view @w6w/ui` → 404); the source itself IS a
|
|
93
|
-
public GitHub repository (`w6w-io/w6w-ui`). `
|
|
93
|
+
public GitHub repository (`w6w-io/w6w-ui`). `createW6WUiAdapter`'s `W6WApi` return
|
|
94
94
|
type targets that contract *structurally* — this package names `@w6w/ui` nowhere in
|
|
95
95
|
its own manifest and needs no change whenever `@w6w/ui` becomes reachable another
|
|
96
96
|
way (this monorepo, a `git+https://` dependency on the public repo, or a private
|
|
97
97
|
registry). This is an honest statement of today's install story, not a promise that
|
|
98
98
|
`npm i @w6w/ui` resolves.
|
|
99
99
|
|
|
100
|
-
`
|
|
101
|
-
`packages/studio`'s own facade uses for these routes (`packages/ui/src/
|
|
100
|
+
`createW6WUiAdapter` is built entirely on `@w6w/sdk/console` — the SAME namespace
|
|
101
|
+
`packages/studio`'s own facade uses for these routes (`packages/ui/src/createW6WApi.ts`
|
|
102
102
|
is the *other* hand-rolled client for them; this package is not a third one).
|
|
103
103
|
**`client.console.*` is documented "Studio-internal… unstable" and is deliberately
|
|
104
104
|
excluded from `endpoints.json`'s conformance runner** (`node/src/client.ts:114-116`).
|
|
@@ -138,7 +138,7 @@ with only a `runId` and no public polling operation to follow it with —
|
|
|
138
138
|
surface described above, so this hook does not reach for it. Pass `wait: false`
|
|
139
139
|
explicitly if you genuinely want the queued-and-walk-away behaviour.
|
|
140
140
|
|
|
141
|
-
`
|
|
141
|
+
`useW6WClient()` returns the underlying `W6WClient` for anything not covered by a
|
|
142
142
|
hook (e.g. `client.console.*` directly, at your own risk per the caveat above).
|
|
143
143
|
|
|
144
144
|
## Known limitations
|
|
@@ -153,7 +153,7 @@ hook (e.g. `client.console.*` directly, at your own risk per the caveat above).
|
|
|
153
153
|
return type just gets no autocomplete for those extra fields.
|
|
154
154
|
- **`ActionTestForm.tsx:149,176`'s error handling cannot be satisfied from this
|
|
155
155
|
package.** `@w6w/ui`'s `ActionTestForm` does a NOMINAL `instanceof ApiError` check
|
|
156
|
-
against its OWN `ApiError` class (`packages/ui/src/
|
|
156
|
+
against its OWN `ApiError` class (`packages/ui/src/createW6WApi.ts`), not a
|
|
157
157
|
duck-typed one. No error object this adapter throws can ever satisfy that check
|
|
158
158
|
without importing `@w6w/ui`'s class directly, which this package's MIT/C-1
|
|
159
159
|
boundary forbids. Concretely: on a failed `invokeAction` used together with
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@w6w/react` — the package barrel.
|
|
3
3
|
*
|
|
4
|
-
* A thin React binding over `@w6w/sdk`: `<
|
|
5
|
-
* token-supplier shim), a small hook set, and `
|
|
6
|
-
* `@w6w/ui` `
|
|
4
|
+
* A thin React binding over `@w6w/sdk`: `<W6WProvider>` (the C-4
|
|
5
|
+
* token-supplier shim), a small hook set, and `createW6WUiAdapter` (the
|
|
6
|
+
* `@w6w/ui` `W6WApi` structural bridge, C-1/C-2). See `README.md` for the
|
|
7
7
|
* install + wrap-your-root example, the hooks catalog, and this lane's
|
|
8
8
|
* documented limitations.
|
|
9
9
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
export { VERSION } from "./src/version.ts";
|
|
16
|
-
export { type TokenSource,
|
|
16
|
+
export { type TokenSource, useW6WClient, W6WProvider, type W6WProviderProps, } from "./src/W6WProvider.tsx";
|
|
17
17
|
export { type MutationResult, type ReadResult, useConnections, useCreateDocument, useCreateVar, useDeleteDocument, useDeleteVar, useDocument, useDocumentByKey, useDocuments, useMe, useRun, useRunWorkflow, useUpdateDocument, useUpdateVar, useVar, useVars, useWorkflows, } from "./src/hooks.ts";
|
|
18
|
-
export {
|
|
18
|
+
export { createW6WUiAdapter, type W6WApi } from "./src/adapter.ts";
|
|
19
19
|
//# sourceMappingURL=mod.d.ts.map
|
package/dist/mod.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@w6w/react` — the package barrel.
|
|
3
3
|
*
|
|
4
|
-
* A thin React binding over `@w6w/sdk`: `<
|
|
5
|
-
* token-supplier shim), a small hook set, and `
|
|
6
|
-
* `@w6w/ui` `
|
|
4
|
+
* A thin React binding over `@w6w/sdk`: `<W6WProvider>` (the C-4
|
|
5
|
+
* token-supplier shim), a small hook set, and `createW6WUiAdapter` (the
|
|
6
|
+
* `@w6w/ui` `W6WApi` structural bridge, C-1/C-2). See `README.md` for the
|
|
7
7
|
* install + wrap-your-root example, the hooks catalog, and this lane's
|
|
8
8
|
* documented limitations.
|
|
9
9
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
export { VERSION } from "./src/version.js";
|
|
16
|
-
export {
|
|
16
|
+
export { useW6WClient, W6WProvider, } from "./src/W6WProvider.js";
|
|
17
17
|
export { useConnections, useCreateDocument, useCreateVar, useDeleteDocument, useDeleteVar, useDocument, useDocumentByKey, useDocuments, useMe, useRun, useRunWorkflow, useUpdateDocument, useUpdateVar, useVar, useVars, useWorkflows, } from "./src/hooks.js";
|
|
18
|
-
export {
|
|
18
|
+
export { createW6WUiAdapter } from "./src/adapter.js";
|
|
19
19
|
//# sourceMappingURL=mod.js.map
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `<
|
|
2
|
+
* `<W6WProvider>` — one `W6WClient` per `baseUrl`, with per-request token
|
|
3
3
|
* freshness (C-4).
|
|
4
4
|
*
|
|
5
|
-
* `@w6w/sdk`'s `
|
|
5
|
+
* `@w6w/sdk`'s `W6WClientOptions.token` (`node/src/config.ts:41-63`) is
|
|
6
6
|
* resolved ONCE, at construction, into `readonly` instance state
|
|
7
7
|
* (`node/src/client.ts:59`) — there is no supplier form. A naive
|
|
8
|
-
* `new
|
|
8
|
+
* `new W6WClient({ token })` therefore captures whatever `token` was at mount
|
|
9
9
|
* time and never sees a later rotation.
|
|
10
10
|
*
|
|
11
11
|
* The fix lives at the `fetch`-injection seam, not the `token` seam.
|
|
12
12
|
* `node/src/http.ts`'s `request()` builds `headers = new Headers(options.headers)`
|
|
13
13
|
* and then unconditionally `headers.set("authorization", ...)` BEFORE calling
|
|
14
14
|
* the injected `fetchImpl(url, {method, headers, body})` — `Headers.set`
|
|
15
|
-
* REPLACES, so a custom `fetch` passed to `new
|
|
15
|
+
* REPLACES, so a custom `fetch` passed to `new W6WClient({ fetch })` can read
|
|
16
16
|
* the CURRENT token and overwrite `authorization` on the `Headers` object it
|
|
17
17
|
* receives, immediately before delegating to the real transport. This
|
|
18
|
-
* provider therefore constructs its `
|
|
18
|
+
* provider therefore constructs its `W6WClient` ONCE, with a non-blank
|
|
19
19
|
* placeholder token (any non-blank string satisfies `requireToken`,
|
|
20
20
|
* `config.ts:229-237` — it is never actually sent, since the injected `fetch`
|
|
21
21
|
* always overwrites it first) and an injected `fetch` that resolves the
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
*
|
|
36
36
|
* @module
|
|
37
37
|
*/
|
|
38
|
-
import { type FetchLike,
|
|
38
|
+
import { type FetchLike, W6WClient } from "@w6w/sdk";
|
|
39
39
|
import { type ReactNode } from "react";
|
|
40
40
|
/** A static bearer token, or a supplier read fresh on every request. */
|
|
41
41
|
export type TokenSource = string | (() => string | null | undefined);
|
|
42
|
-
export interface
|
|
42
|
+
export interface W6WProviderProps {
|
|
43
43
|
/** The w6w server's origin, e.g. `"https://api.example.com"`. */
|
|
44
44
|
baseUrl: string;
|
|
45
45
|
/** A literal bearer token, or a supplier called fresh on every request. */
|
|
@@ -55,14 +55,14 @@ export interface W6wProviderProps {
|
|
|
55
55
|
children: ReactNode;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
* Provides one memoized `
|
|
58
|
+
* Provides one memoized `W6WClient` to every component under it. See this
|
|
59
59
|
* module's header for the C-4 token-freshness mechanism.
|
|
60
60
|
*/
|
|
61
|
-
export declare function
|
|
61
|
+
export declare function W6WProvider(props: W6WProviderProps): ReactNode;
|
|
62
62
|
/**
|
|
63
|
-
* Access the memoized `
|
|
64
|
-
* `<
|
|
65
|
-
* `
|
|
63
|
+
* Access the memoized `W6WClient`. Throws a helpful error if used outside a
|
|
64
|
+
* `<W6WProvider>` (mirrors `packages/ui/src/provider.tsx:249-258`'s
|
|
65
|
+
* `useW6WApi` shape — read-only reference, transcribed here, never imported).
|
|
66
66
|
*/
|
|
67
|
-
export declare function
|
|
68
|
-
//# sourceMappingURL=
|
|
67
|
+
export declare function useW6WClient(): W6WClient;
|
|
68
|
+
//# sourceMappingURL=W6WProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"W6WProvider.d.ts","sourceRoot":"","sources":["../../src/W6WProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,KAAK,SAAS,EAA8C,MAAM,OAAO,CAAC;AAEnF,wEAAwE;AACxE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAUrE,MAAM,WAAW,gBAAgB;IAC/B,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,KAAK,EAAE,WAAW,CAAC;IACnB;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,8FAA8F;IAC9F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAID;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CA8B9D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,SAAS,CASxC"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
/**
|
|
3
|
-
* `<
|
|
3
|
+
* `<W6WProvider>` — one `W6WClient` per `baseUrl`, with per-request token
|
|
4
4
|
* freshness (C-4).
|
|
5
5
|
*
|
|
6
|
-
* `@w6w/sdk`'s `
|
|
6
|
+
* `@w6w/sdk`'s `W6WClientOptions.token` (`node/src/config.ts:41-63`) is
|
|
7
7
|
* resolved ONCE, at construction, into `readonly` instance state
|
|
8
8
|
* (`node/src/client.ts:59`) — there is no supplier form. A naive
|
|
9
|
-
* `new
|
|
9
|
+
* `new W6WClient({ token })` therefore captures whatever `token` was at mount
|
|
10
10
|
* time and never sees a later rotation.
|
|
11
11
|
*
|
|
12
12
|
* The fix lives at the `fetch`-injection seam, not the `token` seam.
|
|
13
13
|
* `node/src/http.ts`'s `request()` builds `headers = new Headers(options.headers)`
|
|
14
14
|
* and then unconditionally `headers.set("authorization", ...)` BEFORE calling
|
|
15
15
|
* the injected `fetchImpl(url, {method, headers, body})` — `Headers.set`
|
|
16
|
-
* REPLACES, so a custom `fetch` passed to `new
|
|
16
|
+
* REPLACES, so a custom `fetch` passed to `new W6WClient({ fetch })` can read
|
|
17
17
|
* the CURRENT token and overwrite `authorization` on the `Headers` object it
|
|
18
18
|
* receives, immediately before delegating to the real transport. This
|
|
19
|
-
* provider therefore constructs its `
|
|
19
|
+
* provider therefore constructs its `W6WClient` ONCE, with a non-blank
|
|
20
20
|
* placeholder token (any non-blank string satisfies `requireToken`,
|
|
21
21
|
* `config.ts:229-237` — it is never actually sent, since the injected `fetch`
|
|
22
22
|
* always overwrites it first) and an injected `fetch` that resolves the
|
|
@@ -36,7 +36,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
36
36
|
*
|
|
37
37
|
* @module
|
|
38
38
|
*/
|
|
39
|
-
import {
|
|
39
|
+
import { W6WClient } from "@w6w/sdk";
|
|
40
40
|
import { createContext, useContext, useMemo, useRef } from "react";
|
|
41
41
|
/**
|
|
42
42
|
* Satisfies `requireToken` at construction so the client never throws a
|
|
@@ -47,10 +47,10 @@ import { createContext, useContext, useMemo, useRef } from "react";
|
|
|
47
47
|
const PLACEHOLDER_TOKEN = "w6w-react-unused-placeholder-token";
|
|
48
48
|
const Ctx = createContext(null);
|
|
49
49
|
/**
|
|
50
|
-
* Provides one memoized `
|
|
50
|
+
* Provides one memoized `W6WClient` to every component under it. See this
|
|
51
51
|
* module's header for the C-4 token-freshness mechanism.
|
|
52
52
|
*/
|
|
53
|
-
export function
|
|
53
|
+
export function W6WProvider(props) {
|
|
54
54
|
const { baseUrl, token, fetch: fetchOverride, project, children } = props;
|
|
55
55
|
// "Latest ref" pattern: kept in sync on every render, but never a `useMemo`
|
|
56
56
|
// dependency below — the injected `fetch` always reads the CURRENT prop
|
|
@@ -72,21 +72,21 @@ export function W6wProvider(props) {
|
|
|
72
72
|
const transport = fetchRef.current ?? ((i, ii) => globalThis.fetch(i, ii));
|
|
73
73
|
return transport(input, { ...init, headers });
|
|
74
74
|
};
|
|
75
|
-
return new
|
|
75
|
+
return new W6WClient({ baseUrl, token: PLACEHOLDER_TOKEN, project, fetch: injectedFetch });
|
|
76
76
|
}, [baseUrl, project]);
|
|
77
77
|
return _jsx(Ctx.Provider, { value: client, children: children });
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Access the memoized `
|
|
81
|
-
* `<
|
|
82
|
-
* `
|
|
80
|
+
* Access the memoized `W6WClient`. Throws a helpful error if used outside a
|
|
81
|
+
* `<W6WProvider>` (mirrors `packages/ui/src/provider.tsx:249-258`'s
|
|
82
|
+
* `useW6WApi` shape — read-only reference, transcribed here, never imported).
|
|
83
83
|
*/
|
|
84
|
-
export function
|
|
84
|
+
export function useW6WClient() {
|
|
85
85
|
const client = useContext(Ctx);
|
|
86
86
|
if (!client) {
|
|
87
|
-
throw new Error("
|
|
88
|
-
'Wrap your app root with <
|
|
87
|
+
throw new Error("useW6WClient must be used inside <W6WProvider>. " +
|
|
88
|
+
'Wrap your app root with <W6WProvider baseUrl="..." token="...">...</W6WProvider>.');
|
|
89
89
|
}
|
|
90
90
|
return client;
|
|
91
91
|
}
|
|
92
|
-
//# sourceMappingURL=
|
|
92
|
+
//# sourceMappingURL=W6WProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"W6WProvider.js","sourceRoot":"","sources":["../../src/W6WProvider.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAkB,SAAS,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAkB,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAKnF;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,oCAAoC,CAAC;AAkB/D,MAAM,GAAG,GAAG,aAAa,CAAmB,IAAI,CAAC,CAAC;AAElD;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAuB;IACjD,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAE1E,4EAA4E;IAC5E,wEAAwE;IACxE,0EAA0E;IAC1E,4EAA4E;IAC5E,uEAAuE;IACvE,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;IACzB,MAAM,QAAQ,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;IACvC,QAAQ,CAAC,OAAO,GAAG,aAAa,CAAC;IAEjC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE;QAC1B,MAAM,aAAa,GAAc,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC/C,MAAM,OAAO,GACX,OAAO,QAAQ,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;YACjF,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC3C,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,OAAO,EAAE,CAAC,CAAC;YACpD,CAAC;YACD,MAAM,SAAS,GACb,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC,CAAS,EAAE,EAAgB,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YACjF,OAAO,SAAS,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QAChD,CAAC,CAAC;QACF,OAAO,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;IAC7F,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAEvB,OAAO,KAAC,GAAG,CAAC,QAAQ,IAAC,KAAK,EAAE,MAAM,YAAG,QAAQ,GAAgB,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,kDAAkD;YAChD,mFAAmF,CACtF,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/src/adapter.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
3
|
-
* `@w6w/ui`'s `
|
|
2
|
+
* `createW6WUiAdapter` — a structurally-typed bridge from a `W6WClient` to
|
|
3
|
+
* `@w6w/ui`'s `W6WApi` contract (C-1, C-2).
|
|
4
4
|
*
|
|
5
|
-
* `
|
|
5
|
+
* `W6WApi` below is a HAND-DUPLICATE of `packages/ui/src/provider.tsx:87-231` —
|
|
6
6
|
* transcribed by hand, never imported. `@w6w/ui` is `SEE LICENSE IN LICENSE`
|
|
7
7
|
* and unpublished; this lane is MIT, so no dependency edge to it may exist
|
|
8
8
|
* anywhere, not even a type-only one (C-1). The VALUE types the interface
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* exceptions the SDK's own module headers document:
|
|
26
26
|
* - `listConnections` — see the comment at its call site below.
|
|
27
27
|
* - `recordTestRun` / `recordStepTestRun` — the SDK returns the real created
|
|
28
|
-
* row; `
|
|
28
|
+
* row; `W6WApi` is pinned `Promise<void>`. Discarded with
|
|
29
29
|
* `.then(() => undefined)`, mirroring
|
|
30
30
|
* `packages/studio/src/repos/saved-tests.ts:97-109` and
|
|
31
31
|
* `step-tests.ts:46-59` (read-only reference, transcribed, never imported).
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
*
|
|
38
38
|
* @module
|
|
39
39
|
*/
|
|
40
|
-
import { type ConnectionSummary, type
|
|
40
|
+
import { type ConnectionSummary, type W6WClient } from "@w6w/sdk";
|
|
41
41
|
import type { ActionDef, ApiCallRecord, AppSummary, AuthDef, InvokeOptions, SavedTest, StepTest, TestRunSummary } from "@w6w/sdk/console";
|
|
42
42
|
/**
|
|
43
|
-
* The `@w6w/ui` `
|
|
43
|
+
* The `@w6w/ui` `W6WApi` contract, hand-duplicated — see this module's
|
|
44
44
|
* header. Every member's signature mirrors `provider.tsx:87-231`'s member of
|
|
45
45
|
* the same name.
|
|
46
46
|
*/
|
|
47
|
-
export interface
|
|
47
|
+
export interface W6WApi {
|
|
48
48
|
/** List registered apps to pick from in the connection modal. */
|
|
49
49
|
listApps(): Promise<AppSummary[]>;
|
|
50
50
|
/** Load auth methods declared by an app's manifest, with availability flags. */
|
|
@@ -139,6 +139,6 @@ export interface W6wApi {
|
|
|
139
139
|
/** List the saved test fixtures for a workflow step. */
|
|
140
140
|
listStepTests(workflowId: string, stepId: string): Promise<StepTest[]>;
|
|
141
141
|
}
|
|
142
|
-
/** Build a `
|
|
143
|
-
export declare function
|
|
142
|
+
/** Build a `W6WApi` implementation over an existing `W6WClient`. See this module's header. */
|
|
143
|
+
export declare function createW6WUiAdapter(client: W6WClient): W6WApi;
|
|
144
144
|
//# sourceMappingURL=adapter.d.ts.map
|
package/dist/src/adapter.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
3
|
-
* `@w6w/ui`'s `
|
|
2
|
+
* `createW6WUiAdapter` — a structurally-typed bridge from a `W6WClient` to
|
|
3
|
+
* `@w6w/ui`'s `W6WApi` contract (C-1, C-2).
|
|
4
4
|
*
|
|
5
|
-
* `
|
|
5
|
+
* `W6WApi` below is a HAND-DUPLICATE of `packages/ui/src/provider.tsx:87-231` —
|
|
6
6
|
* transcribed by hand, never imported. `@w6w/ui` is `SEE LICENSE IN LICENSE`
|
|
7
7
|
* and unpublished; this lane is MIT, so no dependency edge to it may exist
|
|
8
8
|
* anywhere, not even a type-only one (C-1). The VALUE types the interface
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* exceptions the SDK's own module headers document:
|
|
26
26
|
* - `listConnections` — see the comment at its call site below.
|
|
27
27
|
* - `recordTestRun` / `recordStepTestRun` — the SDK returns the real created
|
|
28
|
-
* row; `
|
|
28
|
+
* row; `W6WApi` is pinned `Promise<void>`. Discarded with
|
|
29
29
|
* `.then(() => undefined)`, mirroring
|
|
30
30
|
* `packages/studio/src/repos/saved-tests.ts:97-109` and
|
|
31
31
|
* `step-tests.ts:46-59` (read-only reference, transcribed, never imported).
|
|
@@ -42,7 +42,7 @@ import { ApiError } from "@w6w/sdk";
|
|
|
42
42
|
* Alias `@w6w/sdk`'s `ApiError.raw` onto `.body` (`err.body === err.raw`, not
|
|
43
43
|
* a copy) before an error reaches the caller — the field name every
|
|
44
44
|
* duck-typing consumer of `@w6w/ui`'s own `ApiError` shape expects
|
|
45
|
-
* (`packages/ui/src/
|
|
45
|
+
* (`packages/ui/src/createW6WApi.ts:29-44`). `ApiError.name` is already
|
|
46
46
|
* `"ApiError"` on `@w6w/sdk`'s own class (`node/src/errors.ts`); nothing to
|
|
47
47
|
* add there.
|
|
48
48
|
*
|
|
@@ -67,8 +67,8 @@ async function withApiErrorBody(fn) {
|
|
|
67
67
|
throw err;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
/** Build a `
|
|
71
|
-
export function
|
|
70
|
+
/** Build a `W6WApi` implementation over an existing `W6WClient`. See this module's header. */
|
|
71
|
+
export function createW6WUiAdapter(client) {
|
|
72
72
|
return {
|
|
73
73
|
listApps: () => withApiErrorBody(() => client.console.apps.list()),
|
|
74
74
|
getAppAuth: (appId) => withApiErrorBody(() => client.console.apps.getAuth(appId)),
|
|
@@ -87,7 +87,7 @@ export function createW6wUiAdapter(client) {
|
|
|
87
87
|
createSavedTest: (connectionId, body) => withApiErrorBody(() => client.console.savedTests.create(connectionId, body)),
|
|
88
88
|
updateSavedTest: (connectionId, id, patch) => withApiErrorBody(() => client.console.savedTests.update(connectionId, id, patch)),
|
|
89
89
|
deleteSavedTest: (connectionId, id) => withApiErrorBody(() => client.console.savedTests.delete(connectionId, id)),
|
|
90
|
-
// The SDK returns the real created `SavedTestRun`; `
|
|
90
|
+
// The SDK returns the real created `SavedTestRun`; `W6WApi.recordTestRun`
|
|
91
91
|
// is pinned `Promise<void>` — discard, don't drop the call.
|
|
92
92
|
recordTestRun: (connId, body) => withApiErrorBody(() => client.console.savedTests.recordTestRun(connId, body).then(() => undefined)),
|
|
93
93
|
listTestRuns: (connectionId) => withApiErrorBody(() => client.console.savedTests.listTestRuns(connectionId)),
|
package/dist/src/hooks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The hook set — one small primitive underneath (`useAsync` / a private
|
|
3
3
|
* mutation primitive), every read/mutation hook a thin wrapper over
|
|
4
|
-
* `
|
|
4
|
+
* `useW6WClient()`. No react-query or any other data-fetching dependency
|
|
5
5
|
* anywhere (`package.json` carries none — see README).
|
|
6
6
|
*
|
|
7
7
|
* Built only over the PUBLIC, non-`console` surface (`me`, `documents`,
|
package/dist/src/hooks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { useW6WClient } from "./W6WProvider.js";
|
|
3
3
|
/**
|
|
4
4
|
* Shared plumbing behind every read hook: fetch once on mount, expose
|
|
5
5
|
* `refetch` for an imperative re-fetch, and drop a result that resolves after
|
|
@@ -66,72 +66,72 @@ function useMutationResource(mutator) {
|
|
|
66
66
|
}
|
|
67
67
|
// ── reads ────────────────────────────────────────────────────────────────
|
|
68
68
|
export function useMe() {
|
|
69
|
-
const client =
|
|
69
|
+
const client = useW6WClient();
|
|
70
70
|
const fetcher = useCallback(() => client.me(), [client]);
|
|
71
71
|
return useAsync(fetcher);
|
|
72
72
|
}
|
|
73
73
|
export function useDocuments(options) {
|
|
74
|
-
const client =
|
|
74
|
+
const client = useW6WClient();
|
|
75
75
|
const project = options?.project;
|
|
76
76
|
const fetcher = useCallback(() => client.documents.list(project === undefined ? undefined : { project }), [client, project]);
|
|
77
77
|
return useAsync(fetcher);
|
|
78
78
|
}
|
|
79
79
|
export function useDocument(id, options) {
|
|
80
|
-
const client =
|
|
80
|
+
const client = useW6WClient();
|
|
81
81
|
const project = options?.project;
|
|
82
82
|
const fetcher = useCallback(() => client.documents.get(id, project === undefined ? undefined : { project }), [client, id, project]);
|
|
83
83
|
return useAsync(fetcher);
|
|
84
84
|
}
|
|
85
85
|
export function useDocumentByKey(key, options) {
|
|
86
|
-
const client =
|
|
86
|
+
const client = useW6WClient();
|
|
87
87
|
const project = options?.project;
|
|
88
88
|
const fetcher = useCallback(() => client.documents.getByKey(key, project === undefined ? undefined : { project }), [client, key, project]);
|
|
89
89
|
return useAsync(fetcher);
|
|
90
90
|
}
|
|
91
91
|
export function useVars() {
|
|
92
|
-
const client =
|
|
92
|
+
const client = useW6WClient();
|
|
93
93
|
const fetcher = useCallback(() => client.vars.list(), [client]);
|
|
94
94
|
return useAsync(fetcher);
|
|
95
95
|
}
|
|
96
96
|
export function useVar(id) {
|
|
97
|
-
const client =
|
|
97
|
+
const client = useW6WClient();
|
|
98
98
|
const fetcher = useCallback(() => client.vars.get(id), [client, id]);
|
|
99
99
|
return useAsync(fetcher);
|
|
100
100
|
}
|
|
101
101
|
export function useConnections() {
|
|
102
|
-
const client =
|
|
102
|
+
const client = useW6WClient();
|
|
103
103
|
const fetcher = useCallback(() => client.connections.list(), [client]);
|
|
104
104
|
return useAsync(fetcher);
|
|
105
105
|
}
|
|
106
106
|
export function useWorkflows(options) {
|
|
107
|
-
const client =
|
|
107
|
+
const client = useW6WClient();
|
|
108
108
|
const project = options?.project;
|
|
109
109
|
const fetcher = useCallback(() => client.workflows.list(project === undefined ? undefined : { project }), [client, project]);
|
|
110
110
|
return useAsync(fetcher);
|
|
111
111
|
}
|
|
112
112
|
// ── mutations ────────────────────────────────────────────────────────────
|
|
113
113
|
export function useCreateDocument() {
|
|
114
|
-
const client =
|
|
114
|
+
const client = useW6WClient();
|
|
115
115
|
return useMutationResource((input, options) => client.documents.create(input, options));
|
|
116
116
|
}
|
|
117
117
|
export function useUpdateDocument() {
|
|
118
|
-
const client =
|
|
118
|
+
const client = useW6WClient();
|
|
119
119
|
return useMutationResource((id, patch, options) => client.documents.update(id, patch, options));
|
|
120
120
|
}
|
|
121
121
|
export function useDeleteDocument() {
|
|
122
|
-
const client =
|
|
122
|
+
const client = useW6WClient();
|
|
123
123
|
return useMutationResource((id, options) => client.documents.delete(id, options));
|
|
124
124
|
}
|
|
125
125
|
export function useCreateVar() {
|
|
126
|
-
const client =
|
|
126
|
+
const client = useW6WClient();
|
|
127
127
|
return useMutationResource((input) => client.vars.create(input));
|
|
128
128
|
}
|
|
129
129
|
export function useUpdateVar() {
|
|
130
|
-
const client =
|
|
130
|
+
const client = useW6WClient();
|
|
131
131
|
return useMutationResource((id, patch) => client.vars.update(id, patch));
|
|
132
132
|
}
|
|
133
133
|
export function useDeleteVar() {
|
|
134
|
-
const client =
|
|
134
|
+
const client = useW6WClient();
|
|
135
135
|
return useMutationResource((id) => client.vars.delete(id));
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
@@ -144,11 +144,11 @@ export function useDeleteVar() {
|
|
|
144
144
|
* explicitly; the default only fills in what the caller left unstated.
|
|
145
145
|
*/
|
|
146
146
|
export function useRunWorkflow() {
|
|
147
|
-
const client =
|
|
147
|
+
const client = useW6WClient();
|
|
148
148
|
return useMutationResource((id, options) => client.workflows.run(id, { ...options, wait: options?.wait ?? true }));
|
|
149
149
|
}
|
|
150
150
|
export function useRun() {
|
|
151
|
-
const client =
|
|
151
|
+
const client = useW6WClient();
|
|
152
152
|
return useMutationResource((input) => client.run(input));
|
|
153
153
|
}
|
|
154
154
|
//# sourceMappingURL=hooks.js.map
|
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w6w/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "React bindings for @w6w/sdk — a <
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "React bindings for @w6w/sdk — a <W6WProvider>, a small hook set, and a structural adapter for @w6w/ui's W6WApi contract.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"react": ">=18"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@w6w/sdk": "^0.
|
|
39
|
+
"@w6w/sdk": "^0.5.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@biomejs/biome": "^1.9.4",
|