@colixsystems/widget-sdk 0.38.0 → 0.39.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 +16 -9
- package/dist/cli.js +11 -3
- package/dist/contract.cjs +27 -12
- package/dist/contract.js +27 -12
- package/dist/dev-shims.js +255 -0
- package/dist/devserver.js +640 -73
- package/dist/hooks.js +27 -26
- package/dist/index.d.ts +10 -10
- package/dist/index.js +1 -1
- package/dist/index.native.js +1 -1
- package/dist/webbundle.js +125 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
8
8
|
| ----------- | ------- | -------- |
|
|
9
9
|
| `ctx.datastore` | `@colixsystems/datastore-client` | `tables.{list,get}`, `schema(tableId)`, `records(tableId).{ list(query), get(id), create(values), update(id,values) [PATCH], delete(id), aggregate(spec), permissions(recordId).{ list, grant, update, revoke } }` |
|
|
10
10
|
| `ctx.directory` | `@colixsystems/directory-client` | `me()`, `users.{list,get,invite,deactivate,reactivate}`, `groups.{list,create,remove,addMember,removeMember,listMine}`, `invites.{list,revoke,resend}` |
|
|
11
|
-
| `ctx.
|
|
11
|
+
| `ctx.assets` | `@colixsystems/assets-client` | the Asset Manager: `get(id)`, `list(query)`, `upload(formData)` over `/files` — what `useAsset()` resolves |
|
|
12
12
|
| `ctx.payments` | `@colixsystems/payments-client` | `requestPayment(body)`, `getPayment(id)` |
|
|
13
13
|
|
|
14
14
|
**Wire / casing: snake_case end to end.** The clients send and return snake_case **verbatim** (`created_at`, `group_ids`, `can_read`, `amount_cents`, `data_type`, `is_active`, …). There is **no case transform anywhere** — not on the client and not in the backend; the only casing boundary is Prisma `@map` (snake_case field → camelCase column). Author-defined record column values pass through verbatim. Every `list(...)` returns the `{ data, meta }` envelope; the read hooks unwrap `res.data` for you.
|
|
@@ -32,7 +32,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
32
32
|
| **DATASTORE** | `useDatastoreSchema(tableId)` | `{ schema, loading, error, refetch }` | `schema(tableId)` — `datastore.read:<table>` |
|
|
33
33
|
| **DATASTORE** | `useDatastoreMutation(table)` | `{ create, update, delete }` | `records(table).{ create, update (PATCH), delete }` — `datastore.write:*` |
|
|
34
34
|
| **DATASTORE** | `useRecordPermissions(tableId, recordId)` | `{ permissions, loading, error, grant, revoke, update, refetch }` | `records(table).permissions(record).{ list, grant, update, revoke }` — `acl.write:records` (+ `can_grant` on the record) |
|
|
35
|
-
| **FILES** (`ctx.
|
|
35
|
+
| **FILES** (`ctx.assets`) | `useAsset(id)` | `{ url, file, loading, error, refetch }` | `ctx.assets.get` — no scope |
|
|
36
36
|
| **DIRECTORY** (`ctx.directory`) | `useDirectory(query?)` | `{ users, loading, error, refetch }` | `directory.users.list` — `directory.read:users` |
|
|
37
37
|
| **DIRECTORY** | `useUsers(query?)` | `{ users, loading, error, refetch, invite, deactivate, reactivate, remove }` | `directory.users.*` — `users.read:*` (edits also `users.write:*`; `remove()` also `users.delete:*`) |
|
|
38
38
|
| **DIRECTORY** | `useGroups(query?)` | `{ groups, loading, error, refetch, create, remove, addMember, removeMember }` | `directory.groups.*` — `groups.read:*` (mutations also `groups.write:*`) |
|
|
@@ -47,7 +47,14 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
47
47
|
|
|
48
48
|
## Status
|
|
49
49
|
|
|
50
|
-
`v0.
|
|
50
|
+
`v0.39.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
51
|
+
|
|
52
|
+
### What's new in 0.39.0
|
|
53
|
+
|
|
54
|
+
**Web entry is bundled, not just transpiled (sc-1064).** A first-party / dev widget's WEB entry (`widget.web.jsx`, or the cross-platform `widget.jsx`) is now esbuild-**bundled** by both `appstudio-widget dev` and the publish packer, so vetted web-only deps the host doesn't shim — `react-leaflet`, `leaflet`, its CSS, and its marker PNG assets — are inlined instead of left as bare imports the Studio loader can't resolve. The native entry (`widget.native.jsx`) is still Sucrase transpile-only (Metro bundles its native deps in the export).
|
|
55
|
+
|
|
56
|
+
- **New `./dev-shims` exports**: `hostExternalSpecifiers()` — the canonical, single-source list of bare specifiers the runtime web host resolves (react family, `react-dom` + `react-dom/client`, `@colixsystems/widget-sdk`, and the vetted shimmed packages), i.e. exactly what the bundler externalises; and `REACT_DOM_NAMED_EXPORTS` — the react-dom named surface (`createPortal`, …) the host shim re-exports so `react-leaflet`'s portal-based Popup/Pane share the host's single react-dom instance.
|
|
57
|
+
- **New optional dependency `esbuild`** — lazily imported only on the `dev`/pack bundle paths (same pattern as the optional `sucrase`); the published runtime never forces it.
|
|
51
58
|
|
|
52
59
|
### What's new in 0.38.0
|
|
53
60
|
|
|
@@ -185,10 +192,10 @@ Also: `useFileSignatures(fileIds)` is now **self-scoped** (the caller's own sign
|
|
|
185
192
|
|
|
186
193
|
**The data layer splits into four injected domain clients; the SDK becomes core-only.**
|
|
187
194
|
|
|
188
|
-
- **The SDK no longer owns any data facade.** The bespoke per-hook facades that used to live on `WidgetContext` (`ctx.datastore` as an opaque host object, `ctx.directory.listUsers`, `ctx.users`, `ctx.groups`, `ctx.recordPermissions`, `ctx.
|
|
195
|
+
- **The SDK no longer owns any data facade.** The bespoke per-hook facades that used to live on `WidgetContext` (`ctx.datastore` as an opaque host object, `ctx.directory.listUsers`, `ctx.users`, `ctx.groups`, `ctx.recordPermissions`, `ctx.assets.get`) are replaced by four host-instantiated, host-injected domain clients: `ctx.datastore` (`@colixsystems/datastore-client`), `ctx.directory` (`@colixsystems/directory-client`), `ctx.assets` (`@colixsystems/assets-client`, flattened), `ctx.payments` (`@colixsystems/payments-client`). The SDK imports none of them and ships no HTTP.
|
|
189
196
|
- **`ctx.recordPermissions`, `ctx.users`, `ctx.groups` are removed.** Per-record permission management moved under `ctx.datastore.records(tableId).permissions(recordId)`; user / group administration moved under `ctx.directory.users` / `ctx.directory.groups`. The hooks (`useRecordPermissions`, `useUsers`, `useGroups`) keep the same names and signatures — only the client slice they read changed.
|
|
190
197
|
- **snake_case end to end, no client-side transform.** Clients send and return snake_case verbatim (`group_ids`, `can_read`, `is_active`, `amount_cents`, `data_type`, `created_at`, …). The SDK passes bodies straight through and unwraps the `{ data, meta }` list envelope without renaming a single field. Hook return rows and `useUser()` fields are therefore snake_case (`display_name`, `group_ids`, `is_active`, `member_count`, and `useRecordPermissions` rows carry `user_id` / `group_id` / `can_read` / `can_write` / `can_delete` / `can_grant`).
|
|
191
|
-
- **Companion package versions:** `datastore-client 0.5.0`, `
|
|
198
|
+
- **Companion package versions:** `datastore-client 0.5.0`, `assets-client 0.4.0`, `directory-client 0.1.0`, `payments-client 0.1.0`.
|
|
192
199
|
- **`CONTRACT.version` → `1.9.0`.** Breaking for `WidgetContext` consumers (removed slices, renamed wire fields); the hook export surface is unchanged.
|
|
193
200
|
|
|
194
201
|
### What was in 0.18.0
|
|
@@ -227,7 +234,7 @@ The tenant's **Theme Settings** now flow all the way into `useTheme()`.
|
|
|
227
234
|
The "split-implementation + vetted package list" pivot.
|
|
228
235
|
|
|
229
236
|
- **`CONTRACT.vettedImports` (new).** A curated allowlist of bare specifiers a widget may import — `react`, `@colixsystems/widget-sdk`, `react-native`, `axios`, `date-fns`, `react-native-svg`, `lucide-react-native`, `react-native-maps`, `leaflet`, `react-leaflet`, `expo-av`, `@react-native-community/datetimepicker`, `expo-clipboard`, `expo-haptics`. Each entry carries `platforms` (one or both of `"web"` / `"native"`) and a `category` so the linter and the marketplace listing can render honest platform badges. `CONTRACT.allowedBareImports` (the existing field) is now derived from `vettedImports` and stays a plain `string[]` for back-compat.
|
|
230
|
-
- **`fetch` and `XMLHttpRequest` come off `CONTRACT.bannedApis`.** Widgets may call third-party APIs directly. Calls to the host's own `/api/*` surface will 401 because the JWT token is never shared with widget code; the linter emits a soft `no-host-api-url` warning when it sees host-URL substrings so authors learn the rule statically. Use SDK hooks (`useDatastoreQuery`, `useUsers`, `
|
|
237
|
+
- **`fetch` and `XMLHttpRequest` come off `CONTRACT.bannedApis`.** Widgets may call third-party APIs directly. Calls to the host's own `/api/*` surface will 401 because the JWT token is never shared with widget code; the linter emits a soft `no-host-api-url` warning when it sees host-URL substrings so authors learn the rule statically. Use SDK hooks (`useDatastoreQuery`, `useUsers`, `useAsset`, …) for workspace data; use `axios` / `fetch` for third-party APIs.
|
|
231
238
|
- **`import-not-vetted` linter rule (new).** Every bare `import` specifier is validated against `CONTRACT.vettedImports`. Relative imports inside the bundle (`./shared.js`) are allowed so split-impl widgets can share helpers; `../` and absolute paths are rejected.
|
|
232
239
|
- **`import-platform-mismatch` linter rule (new).** A single-source widget that imports a native-only package while `manifest.supportedPlatforms` includes `"web"` fails the lint. The author either drops the platform from the manifest OR ships a `widget.web.jsx` + `widget.native.jsx` pair where the platform-specific import lives in the file that targets its platform.
|
|
233
240
|
- **Lint findings carry `severity`.** `"error"` (default) blocks publish; `"warning"` (currently only `no-host-api-url`) surfaces to reviewers without blocking. The `lintSource(...)` return shape stays `{ ok, findings }` — `ok` is true iff no error-severity findings exist.
|
|
@@ -257,7 +264,7 @@ The "split-implementation + vetted package list" pivot.
|
|
|
257
264
|
### What's new in 0.12.0
|
|
258
265
|
|
|
259
266
|
- **`useDatastoreRecord(tableId, recordId)` is wired.** Returns `{ data, loading, error, refetch }` for a single record fetched through the host's `records(table).get(id)`. Sister to `useDatastoreQuery`; mirrors its ref discipline so `refetch` stays a stable callback identity. A 404 surfaces as `DatastoreError.code === "NOT_FOUND"`. Additive.
|
|
260
|
-
- **`
|
|
267
|
+
- **`useAsset(fileId)` is wired** + new `WidgetContext.assets` slice. Returns `{ url, file, loading, error, refetch }` — the `url` is an absolute URL the widget can drop straight into `<Image source>`. Backed by a new `files.get(fileId)` host facade (web: `widgetHostFiles` through `api/client`; native: `hostFiles` in the export's `widgetHost.js`). Additive.
|
|
261
268
|
|
|
262
269
|
### What's new in 0.11.0
|
|
263
270
|
|
|
@@ -331,7 +338,7 @@ import { defineWidget, validateManifest, useDatastoreQuery, Text, View } from "@
|
|
|
331
338
|
|
|
332
339
|
- `defineWidget({ manifest, component })` — validates the manifest and produces a widget module the host can register.
|
|
333
340
|
- `validateManifest(m)` / `validatePropertySchema(s)` / `validateProps(schema, props)` — shape validation; no third-party deps.
|
|
334
|
-
- `useDatastoreQuery`, `useDatastoreRecord`, `useDatastoreSchema`, `useDatastoreMutation`, `useDirectory`, `useUsers`, `useGroups`, `useRecordPermissions`, `
|
|
341
|
+
- `useDatastoreQuery`, `useDatastoreRecord`, `useDatastoreSchema`, `useDatastoreMutation`, `useDirectory`, `useUsers`, `useGroups`, `useRecordPermissions`, `useAsset`, `useWidgetEvent`, `usePayments`, `useTheme`, `useI18n`, `useUser`, `useNavigation`, `useChildRenderer`, `useClipboard`, `useToast` — hooks that read from the host-provided `WidgetContext` (or, for `useClipboard`, the platform clipboard API directly). `useDirectory(query?)` returns `{ users, loading, error, refetch }` (each user `{ id, name, role }`) and requires the `directory.read:users` scope. `useUsers(query?)` returns `{ users, loading, error, refetch, invite, deactivate, reactivate, remove }` and requires `users.read:*` (mutations also need `users.write:*`); rejections are a `DirectoryError`. `useGroups(query?)` returns `{ groups, loading, error, refetch, create, remove, addMember, removeMember }` and requires `groups.read:*` (mutations also need `groups.write:*`). `usePayments()` returns `{ requestPayment, getPayment }` and requires the `payments.charge:appUser` scope; `requestPayment(...)` rejects with a `PaymentError`. `useUser()` returns the active end-user identity `{ id, email, display_name, roles, group_ids }` (snake_case verbatim; `id` is `null` for anonymous / preview). `useNavigation()` returns `{ goTo, goBack, push, replace, back, currentRoute }` for internal page navigation — for external URLs use the `Linking` primitive (`Linking.openURL(url)`). `useDatastoreRecord(tableId, recordId)` returns `{ data, loading, error, refetch }` for a single record (data is one row or null). `useDatastoreSchema(tableId)` returns `{ schema, loading, error, refetch }` where `schema` is `{ id, name, columns: [{ id, name, data_type, required, relation_type, target_table_id, is_identification }] }` (structure only, no row data; snake_case verbatim) — use it to resolve a stored `columnId` to its column type at runtime; requires the `datastore.read:<table>` scope. `useAsset(fileId)` returns `{ url, file, loading, error, refetch }` — the `url` is an absolute URL composed against the host's API base. `useChildRenderer()` returns `{ renderNode(node) }` — container widgets call it to render arbitrary child page-tree nodes (prefer the `WidgetTree` component for the common case).
|
|
335
342
|
- `WidgetTree({ node })` — component that renders an author-authored child node through the host's renderer; used by Tabs / Card / custom containers to host arbitrary child widgets.
|
|
336
343
|
- `Text`, `View`, `Pressable`, `Image`, `ScrollView`, `TextInput`, `FlatList`, `SectionList`, `ActivityIndicator`, `Switch`, `StyleSheet`, `Linking`, `Icon`, `DateTimePicker` — re-exported from `react-native` (the RN primitives) or implemented in the SDK (`Icon` wraps `lucide-react-native`, `DateTimePicker` wraps `@react-native-community/datetimepicker`). The web build aliases `react-native` to `react-native-web` so widgets render in the browser without any per-platform code; the exported Expo app's Metro bundler resolves the real `react-native` library. `Linking` is a static API (`Linking.openURL(url)`) — use it for external URLs, and use `useNavigation().goTo(pageId)` for internal page navigation. See https://reactnative.dev/docs/ for per-component props.
|
|
337
344
|
- `WidgetContextProvider` — React context provider that the host (Studio, Player, exported app) wraps widgets with.
|
|
@@ -347,7 +354,7 @@ A widget that works but looks unfinished is only half done. `useTheme()` is the
|
|
|
347
354
|
- **Contain and elevate.** Wrap a logical unit in a surface: `colors.surface` + padding + `radii.md` + a `colors.border` hairline or a subtle shadow. Use the status roles (`danger / success / warning / info`) for state.
|
|
348
355
|
- **Respond to touch.** Give every `Pressable` a pressed state via the function-style `style={({ pressed }) => [base, pressed && { opacity: 0.7 }]}`.
|
|
349
356
|
- **Use icons for clarity.** Pair a `lucide-react-native` icon with its label at a consistent size, coloured from the theme.
|
|
350
|
-
- **Use imagery deliberately.** Render pictures with the `Image` primitive (`source` takes a URL or `{ uri }`); resolve workspace assets via `
|
|
357
|
+
- **Use imagery deliberately.** Render pictures with the `Image` primitive (`source` takes a URL or `{ uri }`); resolve workspace assets via `useAsset()`. Give every image a sized, `radii`-clipped container so it never renders as a raw rectangle, and never hardcode a credentialed image URL — expose an `image`-type property instead.
|
|
351
358
|
- **Design the empty, loading, and error states.** A blank box on a fresh install reads as broken — show a short helper line when a list is empty, a calm loading line, and a single human sentence in `colors.danger` on error.
|
|
352
359
|
|
|
353
360
|
**Honest ceilings:** the styling surface is React Native style objects, not full CSS. There are no per-widget gradients, no custom CSS keyframe animations or `transition` strings, and shadows are limited to the five elevation presets (`none / sm / md / lg / xl`). Aim for clean, confident, professional polish within those bounds.
|
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,10 @@ function usage() {
|
|
|
14
14
|
stderr.write(
|
|
15
15
|
"Usage:\n" +
|
|
16
16
|
" appstudio-widget lint <path>\n" +
|
|
17
|
-
" appstudio-widget dev <entry.jsx> [--port <n>] [--manifest <path>]\n"
|
|
17
|
+
" appstudio-widget dev <entry.jsx|widget-dir> [--port <n>] [--manifest <path>]\n" +
|
|
18
|
+
" A directory containing widget.json runs in multi-file mode " +
|
|
19
|
+
"(REQ-WSDK-DEVKIT v2): the dev server reads the canonical web entry, " +
|
|
20
|
+
"serves siblings under /file/<rel>, and watches the whole tree.\n",
|
|
18
21
|
);
|
|
19
22
|
exit(2);
|
|
20
23
|
}
|
|
@@ -93,14 +96,19 @@ async function runDev(rest) {
|
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
stdout.write(
|
|
96
|
-
`\nappstudio-widget dev — serving ${resolve(entry)}
|
|
99
|
+
`\nappstudio-widget dev — serving ${resolve(entry)} ` +
|
|
100
|
+
`(${handle.directoryMode ? "directory" : "single-file"} mode)\n` +
|
|
97
101
|
` bundle: ${handle.url}/widget.mjs\n` +
|
|
98
102
|
` manifest: ${handle.url}/manifest.json\n` +
|
|
99
103
|
` reload: ${handle.url}/__dev/events (SSE)\n` +
|
|
104
|
+
(handle.directoryMode
|
|
105
|
+
? ` files: ${handle.url}/file/<relpath>\n shims: ${handle.url}/shim/<slug>\n`
|
|
106
|
+
: "") +
|
|
100
107
|
(handle.manifestId ? ` id: ${handle.manifestId}\n` : "") +
|
|
101
108
|
`\nIn the Studio Builder (dev mode), open the "Dev widgets" panel and add:\n` +
|
|
102
109
|
` ${handle.url}\n` +
|
|
103
|
-
`Edits to
|
|
110
|
+
`Edits to ${handle.directoryMode ? "any file in the widget directory" : "the entry"} ` +
|
|
111
|
+
`hot-reload the widget on the canvas. Ctrl+C to stop.\n\n`,
|
|
104
112
|
);
|
|
105
113
|
|
|
106
114
|
const shutdown = () => {
|
package/dist/contract.cjs
CHANGED
|
@@ -143,16 +143,16 @@ const HOOKS = [
|
|
|
143
143
|
scopes: ["datastore.read:<table>"],
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
|
-
name: "
|
|
147
|
-
signature: "
|
|
146
|
+
name: "useAsset",
|
|
147
|
+
signature: "useAsset(assetId)",
|
|
148
148
|
returnShape: {
|
|
149
149
|
url: "string | null",
|
|
150
|
-
|
|
150
|
+
asset: "{ id, url, storedFilename, mimeType, sizeBytes, ... } | null",
|
|
151
151
|
loading: "boolean",
|
|
152
152
|
error: "DatastoreError | null",
|
|
153
153
|
refetch: "() => Promise<void>",
|
|
154
154
|
},
|
|
155
|
-
requiredContextSlice: ["
|
|
155
|
+
requiredContextSlice: ["assets.get"],
|
|
156
156
|
scopes: null,
|
|
157
157
|
},
|
|
158
158
|
{
|
|
@@ -900,11 +900,11 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
900
900
|
required: true,
|
|
901
901
|
fields: { users: "object", groups: "object", bankid: "object" },
|
|
902
902
|
},
|
|
903
|
-
|
|
903
|
+
assets: {
|
|
904
904
|
description:
|
|
905
|
-
"Injected @colixsystems/
|
|
906
|
-
"{ get(id) -> Promise<{ id, url, ... }>, list(query) -> Promise<{ data, meta }>, upload(formData)
|
|
907
|
-
"Backs
|
|
905
|
+
"Injected @colixsystems/assets-client instance, FLATTENED so asset ops are top-level. " +
|
|
906
|
+
"{ get(id) -> Promise<{ id, url, ... }>, list(query) -> Promise<{ data, meta }>, upload(formData) }. " +
|
|
907
|
+
"Backs useAsset(); the returned asset already carries an absolute url the widget can drop into an <Image source>.",
|
|
908
908
|
required: true,
|
|
909
909
|
fields: { get: "function" },
|
|
910
910
|
},
|
|
@@ -1245,12 +1245,27 @@ const VETTED_IMPORTS = [
|
|
|
1245
1245
|
},
|
|
1246
1246
|
];
|
|
1247
1247
|
|
|
1248
|
+
// sc-1064: CORE React infrastructure specifiers the host RESOLVES at runtime
|
|
1249
|
+
// but that are NOT author-facing "vetted widget libraries". `react-dom` and
|
|
1250
|
+
// `react-dom/client` are transitive — `react-leaflet`'s Popup/Pane render
|
|
1251
|
+
// through `createPortal` from `react-dom`, so the host externalises + shims
|
|
1252
|
+
// them — but widget authors should never be encouraged to import react-dom
|
|
1253
|
+
// directly (unlike axios/date-fns/leaflet/…). They belong on
|
|
1254
|
+
// `allowedBareImports` (so the loader's shim⊆vetted guard treats them as
|
|
1255
|
+
// vetted) WITHOUT bloating the rich `VETTED_IMPORTS` reference the AI prompt /
|
|
1256
|
+
// Developer guide enumerate — the SAME treatment `react/jsx-runtime` gets, but
|
|
1257
|
+
// kept out of the author-facing list. Mirror of contract.js.
|
|
1258
|
+
const CORE_INFRA_BARE_IMPORTS = ["react-dom", "react-dom/client"];
|
|
1259
|
+
|
|
1248
1260
|
// Back-compat shape — every existing consumer (widgetLoader, the static
|
|
1249
1261
|
// analyzer's DEPENDENCY_ALLOWLIST, the AI prompt's "Allowed imports" line)
|
|
1250
1262
|
// reads a plain `string[]` from `CONTRACT.allowedBareImports`. Derive it
|
|
1251
|
-
// from the rich list so a single edit
|
|
1252
|
-
// every surface.
|
|
1253
|
-
const ALLOWED_BARE_IMPORTS =
|
|
1263
|
+
// from the rich list (plus the CORE infra specifiers above) so a single edit
|
|
1264
|
+
// in VETTED_IMPORTS propagates to every surface.
|
|
1265
|
+
const ALLOWED_BARE_IMPORTS = [
|
|
1266
|
+
...VETTED_IMPORTS.map((v) => v.specifier),
|
|
1267
|
+
...CORE_INFRA_BARE_IMPORTS,
|
|
1268
|
+
];
|
|
1254
1269
|
|
|
1255
1270
|
// REQ-WSDK-PLATFORM §3.5: host-API URL patterns the linter scans for as a
|
|
1256
1271
|
// soft warning. None of these block the lint by themselves — they prompt
|
|
@@ -1390,7 +1405,7 @@ const CONTRACT = deepFreeze({
|
|
|
1390
1405
|
// records(t).permissions(r) replaces the deleted ctx.recordPermissions),
|
|
1391
1406
|
// ctx.directory is a @colixsystems/directory-client (users/groups
|
|
1392
1407
|
// namespaces replace the deleted ctx.users / ctx.groups; list returns
|
|
1393
|
-
// envelopes), ctx.
|
|
1408
|
+
// envelopes), ctx.assets is a flattened @colixsystems/assets-client,
|
|
1394
1409
|
// ctx.payments is a @colixsystems/payments-client. All rows/bodies are
|
|
1395
1410
|
// snake_case. Hooks now unwrap the list envelope (res.data ?? []). The
|
|
1396
1411
|
// SDK stays duck-typed — it imports none of the four data SDKs. Minor
|
package/dist/contract.js
CHANGED
|
@@ -143,16 +143,16 @@ const HOOKS = [
|
|
|
143
143
|
scopes: ["datastore.read:<table>"],
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
|
-
name: "
|
|
147
|
-
signature: "
|
|
146
|
+
name: "useAsset",
|
|
147
|
+
signature: "useAsset(assetId)",
|
|
148
148
|
returnShape: {
|
|
149
149
|
url: "string | null",
|
|
150
|
-
|
|
150
|
+
asset: "{ id, url, storedFilename, mimeType, sizeBytes, ... } | null",
|
|
151
151
|
loading: "boolean",
|
|
152
152
|
error: "DatastoreError | null",
|
|
153
153
|
refetch: "() => Promise<void>",
|
|
154
154
|
},
|
|
155
|
-
requiredContextSlice: ["
|
|
155
|
+
requiredContextSlice: ["assets.get"],
|
|
156
156
|
scopes: null,
|
|
157
157
|
},
|
|
158
158
|
{
|
|
@@ -900,11 +900,11 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
900
900
|
required: true,
|
|
901
901
|
fields: { users: "object", groups: "object", bankid: "object" },
|
|
902
902
|
},
|
|
903
|
-
|
|
903
|
+
assets: {
|
|
904
904
|
description:
|
|
905
|
-
"Injected @colixsystems/
|
|
906
|
-
"{ get(id) -> Promise<{ id, url, ... }>, list(query) -> Promise<{ data, meta }>, upload(formData)
|
|
907
|
-
"Backs
|
|
905
|
+
"Injected @colixsystems/assets-client instance, FLATTENED so asset ops are top-level. " +
|
|
906
|
+
"{ get(id) -> Promise<{ id, url, ... }>, list(query) -> Promise<{ data, meta }>, upload(formData) }. " +
|
|
907
|
+
"Backs useAsset(); the returned asset already carries an absolute url the widget can drop into an <Image source>.",
|
|
908
908
|
required: true,
|
|
909
909
|
fields: { get: "function" },
|
|
910
910
|
},
|
|
@@ -1245,12 +1245,27 @@ const VETTED_IMPORTS = [
|
|
|
1245
1245
|
},
|
|
1246
1246
|
];
|
|
1247
1247
|
|
|
1248
|
+
// sc-1064: CORE React infrastructure specifiers the host RESOLVES at runtime
|
|
1249
|
+
// but that are NOT author-facing "vetted widget libraries". `react-dom` and
|
|
1250
|
+
// `react-dom/client` are transitive — `react-leaflet`'s Popup/Pane render
|
|
1251
|
+
// through `createPortal` from `react-dom`, so the host externalises + shims
|
|
1252
|
+
// them — but widget authors should never be encouraged to import react-dom
|
|
1253
|
+
// directly (unlike axios/date-fns/leaflet/…). They belong on
|
|
1254
|
+
// `allowedBareImports` (so the loader's shim⊆vetted guard treats them as
|
|
1255
|
+
// vetted) WITHOUT bloating the rich `VETTED_IMPORTS` reference the AI prompt /
|
|
1256
|
+
// Developer guide enumerate — the SAME treatment `react/jsx-runtime` gets, but
|
|
1257
|
+
// kept out of the author-facing list. Mirror of contract.cjs.
|
|
1258
|
+
const CORE_INFRA_BARE_IMPORTS = ["react-dom", "react-dom/client"];
|
|
1259
|
+
|
|
1248
1260
|
// Back-compat shape — every existing consumer (widgetLoader, the static
|
|
1249
1261
|
// analyzer's DEPENDENCY_ALLOWLIST, the AI prompt's "Allowed imports" line)
|
|
1250
1262
|
// reads a plain `string[]` from `CONTRACT.allowedBareImports`. Derive it
|
|
1251
|
-
// from the rich list so a single edit
|
|
1252
|
-
// every surface.
|
|
1253
|
-
const ALLOWED_BARE_IMPORTS =
|
|
1263
|
+
// from the rich list (plus the CORE infra specifiers above) so a single edit
|
|
1264
|
+
// in VETTED_IMPORTS propagates to every surface.
|
|
1265
|
+
const ALLOWED_BARE_IMPORTS = [
|
|
1266
|
+
...VETTED_IMPORTS.map((v) => v.specifier),
|
|
1267
|
+
...CORE_INFRA_BARE_IMPORTS,
|
|
1268
|
+
];
|
|
1254
1269
|
|
|
1255
1270
|
// REQ-WSDK-PLATFORM §3.5: host-API URL patterns the linter scans for as a
|
|
1256
1271
|
// soft warning. None of these block the lint by themselves — they prompt
|
|
@@ -1390,7 +1405,7 @@ const CONTRACT = deepFreeze({
|
|
|
1390
1405
|
// records(t).permissions(r) replaces the deleted ctx.recordPermissions),
|
|
1391
1406
|
// ctx.directory is a @colixsystems/directory-client (users/groups
|
|
1392
1407
|
// namespaces replace the deleted ctx.users / ctx.groups; list returns
|
|
1393
|
-
// envelopes), ctx.
|
|
1408
|
+
// envelopes), ctx.assets is a flattened @colixsystems/assets-client,
|
|
1394
1409
|
// ctx.payments is a @colixsystems/payments-client. All rows/bodies are
|
|
1395
1410
|
// snake_case. Hooks now unwrap the list envelope (res.data ?? []). The
|
|
1396
1411
|
// SDK stays duck-typed — it imports none of the four data SDKs. Minor
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// REQ-WSDK-DEVKIT v2 (sc-1027): shared shim-source generator used by BOTH
|
|
2
|
+
// `widgetLoader.buildShims()` (Studio runtime, blob URLs) AND the dev server's
|
|
3
|
+
// `/shim/<spec>` endpoint (when serving siblings of a multi-file widget).
|
|
4
|
+
//
|
|
5
|
+
// Both code paths produce ESM that re-exports the matching key out of
|
|
6
|
+
// `globalThis.__appstudioWidgetHost__` — populated by the Studio's `buildShims`
|
|
7
|
+
// before any widget bundle is evaluated. Keeping the shim sources in one place
|
|
8
|
+
// means a vetted-package addition lands once and both paths see it.
|
|
9
|
+
//
|
|
10
|
+
// Pure JS, no runtime deps — safe to import from the SDK dev server (Node)
|
|
11
|
+
// and from the Studio loader (browser).
|
|
12
|
+
//
|
|
13
|
+
// LIMITATION (v1): for SIBLING files served by the dev server's `/file/<rel>`
|
|
14
|
+
// endpoint, only the specifiers with a statically-known named-export list are
|
|
15
|
+
// shimmable through `/shim/<spec>`: `react`, `react/jsx-runtime`,
|
|
16
|
+
// `react/jsx-dev-runtime`, and `@colixsystems/widget-sdk`. Any other vetted
|
|
17
|
+
// package (`lucide-react-native`, `react-native-svg`, `date-fns`, ...) must be
|
|
18
|
+
// imported from the widget's ENTRY (where the Studio's blob-shim path
|
|
19
|
+
// runtime-enumerates the host's namespace). Imports of these packages from a
|
|
20
|
+
// sibling .jsx file return `422` from the dev server with a clear message.
|
|
21
|
+
|
|
22
|
+
// React named exports the Studio re-exposes through the shim. Mirrors the
|
|
23
|
+
// browser's `react` named-export surface. Adding a new hook in a React minor
|
|
24
|
+
// release means appending it here.
|
|
25
|
+
export const REACT_NAMED_EXPORTS = [
|
|
26
|
+
"Children",
|
|
27
|
+
"Component",
|
|
28
|
+
"Fragment",
|
|
29
|
+
"Profiler",
|
|
30
|
+
"PureComponent",
|
|
31
|
+
"StrictMode",
|
|
32
|
+
"Suspense",
|
|
33
|
+
"cloneElement",
|
|
34
|
+
"createContext",
|
|
35
|
+
"createElement",
|
|
36
|
+
"createFactory",
|
|
37
|
+
"createRef",
|
|
38
|
+
"forwardRef",
|
|
39
|
+
"isValidElement",
|
|
40
|
+
"lazy",
|
|
41
|
+
"memo",
|
|
42
|
+
"startTransition",
|
|
43
|
+
"useCallback",
|
|
44
|
+
"useContext",
|
|
45
|
+
"useDebugValue",
|
|
46
|
+
"useDeferredValue",
|
|
47
|
+
"useEffect",
|
|
48
|
+
"useId",
|
|
49
|
+
"useImperativeHandle",
|
|
50
|
+
"useInsertionEffect",
|
|
51
|
+
"useLayoutEffect",
|
|
52
|
+
"useMemo",
|
|
53
|
+
"useReducer",
|
|
54
|
+
"useRef",
|
|
55
|
+
"useState",
|
|
56
|
+
"useSyncExternalStore",
|
|
57
|
+
"useTransition",
|
|
58
|
+
"version",
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
// React's automatic JSX runtime: jsx / jsxs / Fragment, plus the dev variant.
|
|
62
|
+
export const REACT_JSX_RUNTIME_EXPORTS = ["jsx", "jsxs", "Fragment", "jsxDEV"];
|
|
63
|
+
|
|
64
|
+
// REQ-WSDK-PLATFORM bundle (sc-1064): the canonical list of bare specifiers the
|
|
65
|
+
// runtime web host RESOLVES for a loaded widget — i.e. the ones the Studio's
|
|
66
|
+
// `widgetLoader.buildShims()` re-exports from `globalThis.__appstudioWidgetHost__`
|
|
67
|
+
// rather than letting a bundle inline a second copy. The web-entry bundler
|
|
68
|
+
// (`webbundle.bundleWebEntry`, used by both the publish packer and the dev
|
|
69
|
+
// server) marks EXACTLY these `external`, so everything else the entry imports
|
|
70
|
+
// (`react-leaflet`, `leaflet`, CSS, PNG assets, …) gets inlined.
|
|
71
|
+
//
|
|
72
|
+
// This is the SINGLE source of truth (CLAUDE.md §3). It MUST stay in lockstep
|
|
73
|
+
// with the frontend's `widgetLoader._hostVettedModules()` + the core React/SDK
|
|
74
|
+
// shims it builds. Two backstops enforce the equality: (1) this list's
|
|
75
|
+
// contents are pinned by the SDK-side importable test
|
|
76
|
+
// (`packages/widget-sdk/src/__tests__/host-externals.test.js`), and (2) the
|
|
77
|
+
// loader's own module-load guard in `frontend/src/services/widgetLoader.js`
|
|
78
|
+
// throws at import time if `hostShimmedSpecifiers()` drifts from
|
|
79
|
+
// `hostExternalSpecifiers()` — the loader's shimmed set can't be asserted from
|
|
80
|
+
// a Node test (it imports `react-dom` etc.), so that equality is enforced by
|
|
81
|
+
// the load-time guard rather than a separate frontend test.
|
|
82
|
+
//
|
|
83
|
+
// Why each entry is host-resolved (NOT bundled):
|
|
84
|
+
// * `react`, `react/jsx-runtime`, `react/jsx-dev-runtime` — the widget MUST
|
|
85
|
+
// share the host's ONE React instance (hooks + context); a bundled second
|
|
86
|
+
// React breaks both.
|
|
87
|
+
// * `react-dom`, `react-dom/client` — `react-leaflet`'s Popup/Pane render
|
|
88
|
+
// through `createPortal` from `react-dom`. A bundled second react-dom
|
|
89
|
+
// paired with the host's external React is a mismatched renderer and
|
|
90
|
+
// crashes. The Studio is a React-DOM app, so it shims its own react-dom.
|
|
91
|
+
// On React 19 the two specifiers expose DIFFERENT surfaces — createPortal /
|
|
92
|
+
// flushSync / version live on `react-dom`, createRoot / hydrateRoot on
|
|
93
|
+
// `react-dom/client` — so the loader stashes + shims each from its own real
|
|
94
|
+
// host namespace (sc-1064).
|
|
95
|
+
// * `@colixsystems/widget-sdk` — the widget must route hooks through the SAME
|
|
96
|
+
// SDK instance the host built (datastore/theme/navigation live there).
|
|
97
|
+
// * `lucide-react-native`, `react-native-svg`, `date-fns` — vetted packages
|
|
98
|
+
// the host already bundles + shims (`_hostVettedModules`); sharing the
|
|
99
|
+
// host copy keeps icons/SVG on the host's react-native-web instance.
|
|
100
|
+
const HOST_EXTERNAL_SPECIFIERS = [
|
|
101
|
+
"react",
|
|
102
|
+
"react/jsx-runtime",
|
|
103
|
+
"react/jsx-dev-runtime",
|
|
104
|
+
"react-dom",
|
|
105
|
+
"react-dom/client",
|
|
106
|
+
"@colixsystems/widget-sdk",
|
|
107
|
+
"lucide-react-native",
|
|
108
|
+
"react-native-svg",
|
|
109
|
+
"date-fns",
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The canonical "host-resolved at runtime" bare-specifier set — the externals
|
|
114
|
+
* the web-entry bundler must NOT inline. Returns a fresh array each call so a
|
|
115
|
+
* caller can't mutate the source of truth.
|
|
116
|
+
*
|
|
117
|
+
* @returns {string[]}
|
|
118
|
+
*/
|
|
119
|
+
export function hostExternalSpecifiers() {
|
|
120
|
+
return [...HOST_EXTERNAL_SPECIFIERS];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function reactShimSrc() {
|
|
124
|
+
const host = "globalThis.__appstudioWidgetHost__.React";
|
|
125
|
+
const named = REACT_NAMED_EXPORTS.map(
|
|
126
|
+
(n) => `export const ${n} = (${host})[${JSON.stringify(n)}];`,
|
|
127
|
+
).join("\n");
|
|
128
|
+
return `const __host = ${host};\nexport default __host;\n${named}\n`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function reactJsxRuntimeShimSrc() {
|
|
132
|
+
const host = "globalThis.__appstudioWidgetHost__.ReactJSXRuntime";
|
|
133
|
+
const named = REACT_JSX_RUNTIME_EXPORTS.map(
|
|
134
|
+
(n) => `export const ${n} = (${host})[${JSON.stringify(n)}];`,
|
|
135
|
+
).join("\n");
|
|
136
|
+
return named;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// react-dom named exports a bundled widget might reach through the host shim.
|
|
140
|
+
// `react-leaflet`'s Popup/Pane/SVGOverlay use `createPortal`; `flushSync`
|
|
141
|
+
// rounds out the surface react-leaflet may touch. These are the names that
|
|
142
|
+
// genuinely EXIST on the `react-dom` namespace in React 19 — `createRoot` /
|
|
143
|
+
// `hydrateRoot` moved to `react-dom/client`, and `render` /
|
|
144
|
+
// `unmountComponentAtNode` / `findDOMNode` were removed entirely, so listing
|
|
145
|
+
// them here would re-export `undefined` (sc-1064). `version` is always present.
|
|
146
|
+
// Mirrors REACT_NAMED_EXPORTS' hand-list-of-the-named-surface approach (a blob
|
|
147
|
+
// module can't `export *`).
|
|
148
|
+
export const REACT_DOM_NAMED_EXPORTS = ["createPortal", "flushSync", "version"];
|
|
149
|
+
|
|
150
|
+
// React 19: `createRoot` / `hydrateRoot` live ONLY on `react-dom/client`. The
|
|
151
|
+
// `react-dom/client` shim sources these from the host's REAL `react-dom/client`
|
|
152
|
+
// namespace (stashed as `ReactDOMClient`), NOT from the `react-dom` namespace
|
|
153
|
+
// where they are `undefined` on v19. `version` is present on both.
|
|
154
|
+
export const REACT_DOM_CLIENT_NAMED_EXPORTS = [
|
|
155
|
+
"createRoot",
|
|
156
|
+
"hydrateRoot",
|
|
157
|
+
"version",
|
|
158
|
+
];
|
|
159
|
+
|
|
160
|
+
function reactDomShimSrc() {
|
|
161
|
+
const host = "globalThis.__appstudioWidgetHost__.ReactDOM";
|
|
162
|
+
const named = REACT_DOM_NAMED_EXPORTS.map(
|
|
163
|
+
(n) => `export const ${n} = (${host})[${JSON.stringify(n)}];`,
|
|
164
|
+
).join("\n");
|
|
165
|
+
return `const __host = ${host};\nexport default __host;\n${named}\n`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function reactDomClientShimSrc() {
|
|
169
|
+
const host = "globalThis.__appstudioWidgetHost__.ReactDOMClient";
|
|
170
|
+
const named = REACT_DOM_CLIENT_NAMED_EXPORTS.map(
|
|
171
|
+
(n) => `export const ${n} = (${host})[${JSON.stringify(n)}];`,
|
|
172
|
+
).join("\n");
|
|
173
|
+
return `const __host = ${host};\nexport default __host;\n${named}\n`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function sdkShimSrc(sdkNamedExports) {
|
|
177
|
+
const host = "globalThis.__appstudioWidgetHost__.sdk";
|
|
178
|
+
const names = (Array.isArray(sdkNamedExports) ? sdkNamedExports : []).filter(
|
|
179
|
+
(n) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n),
|
|
180
|
+
);
|
|
181
|
+
const named = names
|
|
182
|
+
.map((n) => `export const ${n} = (${host})[${JSON.stringify(n)}];`)
|
|
183
|
+
.join("\n");
|
|
184
|
+
return `const __host = ${host};\nexport default __host;\n${named}\n`;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Build a shim ESM source for a vetted bare specifier with a statically-known
|
|
189
|
+
* named-export shape. Returns null when the specifier isn't shimmable from a
|
|
190
|
+
* sibling file — the caller surfaces this as a clear error.
|
|
191
|
+
*
|
|
192
|
+
* @param {string} specifier bare import specifier (e.g. "react")
|
|
193
|
+
* @param {object} [opts]
|
|
194
|
+
* @param {string[]} [opts.sdkExports] named-export list for
|
|
195
|
+
* "@colixsystems/widget-sdk" — caller passes this since the dev server
|
|
196
|
+
* doesn't statically load the SDK.
|
|
197
|
+
* @returns {string | null}
|
|
198
|
+
*/
|
|
199
|
+
export function getShimSource(specifier, opts = {}) {
|
|
200
|
+
switch (specifier) {
|
|
201
|
+
case "react":
|
|
202
|
+
return reactShimSrc();
|
|
203
|
+
case "react/jsx-runtime":
|
|
204
|
+
case "react/jsx-dev-runtime":
|
|
205
|
+
return reactJsxRuntimeShimSrc();
|
|
206
|
+
case "react-dom":
|
|
207
|
+
return reactDomShimSrc();
|
|
208
|
+
case "react-dom/client":
|
|
209
|
+
return reactDomClientShimSrc();
|
|
210
|
+
case "@colixsystems/widget-sdk":
|
|
211
|
+
return sdkShimSrc(opts.sdkExports);
|
|
212
|
+
default:
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The set of bare specifiers a SIBLING file may import — i.e. the keys
|
|
219
|
+
* `getShimSource` recognises. Anything outside this set must move to the
|
|
220
|
+
* entry, where the Studio's runtime blob-shim path enumerates the full
|
|
221
|
+
* `CONTRACT.allowedBareImports` surface (REQ-WSDK-PLATFORM §3.4).
|
|
222
|
+
*
|
|
223
|
+
* @returns {string[]}
|
|
224
|
+
*/
|
|
225
|
+
export function shimmableSpecifiersForSiblings() {
|
|
226
|
+
return [
|
|
227
|
+
"react",
|
|
228
|
+
"react/jsx-runtime",
|
|
229
|
+
"react/jsx-dev-runtime",
|
|
230
|
+
"@colixsystems/widget-sdk",
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Stable URL-safe slug for a bare specifier — used as the path segment under
|
|
236
|
+
* `/shim/` so a specifier like `react/jsx-runtime` doesn't need URL encoding
|
|
237
|
+
* on the wire. Reversed by `shimSpecifierFromSlug` on the server.
|
|
238
|
+
*
|
|
239
|
+
* @param {string} specifier
|
|
240
|
+
* @returns {string}
|
|
241
|
+
*/
|
|
242
|
+
export function shimSlugFor(specifier) {
|
|
243
|
+
return specifier.replace(/\//g, "__").replace(/@/g, "_at_");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Reverse of `shimSlugFor`. Returns the bare specifier; the caller validates
|
|
248
|
+
* it against `shimmableSpecifiersForSiblings()` before serving.
|
|
249
|
+
*
|
|
250
|
+
* @param {string} slug
|
|
251
|
+
* @returns {string}
|
|
252
|
+
*/
|
|
253
|
+
export function shimSpecifierFromSlug(slug) {
|
|
254
|
+
return slug.replace(/_at_/g, "@").replace(/__/g, "/");
|
|
255
|
+
}
|