@colixsystems/widget-sdk 0.9.0 → 0.10.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
@@ -6,7 +6,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
6
6
 
7
7
  ## Status
8
8
 
9
- `v0.9.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**.
9
+ `v0.10.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**.
10
+
11
+ ### What's new in 0.10.0
12
+
13
+ - **`useUser()` is wired.** Returns the active end-user identity `{ id, email, displayName, roles, groupIds }` from the host-provided `WidgetContext`. `id` is `null` for anonymous visitors and on the Studio canvas preview. All fields are guaranteed present (the host fills safe defaults), so widgets read them without optional chaining. Additive — no migration needed for existing widgets.
10
14
 
11
15
  ### What's new in 0.9.0
12
16
 
@@ -71,7 +75,7 @@ import { defineWidget, validateManifest, useDatastoreQuery, Text, View } from "@
71
75
 
72
76
  - `defineWidget({ manifest, component })` — validates the manifest and produces a widget module the host can register.
73
77
  - `validateManifest(m)` / `validatePropertySchema(s)` / `validateProps(schema, props)` — shape validation; no third-party deps.
74
- - `useDatastoreQuery`, `useDatastoreMutation`, `useDirectory`, `useWidgetEvent`, `usePayments`, `useTheme`, `useI18n` — hooks that read from the host-provided `WidgetContext`. `useDirectory(query?)` returns `{ users, loading, error, refetch }` (each user `{ id, name, role }`) and requires the `directory.read:users` scope. `usePayments()` returns `{ requestPayment, getPayment }` and requires the `payments.charge:appUser` scope; `requestPayment(...)` rejects with a `PaymentError`.
78
+ - `useDatastoreQuery`, `useDatastoreMutation`, `useDirectory`, `useWidgetEvent`, `usePayments`, `useTheme`, `useI18n`, `useUser` — hooks that read from the host-provided `WidgetContext`. `useDirectory(query?)` returns `{ users, loading, error, refetch }` (each user `{ id, name, role }`) and requires the `directory.read:users` scope. `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, displayName, roles, groupIds }` (`id` is `null` for anonymous / preview).
75
79
  - `Text`, `View`, `Pressable`, `Image`, `ScrollView`, `TextInput`, `FlatList`, `SectionList`, `ActivityIndicator`, `Switch`, `StyleSheet` — re-exported from `react-native`. 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. See https://reactnative.dev/docs/ for per-component props.
76
80
  - `WidgetContextProvider` — React context provider that the host (Studio, Player, exported app) wraps widgets with.
77
81
 
package/dist/contract.cjs CHANGED
@@ -55,6 +55,19 @@ const HOOKS = [
55
55
  requiredContextSlice: ["i18n.t", "i18n.locale"],
56
56
  scopes: null,
57
57
  },
58
+ {
59
+ name: "useUser",
60
+ signature: "useUser()",
61
+ returnShape: {
62
+ id: "string | null",
63
+ email: "string | null",
64
+ displayName: "string | null",
65
+ roles: "string[]",
66
+ groupIds: "string[]",
67
+ },
68
+ requiredContextSlice: ["user"],
69
+ scopes: null,
70
+ },
58
71
  {
59
72
  name: "useDatastoreQuery",
60
73
  signature: "useDatastoreQuery(tableId, options?)",
package/dist/contract.js CHANGED
@@ -55,6 +55,19 @@ const HOOKS = [
55
55
  requiredContextSlice: ["i18n.t", "i18n.locale"],
56
56
  scopes: null,
57
57
  },
58
+ {
59
+ name: "useUser",
60
+ signature: "useUser()",
61
+ returnShape: {
62
+ id: "string | null",
63
+ email: "string | null",
64
+ displayName: "string | null",
65
+ roles: "string[]",
66
+ groupIds: "string[]",
67
+ },
68
+ requiredContextSlice: ["user"],
69
+ scopes: null,
70
+ },
58
71
  {
59
72
  name: "useDatastoreQuery",
60
73
  signature: "useDatastoreQuery(tableId, options?)",
package/dist/hooks.js CHANGED
@@ -352,6 +352,24 @@ export function useTheme() {
352
352
  return ctx.workspace.theme;
353
353
  }
354
354
 
355
+ /**
356
+ * Returns the active end-user identity:
357
+ * `{ id, email, displayName, roles, groupIds }`.
358
+ *
359
+ * `id` is `null` for anonymous visitors (and on the Studio canvas preview,
360
+ * which renders widgets as if signed-out so the public branch shows). All
361
+ * fields are guaranteed present by the host (`buildHostWidgetContext`
362
+ * + the native `WidgetHost`); widgets read them without optional chaining.
363
+ *
364
+ * Use this to render the signed-in user's name in a header, branch on
365
+ * roles, or stamp a created-by field. Email is opaque to widgets that
366
+ * only need a display name — prefer `displayName` for UI strings.
367
+ */
368
+ export function useUser() {
369
+ const ctx = useWidgetContextOrThrow("useUser");
370
+ return ctx.user;
371
+ }
372
+
355
373
  /**
356
374
  * Structured error thrown by `usePayments` callbacks. Carries a stable
357
375
  * `code` so widgets can branch without parsing message strings.
package/dist/index.d.ts CHANGED
@@ -368,6 +368,19 @@ export function useI18n(): {
368
368
  t(key: string, fallback?: string): string;
369
369
  };
370
370
 
371
+ /**
372
+ * The active end-user identity. `id` is null for anonymous visitors and on
373
+ * the Studio canvas preview; every field is guaranteed present (the host
374
+ * fills safe defaults), so widgets read them without optional chaining.
375
+ */
376
+ export function useUser(): {
377
+ id: string | null;
378
+ email: string | null;
379
+ displayName: string | null;
380
+ roles: string[];
381
+ groupIds: string[];
382
+ };
383
+
371
384
  /**
372
385
  * Error class thrown by useDatastoreMutation callbacks (and surfaced by
373
386
  * useDatastoreQuery in its `error` slot). The `code` is a stable
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ export {
16
16
  usePayments,
17
17
  useTheme,
18
18
  useI18n,
19
+ useUser,
19
20
  } from "./hooks.js";
20
21
  export {
21
22
  Text,
@@ -16,6 +16,7 @@ export {
16
16
  usePayments,
17
17
  useTheme,
18
18
  useI18n,
19
+ useUser,
19
20
  } from "./hooks.js";
20
21
  export {
21
22
  Text,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.9.0",
3
+ "version": "0.10.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",