@consciousclouds/activity-client 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,194 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative Works
92
+ a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works that
98
+ You distribute, all copyright, patent, trademark, and attribution
99
+ notices from the Source form of the Work, excluding those notices
100
+ that do not pertain to any part of the Derivative Works; and
101
+
102
+ (d) If the Work includes a "NOTICE" text file as part of its
103
+ distribution, You must include a readable copy of the attribution
104
+ notices contained within such NOTICE file, in at least one of the
105
+ following places: within a NOTICE text provided as part of the
106
+ Derivative Works; within the Source form or documentation, if
107
+ provided along with the Derivative Works; or, within a display
108
+ generated by the Derivative Works, if and wherever such third-party
109
+ notices normally appear. The contents of the NOTICE file are for
110
+ informational purposes only and do not modify the License. You may
111
+ add Your own attribution notices within Derivative Works that You
112
+ distribute, alongside or in addition to the NOTICE text from the
113
+ Work, provided that such additional attribution notices cannot be
114
+ construed as modifying the License.
115
+
116
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
117
+ any Contribution intentionally submitted for inclusion in the Work by
118
+ You to the Licensor shall be under the terms and conditions of this
119
+ License, without any additional terms or conditions.
120
+
121
+ 6. Trademarks. This License does not grant permission to use the trade
122
+ names, trademarks, service marks, or product names of the Licensor,
123
+ except as required for reasonable and customary use in describing the
124
+ origin of the Work and reproducing the content of the NOTICE file.
125
+
126
+ 7. Disclaimer of Warranty. Unless required by applicable law or
127
+ agreed to in writing, Licensor provides the Work (and each
128
+ Contributor provides its Contributions) on an "AS IS" BASIS,
129
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
130
+ implied, including, without limitation, any conditions of TITLE,
131
+ MERCHANTIBILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
132
+ responsible for determining the appropriateness of using or
133
+ redistributing the Work and assume any risks associated with Your
134
+ exercise of permissions under this License.
135
+
136
+ 8. Limitation of Liability. In no event and under no legal theory,
137
+ whether in tort (including negligence), contract, or otherwise,
138
+ unless required by applicable law (such as deliberate and grossly
139
+ negligent acts) or agreed to in writing, shall any Contributor be
140
+ liable to You for damages, including any direct, indirect, special,
141
+ incidental, or exemplary damages of any character arising as a result
142
+ of this License or out of the use or inability to use the Work
143
+ (including but not limited to damages for loss of goodwill, work
144
+ stoppage, computer failure or malfunction, or all other commercial
145
+ damages or losses), even if such Contributor has been advised of the
146
+ possibility of such damages.
147
+
148
+ 9. Accepting Warranty or Liability. While redistributing the Work or
149
+ Derivative Works thereof, You may choose to offer, and charge a fee
150
+ for, acceptance of support, warranty, indemnity, or other liability
151
+ obligations and/or rights consistent with this License. However, in
152
+ accepting such obligations, You may offer such obligations only on
153
+ Your own behalf and on Your sole responsibility, not on behalf of any
154
+ other Contributor, and only if You agree to indemnify, defend, and
155
+ hold each Contributor harmless for any liability incurred by, or
156
+ claims asserted against, such Contributor by reason of your accepting
157
+ any such warranty or additional liability.
158
+
159
+ Copyright 2024 Conscious Clouds
160
+
161
+ Licensed under the Apache License, Version 2.0 (the "License");
162
+ you may not use this file except in compliance with the License.
163
+ You may obtain a copy of the License at
164
+
165
+ http://www.apache.org/licenses/LICENSE-2.0
166
+
167
+ Unless required by applicable law or agreed to in writing, software
168
+ distributed under the License is distributed on an "AS IS" BASIS,
169
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170
+ See the License for the specific language governing permissions and
171
+ limitations under the License.
172
+
173
+ ---
174
+
175
+ Portions of this package are derived from shadcn/ui (https://ui.shadcn.com),
176
+ Copyright (c) 2023 shadcn, licensed under the MIT License:
177
+
178
+ Permission is hereby granted, free of charge, to any person obtaining a copy
179
+ of this software and associated documentation files (the "Software"), to deal
180
+ in the Software without restriction, including without limitation the rights
181
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
182
+ copies of the Software, and to permit persons to whom the Software is
183
+ furnished to do so, subject to the following conditions:
184
+
185
+ The above copyright notice and this permission notice shall be included in all
186
+ copies or substantial portions of the Software.
187
+
188
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
189
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
190
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
191
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
192
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
193
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
194
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # @consciousclouds/activity-client
2
2
 
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.
3
+ The **product-neutral consumer transport** for the Eventing plane's live-activity feed.
4
+
5
+ Graduated out of `consciousclouds-admin` (Stage 9 Wave B) so **any** enrolled product
6
+ can consume the feed **without importing admin internals**. Three thin layers:
7
+
8
+ - **types** — the activity **wire** types (`ActivityItem`, `ActivityRecentResponse`).
9
+ - **client** — the two same-origin BFF wrappers: `fetchRecentActivity` (the durable
10
+ recovery view over `<base>/recent`) and `streamActivity` (the live SSE tail over
11
+ `<base>/stream`). Base path defaults to `/api/activity`; override via `basePath`.
12
+ - **hook** — `useActivityFeed`, the read model: durable recovery seed → live prepend →
13
+ resume-from-cursor → `event_id` dedupe, with **explicit** (never silent) degradation.
14
+
15
+ ## SDK-law boundary
16
+
17
+ Types + thin HTTP wrappers + a framework-thin read model. What stays **product-owned**:
18
+
19
+ - The **BFF routes** (`<base>/recent`, `<base>/stream`) — the server proxy to the
20
+ Operator Gateway with operator auth. This package never opens a cross-origin call,
21
+ never carries a gateway URL, never holds a credential.
22
+ - The **enablement flag** — deployment config (e.g. a `NEXT_PUBLIC_*` env). The product
23
+ computes it and passes `enabled`; the hook never reads a framework env.
24
+
25
+ ## Usage
26
+
27
+ ```ts
28
+ import { useActivityFeed } from "@consciousclouds/activity-client";
29
+
30
+ // A product computes its own flag (here a Next public env) and injects it.
31
+ const enabled =
32
+ (process.env.NEXT_PUBLIC_ACTIVITY_LIVE ?? "true") !== "false" &&
33
+ (process.env.NEXT_PUBLIC_ACTIVITY_LIVE ?? "true") !== "0";
34
+
35
+ const feed = useActivityFeed({ enabled }); // default basePath: /api/activity
36
+ // or point at a product's own proxy routes:
37
+ const feed2 = useActivityFeed({ enabled, basePath: "/eno/api/activity" });
38
+ ```
39
+
40
+ ## Design references
41
+
42
+ - `eventing-plane-lock` §4/§7/§11 — the envelope, the idempotent read model, recovery.
43
+ - `docs/design/universal-adoption-doctrine.md` — a second product consumes it unchanged.
@@ -0,0 +1,32 @@
1
+ import type { ActivityItem, ActivityRecentResponse } from "./types.js";
2
+ /**
3
+ * The conventional same-origin BFF prefix. A product implements `<base>/recent`
4
+ * and `<base>/stream` as its own server proxy to the Operator Gateway; override
5
+ * via the `basePath` option when the product mounts them elsewhere.
6
+ */
7
+ export declare const DEFAULT_ACTIVITY_BASE_PATH = "/api/activity";
8
+ /**
9
+ * Fetch the DURABLE RECOVERY view (`<base>/recent`). Throws on non-2xx /
10
+ * unreachable so the read model can fall to its degraded state — never a
11
+ * misleading empty feed.
12
+ */
13
+ export declare function fetchRecentActivity(opts?: {
14
+ basePath?: string;
15
+ signal?: AbortSignal;
16
+ }): Promise<ActivityRecentResponse>;
17
+ /**
18
+ * Open the LIVE SSE tail (`<base>/stream`), resuming after `fromCursor` when given.
19
+ * Reads with the house `parseSseFrames`; each `activity` frame is parsed and handed
20
+ * to `onItem`. Calls `onOpen` once the upstream response is OK (the "connection is
21
+ * live" signal). Resolves when the stream ends; throws on a non-OK response (the read
22
+ * model maps that to a reconnect). An aborted read (unmount/reconnect) rejects with an
23
+ * AbortError, which the read model swallows.
24
+ */
25
+ export declare function streamActivity(opts: {
26
+ fromCursor: number | null;
27
+ onItem: (item: ActivityItem) => void;
28
+ onOpen?: () => void;
29
+ signal: AbortSignal;
30
+ basePath?: string;
31
+ }): Promise<void>;
32
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEvE;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,kBAAkB,CAAC;AAK1D;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACrD,OAAO,CAAC,sBAAsB,CAAC,CASjC;AAYD;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE;IACzC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BhB"}
package/dist/client.js ADDED
@@ -0,0 +1,99 @@
1
+ import { fetchWithoutRedirects } from './redirect.js';
2
+ /**
3
+ * The activity TRANSPORT — the product side of the LIVE ACTIVITY seam (the read
4
+ * dual of a turn transport, for the Eventing plane's first consumer). This module
5
+ * owns the wire: the two same-origin BFF routes (`<base>/recent` — the durable
6
+ * recovery view; `<base>/stream` — the live SSE tail), the parse of the gateway's
7
+ * SSE frames, and nothing else. The read-model grammar (dedupe by event_id, cursor
8
+ * tracking, reconnect) lives in the hook (use-activity-feed.ts); the presentation
9
+ * vocabulary lives in the product's widget — never here.
10
+ *
11
+ * PRODUCT-NEUTRAL BY CONSTRUCTION (SDK-law: thin HTTP wrappers, no product meaning).
12
+ * The base path defaults to the conventional `/api/activity` same-origin BFF prefix,
13
+ * but any enrolled product may point it at its OWN proxy routes via `basePath` — so
14
+ * a second product consumes this transport unchanged, without importing another
15
+ * product's routes. The BFF itself (the server proxy to the Operator Gateway with
16
+ * operator auth) stays product-owned: this module never opens a cross-origin call,
17
+ * never carries a gateway URL, never holds a credential.
18
+ *
19
+ * The recovery view is what SURVIVES a page reload (eventing-plane-lock §11: "a
20
+ * missed event must always be recoverable from durable truth"); the stream PREPENDS
21
+ * live events on top of it. The BFF relays the gateway's SSE byte-for-byte, so frames
22
+ * are already `id: <cursor>\nevent: activity\ndata: {...}` — we reuse conductor-sdk's
23
+ * `parseSseFrames` (the house SSE reader; keepalive comments are skipped by it)
24
+ * rather than the browser EventSource API, matching the fetch-stream turn posture.
25
+ */
26
+ import { parseSseFrames } from "@consciousclouds/conductor-sdk";
27
+ /**
28
+ * The conventional same-origin BFF prefix. A product implements `<base>/recent`
29
+ * and `<base>/stream` as its own server proxy to the Operator Gateway; override
30
+ * via the `basePath` option when the product mounts them elsewhere.
31
+ */
32
+ export const DEFAULT_ACTIVITY_BASE_PATH = "/api/activity";
33
+ const recentUrl = (basePath) => `${basePath}/recent`;
34
+ const streamUrl = (basePath) => `${basePath}/stream`;
35
+ /**
36
+ * Fetch the DURABLE RECOVERY view (`<base>/recent`). Throws on non-2xx /
37
+ * unreachable so the read model can fall to its degraded state — never a
38
+ * misleading empty feed.
39
+ */
40
+ export async function fetchRecentActivity(opts = {}) {
41
+ const basePath = opts.basePath ?? DEFAULT_ACTIVITY_BASE_PATH;
42
+ const res = await fetchWithoutRedirects(recentUrl(basePath), { cache: "no-store", signal: opts.signal });
43
+ if (!res.ok)
44
+ throw new Error(`activity/recent returned ${res.status}`);
45
+ const body = (await res.json());
46
+ return {
47
+ cursor: typeof body.cursor === "number" ? body.cursor : 0,
48
+ activity: Array.isArray(body.activity) ? body.activity : [],
49
+ };
50
+ }
51
+ /** A malformed `activity` frame is one that does not parse to an item carrying an `event_id`. */
52
+ function toActivityItem(data) {
53
+ try {
54
+ const item = JSON.parse(data || "{}");
55
+ return typeof item?.event_id === "string" && item.event_id ? item : null;
56
+ }
57
+ catch {
58
+ return null;
59
+ }
60
+ }
61
+ /**
62
+ * Open the LIVE SSE tail (`<base>/stream`), resuming after `fromCursor` when given.
63
+ * Reads with the house `parseSseFrames`; each `activity` frame is parsed and handed
64
+ * to `onItem`. Calls `onOpen` once the upstream response is OK (the "connection is
65
+ * live" signal). Resolves when the stream ends; throws on a non-OK response (the read
66
+ * model maps that to a reconnect). An aborted read (unmount/reconnect) rejects with an
67
+ * AbortError, which the read model swallows.
68
+ */
69
+ export async function streamActivity(opts) {
70
+ const base = streamUrl(opts.basePath ?? DEFAULT_ACTIVITY_BASE_PATH);
71
+ const url = opts.fromCursor != null ? `${base}?cursor=${encodeURIComponent(opts.fromCursor)}` : base;
72
+ const res = await fetchWithoutRedirects(url, {
73
+ headers: { Accept: "text/event-stream" },
74
+ signal: opts.signal,
75
+ });
76
+ if (!res.ok || !res.body) {
77
+ throw new Error(`activity/stream returned ${res.status}`);
78
+ }
79
+ opts.onOpen?.();
80
+ const reader = res.body.getReader();
81
+ const decoder = new TextDecoder();
82
+ let buffer = "";
83
+ for (;;) {
84
+ const { done, value } = await reader.read();
85
+ if (done)
86
+ break;
87
+ buffer += decoder.decode(value, { stream: true });
88
+ const { frames, rest } = parseSseFrames(buffer);
89
+ buffer = rest;
90
+ for (const frame of frames) {
91
+ if (frame.event !== "activity")
92
+ continue;
93
+ const item = toActivityItem(frame.data);
94
+ if (item)
95
+ opts.onItem(item);
96
+ }
97
+ }
98
+ }
99
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAIhE;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,eAAe,CAAC;AAE1D,MAAM,SAAS,GAAG,CAAC,QAAgB,EA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,CAAC,KAAK,KAAK,UAAU;gBAAE,SAAS;YACzC,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACxC,IAAI,IAAI;gBAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @consciousclouds/activity-client — the product-neutral consumer transport for the
3
+ * Eventing plane's live-activity feed.
4
+ *
5
+ * Graduated out of consciousclouds-admin (Stage 9 Wave B) so ANY enrolled product can
6
+ * consume the feed without importing admin internals. Three thin layers:
7
+ *
8
+ * - types — the activity WIRE types (ActivityItem, ActivityRecentResponse).
9
+ * - client — the two same-origin BFF wrappers (fetchRecentActivity over `<base>/recent`,
10
+ * streamActivity over the SSE `<base>/stream`), base path configurable.
11
+ * - hook — the useActivityFeed read model (durable recovery seed + live prepend +
12
+ * resume-from-cursor + event_id dedupe), framework-thin.
13
+ *
14
+ * SDK-law: types + thin HTTP wrappers + a framework-thin read model. The BFF routes,
15
+ * the Operator-Gateway URL, and the credentials posture stay PRODUCT-owned; the
16
+ * enablement flag is product/deployment config the product passes as `enabled`.
17
+ */
18
+ export type { ActivityItem, ActivityRecentResponse } from "./types.js";
19
+ export { DEFAULT_ACTIVITY_BASE_PATH, fetchRecentActivity, streamActivity, } from "./client.js";
20
+ export { useActivityFeed } from "./use-activity-feed.js";
21
+ export type { ActivityConnection, ActivityFeedState, UseActivityFeedOptions, } from "./use-activity-feed.js";
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,YAAY,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @consciousclouds/activity-client — the product-neutral consumer transport for the
3
+ * Eventing plane's live-activity feed.
4
+ *
5
+ * Graduated out of consciousclouds-admin (Stage 9 Wave B) so ANY enrolled product can
6
+ * consume the feed without importing admin internals. Three thin layers:
7
+ *
8
+ * - types — the activity WIRE types (ActivityItem, ActivityRecentResponse).
9
+ * - client — the two same-origin BFF wrappers (fetchRecentActivity over `<base>/recent`,
10
+ * streamActivity over the SSE `<base>/stream`), base path configurable.
11
+ * - hook — the useActivityFeed read model (durable recovery seed + live prepend +
12
+ * resume-from-cursor + event_id dedupe), framework-thin.
13
+ *
14
+ * SDK-law: types + thin HTTP wrappers + a framework-thin read model. The BFF routes,
15
+ * the Operator-Gateway URL, and the credentials posture stay PRODUCT-owned; the
16
+ * enablement flag is product/deployment config the product passes as `enabled`.
17
+ */
18
+ export { DEFAULT_ACTIVITY_BASE_PATH, fetchRecentActivity, streamActivity, } from "./client.js";
19
+ export { useActivityFeed } from "./use-activity-feed.js";
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /** A redirect response was refused before forwarding credentials to its target. */
2
+ export declare class RedirectRefusedError extends Error {
3
+ readonly code = "REDIRECT_REFUSED";
4
+ constructor();
5
+ }
6
+ type RedirectResponse = {
7
+ status: number;
8
+ type?: string;
9
+ body?: ReadableStream | null;
10
+ };
11
+ export declare function refuseRedirect(response: RedirectResponse): Promise<void>;
12
+ export declare function fetchWithoutRedirects(input: string | URL | Request, options?: RequestInit, fetchImpl?: (input: string | URL | Request, options?: RequestInit) => Promise<Response>): Promise<Response>;
13
+ export {};
14
+ //# sourceMappingURL=redirect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../src/redirect.ts"],"names":[],"mappings":"AAGA,mFAAmF;AACnF,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,sBAAsB;;CAMpC;AAED,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,wBAAsB,cAAc,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAK9E;AAED,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAC7B,OAAO,CAAC,EAAE,WAAW,EACrB,SAAS,GAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAS,GAC7F,OAAO,CAAC,QAAQ,CAAC,CAInB"}
@@ -0,0 +1,22 @@
1
+ // Generated by scripts/generate_frontend_sdk_transport.py.
2
+ // Edit the source under platform/frontend/shared-sdk-transport.
3
+ /** A redirect response was refused before forwarding credentials to its target. */
4
+ export class RedirectRefusedError extends Error {
5
+ constructor() {
6
+ super('HTTP redirect refused');
7
+ this.code = 'REDIRECT_REFUSED';
8
+ this.name = 'RedirectRefusedError';
9
+ }
10
+ }
11
+ export async function refuseRedirect(response) {
12
+ if (response.type === 'opaqueredirect' || (response.status >= 300 && response.status < 400)) {
13
+ await response.body?.cancel().catch(() => undefined);
14
+ throw new RedirectRefusedError();
15
+ }
16
+ }
17
+ export async function fetchWithoutRedirects(input, options, fetchImpl = fetch) {
18
+ const response = await fetchImpl(input, { ...options, redirect: 'manual' });
19
+ await refuseRedirect(response);
20
+ return response;
21
+ }
22
+ //# sourceMappingURL=redirect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect.js","sourceRoot":"","sources":["../src/redirect.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,gEAAgE;AAEhE,mFAAmF;AACnF,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAG7C;QACE,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAHxB,SAAI,GAAG,kBAAkB,CAAC;QAIjC,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAQD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAA0B;IAC7D,IAAI,QAAQ,CAAC,IAAI,KAAK,gBAAgB,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC,EAAE,CAAC;QAC5F,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACrD,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,KAA6B,EAC7B,OAAqB,EACrB,YAAyF,KAAK;IAE9F,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC5E,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC/B,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The activity WIRE TYPES — the Eventing plane's v2 envelope, client projection
3
+ * (eventing-plane-lock §4). By-reference only: ids + labels, never bodies; the
4
+ * owner coordinate is filtered out server-side by the scoped bridge (§6) and never
5
+ * appears here. Pure data — no transport, no framework.
6
+ */
7
+ /**
8
+ * One activity notification as it crosses the wire.
9
+ */
10
+ export interface ActivityItem {
11
+ /** The durable cursor — monotonic; the resume coordinate (Last-Event-ID equivalent). */
12
+ cursor: number;
13
+ /** Producer-minted uuid — the idempotency key the read model dedupes on (§7). */
14
+ event_id: string;
15
+ /** Catalog-registered event type, e.g. "EpisodeCreated" (§5). */
16
+ event_type: string;
17
+ /** The enrollment project of the origin plane (§4). */
18
+ project: string;
19
+ /** The origin record's classification (§4). */
20
+ classification: string;
21
+ /** The ledger handle — turn key / run id / decision id (§4 correlation). */
22
+ correlation: string;
23
+ /** A human-readable one-line summary the bridge derived for the feed. */
24
+ label: string;
25
+ /** The truth's moment, from the ledger (ISO-8601). */
26
+ occurred_at: string;
27
+ }
28
+ /** The durable recovery payload the recent BFF relays. */
29
+ export interface ActivityRecentResponse {
30
+ /** The highest cursor in this window — the floor a subsequent stream resumes from. */
31
+ cursor: number;
32
+ activity: ActivityItem[];
33
+ }
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,wFAAwF;IACxF,MAAM,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,QAAQ,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,cAAc,EAAE,MAAM,CAAC;IACvB,4EAA4E;IAC5E,WAAW,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,0DAA0D;AAC1D,MAAM,WAAW,sBAAsB;IACrC,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The activity WIRE TYPES — the Eventing plane's v2 envelope, client projection
3
+ * (eventing-plane-lock §4). By-reference only: ids + labels, never bodies; the
4
+ * owner coordinate is filtered out server-side by the scoped bridge (§6) and never
5
+ * appears here. Pure data — no transport, no framework.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,25 @@
1
+ import type { ActivityItem } from "./types.js";
2
+ /** Health of the live SSE connection (independent of whether durable data is present). */
3
+ export type ActivityConnection = "connecting" | "live" | "reconnecting" | "offline";
4
+ export interface ActivityFeedState {
5
+ /** The read model — newest first (highest cursor first), capped for the DOM. */
6
+ items: ActivityItem[];
7
+ connection: ActivityConnection;
8
+ /** True once the durable recovery view has loaded at least once (reseeds on every mount/reload). */
9
+ recovered: boolean;
10
+ /** True when the live source is entirely unavailable (recovery failed with nothing durable, or disabled)
11
+ * → the widget shows its degraded derived fallback with a visible indicator. */
12
+ degraded: boolean;
13
+ /** Last transport error (for the degraded detail line). */
14
+ error?: string;
15
+ }
16
+ /** Options — all optional; the product injects its own flag + BFF base path. */
17
+ export interface UseActivityFeedOptions {
18
+ /** Whether the live feed is on. Product/deployment config (default true). When false the stream is never
19
+ * opened and the widget shows its degraded derived fallback. */
20
+ enabled?: boolean;
21
+ /** The product's same-origin BFF prefix (default `/api/activity`). */
22
+ basePath?: string;
23
+ }
24
+ export declare function useActivityFeed(options?: UseActivityFeedOptions): ActivityFeedState;
25
+ //# sourceMappingURL=use-activity-feed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-activity-feed.d.ts","sourceRoot":"","sources":["../src/use-activity-feed.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,0FAA0F;AAC1F,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,MAAM,GAAG,cAAc,GAAG,SAAS,CAAC;AAEpF,MAAM,WAAW,iBAAiB;IAChC,gFAAgF;IAChF,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,oGAAoG;IACpG,SAAS,EAAE,OAAO,CAAC;IACnB;oFACgF;IAChF,QAAQ,EAAE,OAAO,CAAC;IAClB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,gFAAgF;AAChF,MAAM,WAAW,sBAAsB;IACrC;oEACgE;IAChE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAWD,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,iBAAiB,CAwHvF"}
@@ -0,0 +1,166 @@
1
+ "use client";
2
+ /**
3
+ * useActivityFeed — the READ-MODEL grammar for the live activity feed
4
+ * (eventing-plane-lock §7: a consumer's derived read model, idempotent by law). The
5
+ * transport (client.ts) owns the wire; THIS hook owns the discipline the lock names:
6
+ *
7
+ * (a) DURABLE RECOVERY SEED — on mount it fetches `<base>/recent`, the view that
8
+ * survives a page reload (§11: "a missed event must always be recoverable from
9
+ * durable truth"). This is the floor.
10
+ * (b) LIVE TAIL — it then opens the SSE stream and PREPENDS live events on top of
11
+ * the recovery seed.
12
+ * (c) RESUME WITHOUT A GAP — on disconnect it resumes from the last cursor (the
13
+ * Last-Event-ID equivalent); if it cannot prove where to resume (no cursor yet),
14
+ * it refetches recent FIRST, then streams — never a silent gap.
15
+ * (d) DEDUPE BY event_id — a live event already present in the recovery seed is
16
+ * dropped, never doubled (§7: a counting/appending read model dedupes durably).
17
+ *
18
+ * Degradation is EXPLICIT, never silent: if the recovery view itself is unavailable
19
+ * (or the feed is disabled) and there is nothing durable to show, `degraded` flips so
20
+ * the widget falls back to its derived feed with a visible indicator. A working
21
+ * recovery view with a dead stream is NOT fully degraded — the durable list stays,
22
+ * `connection` reports `offline`, and the widget shows a "live unavailable" note.
23
+ *
24
+ * PRODUCT-NEUTRAL: the enablement FLAG is product/deployment config (e.g. a
25
+ * `NEXT_PUBLIC_*` env in a Next app), so the product computes it and passes `enabled`;
26
+ * the hook never reads a framework env. `basePath` selects the product's own BFF
27
+ * routes (defaults to the conventional `/api/activity`). Framework-thin: one React
28
+ * effect + refs; no product meaning, no transport of its own.
29
+ */
30
+ import { useEffect, useRef, useState } from "react";
31
+ import { fetchRecentActivity, streamActivity } from "./client.js";
32
+ /** Cap the in-DOM feed; deep history lives in the durable recovery view, not the browser. */
33
+ const MAX_ITEMS = 200;
34
+ /** Reconnect backoff (ms) and the attempt count after which we report `offline`. */
35
+ const BASE_BACKOFF_MS = 1000;
36
+ const MAX_BACKOFF_MS = 15000;
37
+ const OFFLINE_AFTER_ATTEMPTS = 4;
38
+ const errMsg = (e) => (e instanceof Error ? e.message : String(e));
39
+ export function useActivityFeed(options = {}) {
40
+ const enabled = options.enabled ?? true;
41
+ const basePath = options.basePath;
42
+ const [state, setState] = useState({
43
+ items: [],
44
+ connection: "connecting",
45
+ recovered: false,
46
+ degraded: false,
47
+ });
48
+ // Refs are the authoritative source the async loop reads (no stale closures across reconnects).
49
+ const itemsRef = useRef([]);
50
+ const cursorRef = useRef(null);
51
+ const streamAbortRef = useRef(null);
52
+ useEffect(() => {
53
+ // Disabled → explicit degraded (the widget shows the derived fallback). Never open the stream.
54
+ if (!enabled) {
55
+ setState((s) => ({ ...s, degraded: true, connection: "offline" }));
56
+ return;
57
+ }
58
+ let cancelled = false;
59
+ let reconnectTimer = null;
60
+ let attempts = 0;
61
+ /** Merge fresh items (deduped by event_id) into the newest-first, capped read model. */
62
+ function applyIncoming(incoming) {
63
+ if (incoming.length === 0)
64
+ return;
65
+ const known = new Set(itemsRef.current.map((i) => i.event_id));
66
+ const fresh = incoming.filter((i) => !known.has(i.event_id)); // (d) dedupe by event_id
67
+ if (fresh.length === 0)
68
+ return;
69
+ const merged = [...fresh, ...itemsRef.current]
70
+ .sort((a, b) => b.cursor - a.cursor)
71
+ .slice(0, MAX_ITEMS);
72
+ itemsRef.current = merged;
73
+ cursorRef.current = merged.length ? merged[0].cursor : cursorRef.current;
74
+ setState((s) => ({ ...s, items: merged }));
75
+ }
76
+ /** (a) Durable recovery. Returns true when the durable truth was reached. */
77
+ async function recover() {
78
+ try {
79
+ const res = await fetchRecentActivity({ basePath });
80
+ if (cancelled)
81
+ return true;
82
+ applyIncoming(res.activity);
83
+ setState((s) => ({ ...s, recovered: true, degraded: false, error: undefined }));
84
+ return true;
85
+ }
86
+ catch (err) {
87
+ if (cancelled)
88
+ return false;
89
+ // Recovery unreachable: degrade ONLY if we have nothing durable to show (never silently blank).
90
+ setState((s) => ({ ...s, degraded: itemsRef.current.length === 0, error: errMsg(err) }));
91
+ return false;
92
+ }
93
+ }
94
+ /** (b) Live tail, resuming from the last cursor when present. */
95
+ async function runStream() {
96
+ const ac = new AbortController();
97
+ streamAbortRef.current = ac;
98
+ try {
99
+ await streamActivity({
100
+ fromCursor: cursorRef.current,
101
+ basePath,
102
+ onItem: (item) => {
103
+ if (!cancelled)
104
+ applyIncoming([item]);
105
+ },
106
+ onOpen: () => {
107
+ if (cancelled)
108
+ return;
109
+ attempts = 0;
110
+ setState((s) => ({ ...s, connection: "live", degraded: false, error: undefined }));
111
+ },
112
+ signal: ac.signal,
113
+ });
114
+ // The server closed the stream — treat a clean end as a reconnect trigger (resume from cursor).
115
+ if (!cancelled)
116
+ scheduleReconnect();
117
+ }
118
+ catch (err) {
119
+ if (cancelled)
120
+ return;
121
+ if (err instanceof DOMException && err.name === "AbortError")
122
+ return; // unmount/reconnect abort
123
+ setState((s) => ({ ...s, error: errMsg(err) }));
124
+ scheduleReconnect();
125
+ }
126
+ }
127
+ /** (c) Backoff reconnect. Resume from cursor; if none, recover FIRST so no gap is silently skipped. */
128
+ function scheduleReconnect() {
129
+ if (cancelled)
130
+ return;
131
+ setState((s) => ({
132
+ ...s,
133
+ connection: attempts >= OFFLINE_AFTER_ATTEMPTS ? "offline" : "reconnecting",
134
+ }));
135
+ const delay = Math.min(MAX_BACKOFF_MS, BASE_BACKOFF_MS * 2 ** attempts);
136
+ attempts += 1;
137
+ reconnectTimer = setTimeout(() => {
138
+ void (async () => {
139
+ if (cancelled)
140
+ return;
141
+ if (cursorRef.current == null)
142
+ await recover(); // continuity unprovable → reseed durable truth
143
+ if (cancelled)
144
+ return;
145
+ void runStream();
146
+ })();
147
+ }, delay);
148
+ }
149
+ // Initial run: durable recovery seed, THEN the live tail.
150
+ void (async () => {
151
+ setState((s) => ({ ...s, connection: "connecting" }));
152
+ await recover();
153
+ if (cancelled)
154
+ return;
155
+ void runStream();
156
+ })();
157
+ return () => {
158
+ cancelled = true;
159
+ if (reconnectTimer)
160
+ clearTimeout(reconnectTimer);
161
+ streamAbortRef.current?.abort();
162
+ };
163
+ }, [enabled, basePath]);
164
+ return state;
165
+ }
166
+ //# sourceMappingURL=use-activity-feed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-activity-feed.js","sourceRoot":"","sources":["../src/use-activity-feed.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA4BlE,6FAA6F;AAC7F,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,oFAAoF;AACpF,MAAM,eAAe,GAAG,IAAK,CAAC;AAC9B,MAAM,cAAc,GAAG,KAAM,CAAC;AAC9B,MAAM,sB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AChB,IAAI,SAAS;gBAAE,OAAO;YACtB,KAAK,SAAS,EAAE,CAAC;QACnB,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,IAAI,cAAc;gBAAE,YAAY,CAAC,cAAc,CAAC,CAAC;YACjD,cAAc,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QAClC,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAExB,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@consciousclouds/activity-client",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.2",
4
+ "description": "ConsciousClouds Activity Client \u2014 the product-neutral consumer transport for the Eventing plane's live-activity feed. Wire types (ActivityItem, ActivityRecentResponse), the two thin same-origin BFF wrappers (fetchRecentActivity over /recent, streamActivity over the SSE /stream \u2014 base path configurable), and the useActivityFeed read-model hook (durable recovery seed + live prepend + resume-from-cursor + event_id dedupe). SDK-law: types + thin HTTP wrappers + a framework-thin read model; the BFF routes, gateway URL, and credentials posture stay product-owned. Graduated out of consciousclouds-admin so any enrolled product can consume the feed without importing admin internals.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.build.json",
22
+ "clean": "rm -rf dist",
23
+ "test": "bun test",
24
+ "type-check": "tsc --noEmit",
25
+ "prepublishOnly": "bun run clean && bun run build && bun run type-check"
26
+ },
27
+ "dependencies": {
28
+ "@consciousclouds/conductor-sdk": "^0.1.0"
29
+ },
30
+ "peerDependencies": {
31
+ "react": ">=18.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@happy-dom/global-registrator": "^20.10.3",
35
+ "@types/react": "^19.2.7",
36
+ "@types/react-dom": "^19.2.1",
37
+ "happy-dom": "^20.10.3",
38
+ "react": "19.2.4",
39
+ "react-dom": "19.2.4",
40
+ "typescript": "^5.7.2"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "engines": {
46
+ "bun": ">=1.0.0",
47
+ "node": ">=18.0.0"
48
+ }
49
+ }