@colixsystems/widget-sdk 0.59.0 → 0.60.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 CHANGED
@@ -52,7 +52,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
52
52
 
53
53
  ## Status
54
54
 
55
- `v0.59.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**.
55
+ `v0.60.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**.
56
+
57
+ ### What's new in 0.60.0
58
+
59
+ **The host fills `propertySchema` defaults onto props (sc-3228).** The platform host now applies a widget's manifest `default`s at its render boundary: for every leaf a page left unset it substitutes the declared `default`; an explicitly-bound value passes through untouched. The web Player and the native Expo export both do this against the widget's `propertySchema`, so an unset `columnRef` / field binding arrives as its declared default (e.g. `"Title"`) on BOTH hosts instead of `undefined`. **For widget authors this means: read `props.<field>` directly — the in-code `props.titleField || "Title"` fallback pattern is no longer needed and should be removed.** This is done for you by the host; there is no author API to call. (The resolver lives at the host-only subpath `@colixsystems/widget-sdk/host`, consumed by the platform hosts, not by widgets.) `CONTRACT.version` → `1.41.0`. Additive — no existing export changed signature.
56
60
 
57
61
  ### What's new in 0.59.0
58
62
 
@@ -214,7 +218,7 @@ Also: `useFileSignatures(fileIds)` is now **self-scoped** (the caller's own sign
214
218
 
215
219
  **Filestore browsing + BankID file signing for widgets (REQ-FS / REQ-SIGN).** Three new hooks read a newly-injected `ctx.filestore` (the `@colixsystems/filestore-client`, now constructed by both the web and native hosts):
216
220
  - `useFilestoreFiles({ spaceType, folderId?, q?, type? })` → `{ files, loading, error, refetch }` — browses the end-user's Filestore space. The hook resolves `owner_id` from the host context (tenant for a project space, the app user for a personal space), so the widget only picks the space.
217
- - `useFilestoreFile(fileId)` → `{ file, url, loading, error, refetch }` — resolves ONE file id (as held in a datastore `FILE` column) to a displayable `url` (its `presigned_url`, absolutized for web + native) via `ctx.filestore.files.get(id)`. Empty / deleted / not-found ids resolve to `url: null` so a display widget shows a fallback. Requires `files.read:*`.
221
+ - `useFilestoreFile(fileId)` → `{ file, url, loading, error, refetch }` — resolves ONE file id to a displayable `url` (its `presigned_url`, absolutized for web + native) via `ctx.filestore.files.get(id)`. A datastore `FILE` column holds — and reads back as — that **bare file-id string**; it is NOT hydrated into an object the way a `RELATION` (`{ id, label }`) or `USER` (`{ id, name }`) column is, so pass the value straight to the hook (no `{ id }` / `{ url }` unwrapping guard). Empty / deleted / not-found ids resolve to `url: null` so a display widget shows a fallback. Requires `files.read:*`.
218
222
  - `useFilestoreFolders({ spaceType, parentFolderId?, q?, enabled? })` → `{ folders, loading, error, refetch }` — the folder-navigation companion to `useFilestoreFiles`; pass `enabled:false` to suspend fetching.
219
223
  - `useFilestoreUpload({ spaceType, folderId? })` → `{ upload, uploading, error, lastUploaded }` — POSTs a multipart upload to `ctx.filestore.files.upload`. Resolves `owner_id` from the host context (like the read hooks) so the widget only picks the space + destination folder. Pair with the `<FilePicker>` primitive for the visible trigger. Requires the `files.write:*` scope.
220
224
  - `useFileSignature(fileId)` → `{ status, qr, signerName, verdict, initiate, refresh, cancel, verify, … }` — drives a BankID signing flow for a file (the backend hashes the bytes server-side, binds the digest into the signature, and verifies the proof offline).
package/dist/contract.cjs CHANGED
@@ -1891,7 +1891,14 @@ const CONTRACT = deepFreeze({
1891
1891
  // filestore file id (as held in a datastore FILE column) to a
1892
1892
  // displayable `url` (its presigned_url, absolutized for web + native).
1893
1893
  // New read hook, no existing behaviour changes — minor bump.
1894
- version: "1.40.0",
1894
+ // 1.41.0: additive (sc-3228) — the host (web Player + native export) now
1895
+ // fills a widget's propertySchema `default`s onto props at the render
1896
+ // boundary, so an unset `columnRef` / field binding arrives as its declared
1897
+ // default instead of undefined. A widget reads `props.<field>` directly —
1898
+ // no in-code `|| "fallback"`. Backed by a host-only subpath export
1899
+ // (`@colixsystems/widget-sdk/host` -> resolveProps); the author-facing entry
1900
+ // is unchanged. No existing behaviour changes — minor bump.
1901
+ version: "1.41.0",
1895
1902
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
1896
1903
  hooks: HOOKS,
1897
1904
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -1891,7 +1891,14 @@ const CONTRACT = deepFreeze({
1891
1891
  // filestore file id (as held in a datastore FILE column) to a
1892
1892
  // displayable `url` (its presigned_url, absolutized for web + native).
1893
1893
  // New read hook, no existing behaviour changes — minor bump.
1894
- version: "1.40.0",
1894
+ // 1.41.0: additive (sc-3228) — the host (web Player + native export) now
1895
+ // fills a widget's propertySchema `default`s onto props at the render
1896
+ // boundary, so an unset `columnRef` / field binding arrives as its declared
1897
+ // default instead of undefined. A widget reads `props.<field>` directly —
1898
+ // no in-code `|| "fallback"`. Backed by a host-only subpath export
1899
+ // (`@colixsystems/widget-sdk/host` -> resolveProps); the author-facing entry
1900
+ // is unchanged. No existing behaviour changes — minor bump.
1901
+ version: "1.41.0",
1895
1902
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
1896
1903
  hooks: HOOKS,
1897
1904
  primitives: PRIMITIVES,
package/dist/host.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ // Host-integration surface — not the author-facing widget API. See host.js.
2
+ import type { WidgetPropertySchema } from "./index";
3
+
4
+ /**
5
+ * Host render-boundary helper: fills a widget's propertySchema `default`s onto
6
+ * props for unset (undefined/null) leaves; explicitly-bound values pass
7
+ * through. Never validates or coerces; always returns the merged object.
8
+ * Applied by the platform hosts, never by widget authors.
9
+ */
10
+ export function resolveProps<T = Record<string, unknown>>(
11
+ schema: WidgetPropertySchema,
12
+ props: unknown,
13
+ ): T;
package/dist/host.js ADDED
@@ -0,0 +1,12 @@
1
+ // Host-integration surface — NOT part of the author-facing widget API.
2
+ // These exports are consumed only by the platform hosts that render widgets
3
+ // (the web Player / Studio Canvas and the native Expo export), never by a
4
+ // widget author. Authors receive already-correct props and never call these.
5
+ //
6
+ // `resolveProps` lives here (re-exported from property-schema.js, the single
7
+ // source of schema semantics) so the host can fill a widget's declared
8
+ // propertySchema `default`s onto props at its render boundary. It is
9
+ // deliberately kept off the main entry (`@colixsystems/widget-sdk`) so it does
10
+ // not appear in the author import surface or the Developer guide.
11
+
12
+ export { resolveProps } from "./property-schema.js";
@@ -24,6 +24,8 @@ export {
24
24
  useFilestoreFolders,
25
25
  useFileSignature,
26
26
  useFileSignatures,
27
+ useFileRoster,
28
+ useFolderPermissions,
27
29
  useDatastoreMutation,
28
30
  useDirectory,
29
31
  useUsers,
@@ -243,3 +243,56 @@ export function validateProps(schema, props) {
243
243
  }
244
244
  return errors.length === 0 ? { ok: true, value: out } : { ok: false, errors };
245
245
  }
246
+
247
+ // Defaults are static config; clone object/array ones so a widget mutating
248
+ // its props can never corrupt the shared manifest default.
249
+ function cloneDefault(value) {
250
+ if (value === null || typeof value !== "object") return value;
251
+ return JSON.parse(JSON.stringify(value));
252
+ }
253
+
254
+ function resolveLeaf(def, value) {
255
+ if (!isPlainObject(def)) return value;
256
+ if (value === undefined || value === null) {
257
+ return def.default !== undefined ? cloneDefault(def.default) : value;
258
+ }
259
+ if (
260
+ def.type === "object" &&
261
+ isPlainObject(def.properties) &&
262
+ isPlainObject(value)
263
+ ) {
264
+ const out = { ...value };
265
+ for (const [k, child] of Object.entries(def.properties)) {
266
+ out[k] = resolveLeaf(child, value[k]);
267
+ }
268
+ return out;
269
+ }
270
+ // Fill per-element defaults for an author-supplied array<object> (e.g. a
271
+ // `columns` list whose item objects carry field-level defaults).
272
+ if (def.type === "array" && isPlainObject(def.items) && Array.isArray(value)) {
273
+ return value.map((item) => resolveLeaf(def.items, item));
274
+ }
275
+ return value;
276
+ }
277
+
278
+ /**
279
+ * Fills in a widget's `propertySchema` defaults on `props` for the host render
280
+ * boundary: any leaf the author left unset (undefined/null) takes its declared
281
+ * `default`; an explicitly-set value passes through untouched. Unlike
282
+ * {@link validateProps} it never validates or coerces and always returns the
283
+ * merged object — a partially-configured binding stays valid while the author
284
+ * is still picking. Applied once by the host (web Player + native export) so a
285
+ * widget reads `props.<field>` directly without in-code fallbacks.
286
+ * @param {Record<string, any>} schema
287
+ * @param {unknown} props
288
+ * @returns {Record<string, unknown>}
289
+ */
290
+ export function resolveProps(schema, props) {
291
+ const input = isPlainObject(props) ? props : {};
292
+ if (!isPlainObject(schema)) return input;
293
+ const out = { ...input };
294
+ for (const [k, def] of Object.entries(schema)) {
295
+ out[k] = resolveLeaf(def, input[k]);
296
+ }
297
+ return out;
298
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.59.0",
3
+ "version": "0.60.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,6 +22,12 @@
22
22
  "import": "./dist/dev-shims.js",
23
23
  "default": "./dist/dev-shims.js"
24
24
  },
25
+ "./host": {
26
+ "types": "./dist/host.d.ts",
27
+ "react-native": "./dist/host.js",
28
+ "import": "./dist/host.js",
29
+ "default": "./dist/host.js"
30
+ },
25
31
  "./contract": {
26
32
  "types": "./dist/index.d.ts",
27
33
  "require": "./dist/contract.cjs",
@@ -42,7 +48,7 @@
42
48
  ],
43
49
  "scripts": {
44
50
  "build": "node scripts/build.js",
45
- "test": "node --test src/__tests__/contract.test.js src/__tests__/hooks-users.test.js src/__tests__/hooks-groups.test.js src/__tests__/hooks-schema.test.js src/__tests__/hooks-assets-by-tag.test.js src/__tests__/hooks-filestore-upload.test.js src/__tests__/hooks-mutation.test.js src/__tests__/hooks-record-permissions.test.js src/__tests__/hooks-geolocation.test.js src/__tests__/hooks-subscription.test.js src/__tests__/linter-users-scope.test.js src/__tests__/linter-comments.test.js src/__tests__/linter-platform.test.js src/__tests__/linter-react-import.test.js src/__tests__/lucide-icon-names.test.js src/__tests__/lucideIconName.test.js src/__tests__/manifest-actions.test.js src/__tests__/widget-translations.test.js src/__tests__/devserver.test.js src/__tests__/host-externals.test.js src/__tests__/datetimepicker.test.js"
51
+ "test": "node --test src/__tests__/contract.test.js src/__tests__/hooks-users.test.js src/__tests__/hooks-groups.test.js src/__tests__/hooks-schema.test.js src/__tests__/hooks-assets-by-tag.test.js src/__tests__/hooks-filestore-upload.test.js src/__tests__/hooks-mutation.test.js src/__tests__/hooks-record-permissions.test.js src/__tests__/hooks-geolocation.test.js src/__tests__/hooks-subscription.test.js src/__tests__/linter-users-scope.test.js src/__tests__/linter-comments.test.js src/__tests__/linter-platform.test.js src/__tests__/linter-react-import.test.js src/__tests__/lucide-icon-names.test.js src/__tests__/lucideIconName.test.js src/__tests__/manifest-actions.test.js src/__tests__/widget-translations.test.js src/__tests__/devserver.test.js src/__tests__/host-externals.test.js src/__tests__/datetimepicker.test.js src/__tests__/property-schema-resolve.test.js"
46
52
  },
47
53
  "engines": {
48
54
  "node": ">=18"