@palettelab/sdk 0.1.1 → 0.1.3
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 +163 -0
- package/package.json +5 -4
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# @palettelab/sdk
|
|
2
|
+
|
|
3
|
+
Frontend SDK for building Palette plugins and internal apps.
|
|
4
|
+
|
|
5
|
+
Use this package from plugin frontends created with `@palettelab/cli`. It provides typed platform context, authenticated API helpers, React hooks for common Palette resources, iframe sandbox bridge helpers, install configuration helpers, and test utilities.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @palettelab/sdk react react-dom
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react` and `react-dom` are peer dependencies. Plugin bundles should externalize React and `@palettelab/sdk`; the Palette CLI handles this for standard templates.
|
|
14
|
+
|
|
15
|
+
## Exports
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {
|
|
19
|
+
PluginProvider,
|
|
20
|
+
usePlatform,
|
|
21
|
+
usePluginTasks,
|
|
22
|
+
usePluginDataRooms,
|
|
23
|
+
usePluginChat,
|
|
24
|
+
apiFetch,
|
|
25
|
+
apiUpload,
|
|
26
|
+
createSandboxBridge,
|
|
27
|
+
getInstallConfig,
|
|
28
|
+
updateInstallConfig,
|
|
29
|
+
} from "@palettelab/sdk"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Subpath exports are also available:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { usePlatform } from "@palettelab/sdk/hooks"
|
|
36
|
+
import type { PluginManifest } from "@palettelab/sdk/types"
|
|
37
|
+
import { PluginProvider } from "@palettelab/sdk/components"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Plugin Root
|
|
41
|
+
|
|
42
|
+
The platform passes plugin runtime context into your root component. Wrap your UI with `PluginProvider` so hooks can read it.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { PluginProvider, usePlatform, type PluginComponentProps } from "@palettelab/sdk"
|
|
46
|
+
|
|
47
|
+
function App() {
|
|
48
|
+
const { user, organizationId, pluginId } = usePlatform()
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<main>
|
|
52
|
+
<h1>{pluginId}</h1>
|
|
53
|
+
<p>{user?.email}</p>
|
|
54
|
+
<p>Organization: {organizationId}</p>
|
|
55
|
+
</main>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default function PluginRoot(props: PluginComponentProps) {
|
|
60
|
+
return (
|
|
61
|
+
<PluginProvider value={props}>
|
|
62
|
+
<App />
|
|
63
|
+
</PluginProvider>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## API Helpers
|
|
69
|
+
|
|
70
|
+
Use `apiFetch` for authenticated platform API calls. It includes credentials and performs the platform refresh flow for normal portal runtime.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { apiFetch } from "@palettelab/sdk"
|
|
74
|
+
|
|
75
|
+
const res = await apiFetch("/api/v1/tasks")
|
|
76
|
+
const tasks = await res.json()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Use `apiUpload` for multipart uploads.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { apiUpload } from "@palettelab/sdk"
|
|
83
|
+
|
|
84
|
+
await apiUpload("/api/v1/resources/upload", file)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Resource Hooks
|
|
88
|
+
|
|
89
|
+
The SDK includes hooks for common Palette resources:
|
|
90
|
+
|
|
91
|
+
- `usePluginTasks`
|
|
92
|
+
- `usePluginDataRooms`
|
|
93
|
+
- `usePluginChat`
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { usePluginTasks } from "@palettelab/sdk"
|
|
97
|
+
|
|
98
|
+
export function TaskList() {
|
|
99
|
+
const { tasks, loading, error, refetch } = usePluginTasks()
|
|
100
|
+
|
|
101
|
+
if (loading) return <p>Loading...</p>
|
|
102
|
+
if (error) return <p>{error}</p>
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<ul>
|
|
106
|
+
{tasks.map((task) => (
|
|
107
|
+
<li key={task.id}>{task.title}</li>
|
|
108
|
+
))}
|
|
109
|
+
</ul>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Install Configuration
|
|
115
|
+
|
|
116
|
+
Plugins can read and update their installation configuration through helper APIs.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { getInstallConfig, updateInstallConfig } from "@palettelab/sdk"
|
|
120
|
+
|
|
121
|
+
const config = await getInstallConfig()
|
|
122
|
+
await updateInstallConfig({ ...config, enabled: true })
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Sandbox Bridge
|
|
126
|
+
|
|
127
|
+
Appstore plugin frontends run inside an iframe sandbox by default. Use `createSandboxBridge` when you need to explicitly call host-proxied APIs from sandbox runtime code.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { createSandboxBridge, isSandboxRuntime } from "@palettelab/sdk"
|
|
131
|
+
|
|
132
|
+
if (isSandboxRuntime()) {
|
|
133
|
+
const bridge = createSandboxBridge()
|
|
134
|
+
const result = await bridge.apiFetch("/api/v1/tasks")
|
|
135
|
+
console.log(result)
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
For standard React plugin templates, the runtime wiring is already handled by the platform and CLI.
|
|
140
|
+
|
|
141
|
+
## Testing
|
|
142
|
+
|
|
143
|
+
Use the SDK test utilities to render plugin components with a mock platform context.
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import { createMockPlatformContext, withPluginProvider } from "@palettelab/sdk"
|
|
147
|
+
|
|
148
|
+
const ctx = createMockPlatformContext({
|
|
149
|
+
pluginId: "hello-sdk",
|
|
150
|
+
organizationId: 1,
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
const Wrapped = withPluginProvider(MyPluginComponent, ctx)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Package Contents
|
|
157
|
+
|
|
158
|
+
The npm package ships compiled CommonJS, ESM, and TypeScript declarations from `dist/`.
|
|
159
|
+
|
|
160
|
+
## Related Packages
|
|
161
|
+
|
|
162
|
+
- `@palettelab/cli` provides the `pltt` command for scaffolding, local dev, validation, packaging, and publishing.
|
|
163
|
+
- `palette-sdk` is the Python backend SDK for FastAPI plugin routes, permissions, tools, DB helpers, RLS, and test helpers.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@palettelab/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Palette Platform SDK for building plugins and apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,15 +27,16 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
|
-
"dist"
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
31
32
|
],
|
|
32
33
|
"publishConfig": {
|
|
33
|
-
"registry": "https://
|
|
34
|
+
"registry": "https://registry.npmjs.org"
|
|
34
35
|
},
|
|
35
36
|
"license": "MIT",
|
|
36
37
|
"repository": {
|
|
37
38
|
"type": "git",
|
|
38
|
-
"url": "https://github.com/palette-lab/virtual-organisation.git",
|
|
39
|
+
"url": "git+https://github.com/palette-lab/virtual-organisation.git",
|
|
39
40
|
"directory": "sdk/frontend"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|