@colixsystems/widget-sdk 0.205.1 → 0.207.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.
@@ -18,7 +18,7 @@ export const TOAST_DEFAULTS = Object.freeze({
18
18
  const KINDS = Object.freeze(["success", "error", "warning", "info"]);
19
19
 
20
20
  // `error` is the widget-facing kind; `danger` is the theme's colour role.
21
- const KIND_COLOR_ROLE = Object.freeze({
21
+ export const KIND_COLOR_ROLE = Object.freeze({
22
22
  success: "success",
23
23
  error: "danger",
24
24
  warning: "warning",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.205.1",
3
+ "version": "0.207.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "homepage": "https://github.com/Colix-AB/AppStudio",
6
6
  "type": "module",
package/src/contract.js CHANGED
@@ -704,6 +704,25 @@ const THEME_COMPONENTS = Object.freeze({
704
704
  }),
705
705
  targets: Object.freeze({}),
706
706
  }),
707
+ // Inline messages: `<Banner>` reads this scope directly, so it names the
708
+ // SDK component it styles and binds no widget field.
709
+ alert: Object.freeze({
710
+ label: "Alerts",
711
+ sdkComponents: Object.freeze(["Banner"]),
712
+ tokens: Object.freeze({
713
+ radius: Object.freeze({ type: "size", min: 0, max: 32, uiDefault: "radii.md" }),
714
+ borderWidth: Object.freeze({ type: "size", min: 0, max: 4 }),
715
+ infoBackground: Object.freeze({ type: "color" }),
716
+ infoTextColor: Object.freeze({ type: "color" }),
717
+ successBackground: Object.freeze({ type: "color" }),
718
+ successTextColor: Object.freeze({ type: "color" }),
719
+ warningBackground: Object.freeze({ type: "color" }),
720
+ warningTextColor: Object.freeze({ type: "color" }),
721
+ errorBackground: Object.freeze({ type: "color" }),
722
+ errorTextColor: Object.freeze({ type: "color" }),
723
+ }),
724
+ targets: Object.freeze({}),
725
+ }),
707
726
  });
708
727
 
709
728
  // sc-4505 — the value types a widget event payload field may declare. Narrower
@@ -2064,6 +2083,62 @@ const HOOKS = [
2064
2083
  requiredContextSlice: ["directory.users"],
2065
2084
  scopes: ["users.activity:*"],
2066
2085
  },
2086
+ // sc-11025 / REQ-USERMGMT-12 — online status for people who share a record.
2087
+ {
2088
+ name: "useOnlineMembers",
2089
+ signature: "useOnlineMembers(tableId, recordIds)",
2090
+ description:
2091
+ "Who is online among the members of each record the viewer is a " +
2092
+ "member of (a conversation, a team, a case), on a table that shows its " +
2093
+ "members' online status (a template table's `presence: true`, or the " +
2094
+ "table setting in the Studio). Members hold their OWN read grant on the " +
2095
+ "record, given to them by a person (a grant from a template or one " +
2096
+ "inherited from a parent row names no member). `online` is a Set of " +
2097
+ "the user ids online across the records; `byRecord[recordId]` is " +
2098
+ "{ online_user_ids, online_count } — the ids are capped at 100 per " +
2099
+ "record, so count with `online_count`. A record the viewer only reads " +
2100
+ "(through a group or a grant to everyone) or cannot read answers with " +
2101
+ "nobody. Refreshes every minute while the app is in front, on return " +
2102
+ "to it and on pull-to-refresh. `supported` is true only once the " +
2103
+ "workspace answered: it is false while the workspace does not record " +
2104
+ "user activity, when the table has not opted in, when the viewer hides " +
2105
+ "their own status (useOnlineVisibility), and in a preview — then show " +
2106
+ "NO online state at all, never \"offline\". The viewer's own id may be " +
2107
+ "in `online`; leave it out when you mean \"someone else is here\". " +
2108
+ "Never timestamps. Declare `directory.read:users`: the publish checks " +
2109
+ "do not require it for this hook, but it is the scope the hook belongs to.",
2110
+ returnShape: {
2111
+ supported: "boolean // false: render no online dots, no counts, no 'offline' state",
2112
+ online: "Set<string> // user ids online across the records",
2113
+ byRecord: "{ [recordId]: { online_user_ids: string[], online_count: number } }",
2114
+ loading: "boolean",
2115
+ error: "DirectoryError | null // reason ACTIVITY_UNAVAILABLE, ACTIVITY_DISABLED, ONLINE_STATUS_HIDDEN, PRESENCE_NOT_ENABLED or FORBIDDEN (not a live person) when refused",
2116
+ refetch: "() => Promise<void>",
2117
+ },
2118
+ requiredContextSlice: ["directory.presence"],
2119
+ scopes: ["directory.read:users"],
2120
+ },
2121
+ {
2122
+ name: "useOnlineVisibility",
2123
+ signature: "useOnlineVisibility()",
2124
+ description:
2125
+ "The viewer's own \"Show when I'm online\" switch, on by default. " +
2126
+ "`supported` is false where the workspace shows nobody online: offer " +
2127
+ "the switch only when it is true. `setShowOnline(false)` hides the " +
2128
+ "viewer from everyone, and they then see nobody online either; every " +
2129
+ "useOnlineMembers on the page re-reads. No scope: it is the viewer's " +
2130
+ "own setting.",
2131
+ returnShape: {
2132
+ supported: "boolean",
2133
+ showOnline: "boolean | null // null until known",
2134
+ loading: "boolean",
2135
+ saving: "boolean",
2136
+ error: "DirectoryError | null",
2137
+ setShowOnline: "(showOnline: boolean) => Promise<void> // rejects with DirectoryError",
2138
+ },
2139
+ requiredContextSlice: ["directory.presence"],
2140
+ scopes: null,
2141
+ },
2067
2142
  // REQ-USERMGMT / REQ-ACL-SYS M3 — AppUserGroup administration. Returns
2068
2143
  // `{ groups, loading, error, refetch, create, remove, addMember, removeMember }`.
2069
2144
  // Reads need `groups.read:*`; mutations need `groups.write:*`. Removing a
@@ -2906,6 +2981,13 @@ const PRIMITIVES = [
2906
2981
  rnComponent: null,
2907
2982
  docsUrl: null,
2908
2983
  },
2984
+ {
2985
+ name: "Banner",
2986
+ description:
2987
+ 'Themed inline message. `<Banner tone="error" title="Could not save" message={err.message} action={{ label: "Retry", onPress: save }} onDismiss={() => setErr(null)} />`. THE way to show an error, warning, success or notice that belongs to a place in the widget and stays until it is resolved: a list that failed to load, a form the user cannot submit yet, a "read-only" or "offline" notice. Render it where the problem is — above the list or form it concerns. Use `useToast()` instead for a brief confirmation of something the user just did ("Saved", "Deleted") that needs no decision and may disappear on its own; never both for one event. Its fill, text colour, border and corner radius come from the app\'s theme per tone (Design > Components > Alerts), so never hand-roll a tinted box from `View` + a border + a hex. Props: `tone` ("info" default | "success" | "warning" | "error"), `title` (optional, one short line) and `message` (wraps — never truncate it): text, or an element you built when part of it needs its own styling, `icon` (a lucide name replacing the tone\'s own glyph, or `false` for none), `action` (`{ label, onPress, accessibilityLabel?, testID? }`, ONE action such as Retry), `onDismiss` (pass it to show a close control; you hide the banner in the handler), `dismissAccessibilityLabel` (default "Dismiss" — pass a translated one), `style` (spacing around it), `testID`. An `error` is marked as an alert, and the other tones as a polite status: the web and Android announce them when they appear, while iOS reads the banner in place.',
2988
+ rnComponent: null,
2989
+ docsUrl: null,
2990
+ },
2909
2991
  {
2910
2992
  name: "Accordion",
2911
2993
  description:
@@ -3214,7 +3296,7 @@ const MANIFEST_SCHEMA = {
3214
3296
  type: "object",
3215
3297
  required: false,
3216
3298
  description:
3217
- "Optional. Tables the widget needs, seeded into the workspace at install time. Authors wire them into the widget's `tableRef` properties via the Properties Panel — the SDK does not auto-bind. Limits: 8 tables, 24 columns per table. RELATION columns address siblings by `targetSuffix` (any table in the same array, in any order; tables may relate to each other both ways). Tables persist across uninstalls. A `tableRef` property may also carry `sharedTable: true`, declaring that the table is the APP'S OWN — the author picks an existing table and the widget seeds nothing for it. That is the correct shape for a widget that reads data it does not own (a chart, a metric, a manager view over another widget's table). `sharedTable` exempts the property from needing a seeded table at publish (`manifest.requiredTableRefsHaveTemplate`) WITHOUT making it optional: the author must still bind one, and the host still refuses to place the widget unbound. Use it instead of dropping `required` — a widget that silently renders an empty tile is the defect it looks like a fix for. sc-7530: a table may also declare `roleGrants` — group-scoped access named SYMBOLICALLY, because a group id belongs to the workspace that installs the widget and could never travel in the manifest. Declare the audiences once at template level as `roles: [{ key, label, description? }]` (key is lowercase kebab, max 8 roles), then per table `roleGrants: [{ role, canRead?, canWrite?, canDelete? }]`. The installing workspace binds each role to one of its own user groups (or has one created) during the install consent step, so a permission model where an admin group does everything and signed-in users only read survives the trip between workspaces. Use `publicGrant` for the two id-less audiences (everyone / any signed-in user) and `roleGrants` for anything that names a group. A role nobody binds simply writes no grant — it never fails the install. sc-7557: a column may declare `encrypted: true` — its values are stored AES-256-GCM encrypted at rest under a per-workspace subkey. The widget still reads and writes PLAINTEXT (the platform encrypts on write, decrypts for end users); studio users see `🔒` instead, and the column cannot be searched, filtered or sorted on. Sample `rows` you seed for it are encrypted the same way. Not valid on `RELATION` — its value is a foreign key the backend must resolve — and publishing one is rejected. An `inheritAcl` RELATION column may add `inheritAclReadOnly: true` — rows then inherit READ access only, so members of the parent read every child and may add children, but change or delete only the rows they created (pair with `grantCreatorPermissions`). A column may declare `defaultValue`, written when a create omits it: `@currentUser` on USER, `@now` on DATE / DATETIME, or a literal of the column's own type (none on FILE, RELATION or USER_GROUP — ids belong to the installing workspace). `defaultLocked: true` on an `@currentUser` / `@now` default makes the server always stamp it and ignore any client value on create and update, so an author column cannot be forged. `immutable: true` makes a column write-once: a create sets it as usual and any value sent for it on update is ignored (not valid on a MANY_TO_MANY relation).",
3299
+ "Optional. Tables the widget needs, seeded into the workspace at install time. Authors wire them into the widget's `tableRef` properties via the Properties Panel — the SDK does not auto-bind. Limits: 8 tables, 24 columns per table. RELATION columns address siblings by `targetSuffix` (any table in the same array, in any order; tables may relate to each other both ways). Tables persist across uninstalls. A `tableRef` property may also carry `sharedTable: true`, declaring that the table is the APP'S OWN — the author picks an existing table and the widget seeds nothing for it. That is the correct shape for a widget that reads data it does not own (a chart, a metric, a manager view over another widget's table). `sharedTable` exempts the property from needing a seeded table at publish (`manifest.requiredTableRefsHaveTemplate`) WITHOUT making it optional: the author must still bind one, and the host still refuses to place the widget unbound. Use it instead of dropping `required` — a widget that silently renders an empty tile is the defect it looks like a fix for. sc-7530: a table may also declare `roleGrants` — group-scoped access named SYMBOLICALLY, because a group id belongs to the workspace that installs the widget and could never travel in the manifest. Declare the audiences once at template level as `roles: [{ key, label, description? }]` (key is lowercase kebab, max 8 roles), then per table `roleGrants: [{ role, canRead?, canWrite?, canDelete? }]`. The installing workspace binds each role to one of its own user groups (or has one created) during the install consent step, so a permission model where an admin group does everything and signed-in users only read survives the trip between workspaces. Use `publicGrant` for the two id-less audiences (everyone / any signed-in user) and `roleGrants` for anything that names a group. A role nobody binds simply writes no grant — it never fails the install. sc-7557: a column may declare `encrypted: true` — its values are stored AES-256-GCM encrypted at rest under a per-workspace subkey. The widget still reads and writes PLAINTEXT (the platform encrypts on write, decrypts for end users); studio users see `🔒` instead, and the column cannot be searched, filtered or sorted on. Sample `rows` you seed for it are encrypted the same way. Not valid on `RELATION` — its value is a foreign key the backend must resolve — and publishing one is rejected. An `inheritAcl` RELATION column may add `inheritAclReadOnly: true` — rows then inherit READ access only, so members of the parent read every child and may add children, but change or delete only the rows they created (pair with `grantCreatorPermissions`). A column may declare `defaultValue`, written when a create omits it: `@currentUser` on USER, `@now` on DATE / DATETIME, or a literal of the column's own type (none on FILE, RELATION or USER_GROUP — ids belong to the installing workspace). `defaultLocked: true` on an `@currentUser` / `@now` default makes the server always stamp it and ignore any client value on create and update, so an author column cannot be forged. `immutable: true` makes a column write-once: a create sets it as usual and any value sent for it on update is ignored (not valid on a MANY_TO_MANY relation). A table may declare `presence: true` so the people who share a row see which of each other are online (useOnlineMembers); it takes effect only while the workspace records user activity, and an upgrade that declares it turns it on for the existing table.",
3218
3300
  },
3219
3301
  translations: {
3220
3302
  type: "object",
@@ -3365,10 +3447,11 @@ const WIDGET_CONTEXT_SHAPE = {
3365
3447
  "{ me(), users: { list(query?) -> Promise<{ data, meta }>, get(id), invite(body), deactivate(id), reactivate(id) }, " +
3366
3448
  "groups: { list(query?) -> Promise<{ data, meta }>, create(body), remove(id), addMember(groupId, userId), removeMember(groupId, userId), listMine() }, " +
3367
3449
  "invites: { list(), revoke(id), resend(id) }, " +
3368
- "bankid: { status() -> { linked, available }, startLink() -> { order_ref, qr, ... }, collect(orderRef), cancel(orderRef), unlink() } }. " +
3369
- "users backs useDirectory() + useUsers(); groups backs useGroups(); invites backs useInvites() (list/resend/revoke pending invites, gated by users.write:* + the users.write capability); bankid backs useBankIdLink() (REQ-BANKID-AUTH — self-service account linking, JWT-gated, no widget scope). List methods return the { data, meta } envelope verbatim (hooks unwrap res.data); rows/bodies are snake_case. Reads gated by directory.read:users / users.read:* / groups.read:*; mutations by users.write:* / groups.write:* (destructive user removal by users.delete:*).",
3450
+ "bankid: { status() -> { linked, available }, startLink() -> { order_ref, qr, ... }, collect(orderRef), cancel(orderRef), unlink() }, " +
3451
+ "presence: { online(tableId, recordIds) -> { data: [{ record_id, online_user_ids, online_count }] }, me() -> { show_online }, setShowOnline(bool) -> { show_online } } }. " +
3452
+ "users backs useDirectory() + useUsers(); groups backs useGroups(); invites backs useInvites() (list/resend/revoke pending invites, gated by users.write:* + the users.write capability); bankid backs useBankIdLink() (REQ-BANKID-AUTH — self-service account linking, JWT-gated, no widget scope); presence backs useOnlineMembers() + useOnlineVisibility() (session-gated, no scope header). List methods return the { data, meta } envelope verbatim (hooks unwrap res.data); rows/bodies are snake_case. Reads gated by directory.read:users / users.read:* / groups.read:*; mutations by users.write:* / groups.write:* (destructive user removal by users.delete:*).",
3370
3453
  required: true,
3371
- fields: { users: "object", groups: "object", invites: "object", bankid: "object" },
3454
+ fields: { users: "object", groups: "object", invites: "object", bankid: "object", presence: "object" },
3372
3455
  },
3373
3456
  assets: {
3374
3457
  description:
@@ -5460,7 +5543,14 @@ const CONTRACT = deepFreeze({
5460
5543
  // and `useInactiveUsers` read user activity through the new
5461
5544
  // `ctx.directory.users.activity` / `.inactive` / `.remind`, behind the
5462
5545
  // new `users.activity:*` scope.
5463
- version: "1.164.0",
5546
+ // 1.165.0: additive (sc-11025) — `useOnlineMembers(tableId, recordIds)`
5547
+ // and `useOnlineVisibility()` read who of a record's members is online
5548
+ // and the viewer's own switch, through the new `ctx.directory.presence`.
5549
+ // A `datastoreTemplate` table may declare `presence: true`.
5550
+ // 1.166.0: additive (sc-10927) — the `Banner` primitive (a themed inline
5551
+ // error, warning, success or notice) and the `alert` component scope it
5552
+ // reads.
5553
+ version: "1.166.0",
5464
5554
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
5465
5555
  hooks: HOOKS,
5466
5556
  primitives: PRIMITIVES,