@collective-intelligence/extensions-sdk-frontend-react 0.1.8 → 0.1.9
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 +74 -0
- package/dist/index.d.ts +17 -3
- package/dist/index.js +1 -1
- package/dist/studio-api/@tanstack/react-query.gen.d.ts +818 -0
- package/dist/studio-api/client/client.gen.d.ts +2 -0
- package/dist/studio-api/client/index.d.ts +8 -0
- package/dist/studio-api/client/types.gen.d.ts +118 -0
- package/dist/studio-api/client/utils.gen.d.ts +33 -0
- package/dist/studio-api/client.gen.d.ts +12 -0
- package/dist/studio-api/core/auth.gen.d.ts +18 -0
- package/dist/studio-api/core/bodySerializer.gen.d.ts +25 -0
- package/dist/studio-api/core/params.gen.d.ts +43 -0
- package/dist/studio-api/core/pathSerializer.gen.d.ts +33 -0
- package/dist/studio-api/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/studio-api/core/serverSentEvents.gen.d.ts +72 -0
- package/dist/studio-api/core/types.gen.d.ts +78 -0
- package/dist/studio-api/core/utils.gen.d.ts +19 -0
- package/dist/studio-api/index.d.ts +4 -0
- package/dist/studio-api/index.js +6 -0
- package/dist/studio-api/sdk.gen.d.ts +22 -0
- package/dist/studio-api/types.gen.d.ts +476 -0
- package/dist/studio-declarations.d.ts +0 -39
- package/dist/studio-view-context.d.ts +45 -0
- package/dist/studio.d.ts +21 -3
- package/dist/studio.js +1 -1
- package/package.json +13 -4
package/README.md
CHANGED
|
@@ -140,6 +140,80 @@ The chart exposes every declared input and output with its port name, direction,
|
|
|
140
140
|
connection limit, and allowed peer constraints. Port targets are 20 pixels wide;
|
|
141
141
|
the card grows to keep dense port lists and contextual add controls separated.
|
|
142
142
|
|
|
143
|
+
## Studio API
|
|
144
|
+
|
|
145
|
+
The `studio-api` entrypoint is a generated client for the backend operations
|
|
146
|
+
that hosted Studio Widgets are meant to use. The backend marks each such
|
|
147
|
+
operation with the `widget-public` OpenAPI tag. The tag selects what the client
|
|
148
|
+
generates; it is not an authorization boundary. Each request runs with the
|
|
149
|
+
signed-in user's own permissions, and the backend authorizes it like any other
|
|
150
|
+
request. The entrypoint exports the SDK functions, their types, TanStack Query
|
|
151
|
+
options, mutation options and query keys, and the `client` instance. The Studio
|
|
152
|
+
Host binds that client to its authenticated transport; Widgets do not configure
|
|
153
|
+
credentials. Every Widget shares the one bound `client`, so the Host locks it:
|
|
154
|
+
`client.setConfig` and every `client.interceptors` change throw. Set headers
|
|
155
|
+
and other request options per call.
|
|
156
|
+
|
|
157
|
+
### Studio view context
|
|
158
|
+
|
|
159
|
+
The Studio Host gives every placed view and Widget component a `context` prop
|
|
160
|
+
next to its configured props. The `/studio` entrypoint types it as
|
|
161
|
+
`StudioViewComponentProps`:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
type StudioViewContext = Readonly<{
|
|
165
|
+
appId: string
|
|
166
|
+
appSlug: string
|
|
167
|
+
organizationId: string
|
|
168
|
+
pageId: string
|
|
169
|
+
publishedRevisionId: string
|
|
170
|
+
viewId: string
|
|
171
|
+
}>
|
|
172
|
+
type StudioViewComponentProps = Readonly<{
|
|
173
|
+
context: StudioViewContext | null
|
|
174
|
+
}>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Studio generates view, page, and revision ids when an app is installed or
|
|
178
|
+
published, so a declaration cannot name them; read them from `context`.
|
|
179
|
+
`context` is `null` when the view has no published placement: in the builder
|
|
180
|
+
preview, without an Organization, or before the app has a published revision.
|
|
181
|
+
Hide or disable the API calls of the Widget in that case.
|
|
182
|
+
|
|
183
|
+
`studioViewScope(context)` returns the `headers` and `path` options of the
|
|
184
|
+
view-data operations. `studioPublishedViewScope(context)` returns the
|
|
185
|
+
`headers` and `query` options of operations on a published view, such as
|
|
186
|
+
`studioWorkflowRunsList`:
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import type {
|
|
190
|
+
StudioViewComponentProps,
|
|
191
|
+
StudioViewContext
|
|
192
|
+
} from "@collective-intelligence/extensions-sdk-frontend-react/studio"
|
|
193
|
+
|
|
194
|
+
import { studioViewScope } from "@collective-intelligence/extensions-sdk-frontend-react/studio"
|
|
195
|
+
import { studioViewDataSearchOptions } from "@collective-intelligence/extensions-sdk-frontend-react/studio-api"
|
|
196
|
+
import { useQuery } from "@tanstack/react-query"
|
|
197
|
+
|
|
198
|
+
const CustomerRows = ({ context }: { context: StudioViewContext }) => {
|
|
199
|
+
const rows = useQuery(
|
|
200
|
+
studioViewDataSearchOptions({
|
|
201
|
+
...studioViewScope(context),
|
|
202
|
+
body: { limit: 10 }
|
|
203
|
+
})
|
|
204
|
+
)
|
|
205
|
+
return <output>{rows.status}</output>
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const CustomerWidget = ({ context }: StudioViewComponentProps) =>
|
|
209
|
+
context === null ? null : <CustomerRows context={context} />
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`src/studio-api/` is generated and committed. After a backend change to a
|
|
213
|
+
marked operation, run `bun run --filter @repo/backend api:openapi`, then
|
|
214
|
+
`bun run api:codegen:studio-api` in this package. CI runs
|
|
215
|
+
`api:codegen:studio-api:check` and fails when the committed client is stale.
|
|
216
|
+
|
|
143
217
|
## Building in the workspace
|
|
144
218
|
|
|
145
219
|
This package needs the built `@collective-intelligence/ui-react` declarations
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const declareStudioApp:
|
|
1
|
+
import { declareStudioComponent as declareStudioComponentImplementation } from "./studio-declarations.js";
|
|
2
|
+
export declare const declareStudioApp: (input: import("@collective-intelligence/extensions-sdk").StudioAppDeclarationInput) => import("@collective-intelligence/extensions-sdk").DeclaredComponent<import("@collective-intelligence/extensions-sdk").StudioAppDeclaration>;
|
|
3
|
+
export declare const declareStudioAppTemplate: (input: Readonly<{
|
|
4
|
+
definition: Omit<import("@collective-intelligence/extensions-sdk").StudioAppTemplateDeclaration, "description" | "displayName" | "fqn" | "icon" | "kind" | "tags" | "version">;
|
|
5
|
+
manifest: Readonly<{
|
|
6
|
+
fqn: string;
|
|
7
|
+
version: string;
|
|
8
|
+
}>;
|
|
9
|
+
presentation: Readonly<{
|
|
10
|
+
description?: string;
|
|
11
|
+
displayName: string;
|
|
12
|
+
icon?: string;
|
|
13
|
+
tags?: readonly string[];
|
|
14
|
+
}>;
|
|
15
|
+
}>) => import("@collective-intelligence/extensions-sdk").DeclaredComponent<import("@collective-intelligence/extensions-sdk").StudioAppTemplateDeclaration>;
|
|
3
16
|
export declare const declareStudioComponent: typeof declareStudioComponentImplementation;
|
|
4
|
-
export type {
|
|
17
|
+
export type { StudioAppDeclaration, StudioAppDeclarationInput, StudioAppDefinition, StudioAppPageDefinition, StudioAppSectionDefinition, StudioAppTemplateDeclaration, StudioAppTemplateDefinition, StudioAppTemplatePageDefinition, StudioAppTemplateSectionDefinition } from "@collective-intelligence/extensions-sdk";
|
|
18
|
+
export type { LocalizedStudioText, StudioComponentComposition, StudioComponentDeclaration, StudioComponentDeclarationInput } from "./studio-declarations.js";
|
|
5
19
|
export type { HostedContributionErrorBoundaryProps, HostedContributionLoadFailure, HostedContributionLoadState, HostedContributionUnavailableProps } from "./load-state.js";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{assertConsumerProfile as
|
|
1
|
+
import{declareStudioApp as d,declareStudioAppTemplate as m}from"@collective-intelligence/extensions-sdk";import{assertConsumerProfile as r,canonicalJson as p,normalizePackageSchemaProjection as c}from"@collective-intelligence/extensions-sdk";var s=(o)=>{try{p(o)}catch(e){let t=e instanceof Error?e.message:String(e);throw TypeError(`Studio declaration must be serializable JSON: ${t}`,{cause:e})}},a=(o)=>{let e=o.definition.propsSchema,t=`studio_component:${o.manifest.fqn}.propsSchema`,n=c(e.project("input"));r(n,"studio_props",t);let i={category:o.definition.category,...o.definition.composition===void 0?void 0:{composition:o.definition.composition},...o.presentation,...o.manifest,kind:"studioComponent",propsSchema:n,sourceRef:o.definition.sourceRef};return s(i),{manifest:i,schemaSidecars:[{direction:"input",location:t,profile:"studio_props",source:e}]}};var g=d,y=m,D=a;export{g as declareStudioApp,y as declareStudioAppTemplate,D as declareStudioComponent};
|