@colixsystems/widget-sdk 0.359.0 → 0.361.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 +10 -2
- package/dist/contract.cjs +12 -5
- package/dist/contract.js +12 -5
- package/dist/hooks.js +11 -31
- package/dist/index.d.ts +19 -5
- package/package.json +1 -1
- package/src/contract.js +12 -5
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
56
56
|
| **DATASTORE** | `useDatastoreFigure(table, { aggregate, column, filter })` (optional: options) | `{ value, text, truncated, loading, fetching, error, refetch }` | `records(table).list` (a count reads the envelope total; a sum or average up to 1000 rows) — `datastore.read:*`. One count / sum / average for a `<Stat>`, computed exactly as the built-in Stat widget does. |
|
|
57
57
|
| **DATASTORE** | `useDatastoreRecord(table, id, options)` (optional: options) | `{ data, loading, fetching, error, refetch }` — a refetch of the same record keeps `data` while `fetching`; `{ includeCapabilities: true }` adds `data._capabilities` | `records(table).get` — `datastore.read:<table>` |
|
|
58
58
|
| **DATASTORE** | `useDatastoreSchema(tableId)` | `{ schema, loading, error, refetch }` | `schema(tableId)` — `datastore.read:<table>` |
|
|
59
|
-
| **DATASTORE** | `useBoundColumns(tableId, shape, props)` | `{ columns, resolved, missing, loading, error }` | `schema(tableId)` (built on `useDatastoreSchema`) — `datastore.read:<table>`. Resolves author-bound column NAMES from `props` by exact name → case-insensitive name
|
|
59
|
+
| **DATASTORE** | `useBoundColumns(tableId, shape, props)` | `{ columns, resolved, missing, loading, error }` | `schema(tableId)` (built on `useDatastoreSchema`) — `datastore.read:<table>`. Resolves author-bound column NAMES from `props` by exact name → case-insensitive name. A `dataType` match alone never binds: a name that matches no column is listed in `missing` instead of showing another column. `columns` holds the resolved NAME (`record[columns.titleField]`); `resolved` holds the full `Column`; `missing` lists non-`optional` keys that never resolved. Falsy `tableId` collapses to `{ columns: {}, resolved: {}, missing: Object.keys(shape), loading: false, error: null }`. |
|
|
60
60
|
| **DATASTORE** | `useInterpretDraft(tableId)` | `{ interpret, interpreting, error, result, available }` | `interpret(tableId, body)` — `datastore.read:<table>`. Turns ONE sentence a user typed ("walk at 11 am tomorrow") into DRAFT column values so a form can prefill itself. IMPERATIVE: call `interpret(text, { fields?, timeZone? })` from an event handler, never on mount. It DRAFTS and writes nothing — show the values for review, then submit through `useDatastoreMutation().create`. Resolves to `{ values, unresolved }`; `values` is keyed by column NAME (the shape `create()` takes) and `unresolved` names the fields the sentence did not state. Only text / number / boolean / date / datetime / array columns are drafted — `FILE`, `RELATION`, `USER` and `USER_GROUP` carry ids and are never guessed. Fails closed to an empty draft. **Every call spends the workspace's AI credits** and is rate-limited per actor, so call it once per user action (never on mount or in a render loop); once the workspace runs out the call is refused with a generic 429 — an app user is deliberately **not** told the workspace's billing state, since they have never heard of an AI credit and cannot buy one. Never surface a raw error to the person filling the form: say drafting is unavailable and keep every field editable by hand. `available` is false where the host brokers no interpreter. |
|
|
61
61
|
| **AGENTS** | `useAgent(agentRef, { files }?)` | `{ send, cancel, reset, messages, sending, resuming, error, available, acceptsFiles, fileLimits }` | `ctx.agents` — `ai.invoke:*`. Hold a conversation with one of the WORKSPACE's own AI agents (an author-written name + system prompt). Sending is IMPERATIVE: call `send(text)` from an event handler, never on mount — the first send opens the conversation, so a widget nobody types into costs nothing. On mount the hook DOES reopen the caller's most recent thread with this agent, so a refresh or a navigation keeps the conversation instead of starting a blank one; that resume only READS and spends no credit. `resuming` is true while it runs — render a loading state, not an empty thread. `messages` is the running transcript, oldest first. You **cannot** set or read the system prompt, replay an edited transcript, or pick a model: the server assembles every turn from the stored prompt plus the stored history, and `content` is the only thing that reaches the wire. `reset()` drops the thread (a "new chat" affordance), and the new thread is the one a later mount resumes. **Every send spends the workspace's AI credits** and is rate-limited per caller AND per workspace. Rejects with `AgentError`; branch on `.code` — `AI_QUOTA_EXCEEDED` (429) is the workspace's credit ceiling and will NOT clear on a retry, unlike `RATE_LIMITED`, so never offer "try again" for it, and `AGENT_DISABLED` (409) means the author turned it off, so hide the affordance. Never surface a raw error or the workspace's billing state to an app user. `available` is false when no agent is bound or the host brokers none — render a visible unbound state, never a blank box. An assistant message that used a tool also carries **`activity`** — what the agent DID with the user's data: the table it read (with the `search` text and `filters` it read with), or the table and columns it CHANGED (never the values, and never a row the permissions refused), with `count` when a create added many rows in one step. **Render a write.** A reply saying "done!" is not evidence a row was written, and if the agent got it wrong the user has no other way to notice. A talk-only turn omits the key entirely. **Files:** with `{ files: true }` the hook asks once (no credit) whether the agent reads files — `acceptsFiles`, `fileLimits` — and `send(text, { files })` sends Filestore images or PDFs with the turn. |
|
|
62
62
|
| **ACTIONS** | `useAction(actionRef)` | `{ available, run, enqueue, running, result, error }` | `ctx.actions` — `actions.run:*`. Run one of the workspace's Actions from an event handler (never on mount) and read the value it passed to `respond()`, or `enqueue` it to run later with its normal limits and no answer. The Action needs the app trigger. `available` is false when nothing is bound or the host brokers no client. Errors are `ActionError` with a stable `code`. |
|
|
@@ -93,7 +93,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
93
93
|
|
|
94
94
|
## Status
|
|
95
95
|
|
|
96
|
-
`v0.
|
|
96
|
+
`v0.361.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**.
|
|
97
|
+
|
|
98
|
+
### What's new in 0.361.0 (contract 1.297.0)
|
|
99
|
+
|
|
100
|
+
**`useBoundColumns` no longer guesses a column by type.** A key whose bound name matches no column, exactly or case-insensitively, now reads `undefined` and is listed in `missing` (unless `optional: true`). It used to take the first free column of the key's `dataType`, so a widget could show the wrong column with no warning, while the Studio's Properties panel and the preview showed the prop unbound. Pick the column in the Properties panel, or declare `ui.autoFill: { names, types }` on the `columnRef` so the Studio picks one by type when the table is chosen and stores it. `dataType` stays in the shape as the column type the key expects. Behaviour change; minor bump.
|
|
101
|
+
|
|
102
|
+
### What's new in 0.360.0 (contract 1.296.0)
|
|
103
|
+
|
|
104
|
+
**A rental is priced by the days it covers.** A per-day rental priced by a quantity the buyer wrote let a buyer book five days and pay for one. A table that holds a `pricedItem` (a lines table, or a bookings table that names the rented item itself) may now declare `rentalStart: true` and `rentalEnd: true` on two write-once (`immutable: true`) DATE columns in a `datastoreTemplate`, one of each, declared together, instead of a `lineQuantity`. When `requestPayment({ order })` opens the charge, the server counts that priced item once per inclusive calendar day between the two dates (1–3 Dec is 3, a single day is 1) times its `unitPrice`. A missing date, an end before the start or a rental longer than 999 days is refused with the non-retryable `ORDER_LINES_INVALID`. The rented items' table cannot also declare a `stockQuantity`. For a per-night stay (a room or an apartment) also declare `rentalByNight: true` on the `rentalEnd` column: the end date is then the check-out day, so 1–3 Dec is 2 nights and a same-day stay is refused. Write the dates when creating the row; never compute or send the price from the widget.
|
|
97
105
|
|
|
98
106
|
### What's new in 0.359.0 (contract 1.295.0)
|
|
99
107
|
|
package/dist/contract.cjs
CHANGED
|
@@ -2169,9 +2169,10 @@ const HOOKS = [
|
|
|
2169
2169
|
description:
|
|
2170
2170
|
"sc-5206 — resolve author-bound column NAMES from a widget's own props, built on useDatastoreSchema. shape is " +
|
|
2171
2171
|
"{ [propKey]: { dataType?, optional? } }; props is the widget's own props carrying author-bound column names (e.g. props.titleField === " +
|
|
2172
|
-
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match,
|
|
2173
|
-
"
|
|
2174
|
-
"
|
|
2172
|
+
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, each skipping a column an " +
|
|
2173
|
+
"EARLIER key in this call already claimed, (3) unresolved. A dataType match alone never binds: dataType states the column type the key " +
|
|
2174
|
+
"expects. Unresolved NEVER throws — the key reads undefined and is named in missing, so a stale or unset binding degrades visibly instead " +
|
|
2175
|
+
"of crashing the widget or showing another column. Returns { columns, resolved, " +
|
|
2175
2176
|
"missing, loading, error }: columns holds the resolved column NAME — a drop-in replacement for record[props.titleField] -> " +
|
|
2176
2177
|
"record[columns.titleField]; resolved holds the full Column object (snake_case verbatim, as useDatastoreSchema returns it) so a caller can " +
|
|
2177
2178
|
"inspect resolved.<key>.data_type; missing lists every key whose spec is not optional:true and did not resolve. Falsy tableId collapses to " +
|
|
@@ -4444,7 +4445,7 @@ const MANIFEST_SCHEMA = {
|
|
|
4444
4445
|
type: "object",
|
|
4445
4446
|
required: false,
|
|
4446
4447
|
description:
|
|
4447
|
-
"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: 100 tables, 200 columns per table, 100 sample rows per table and 20000 sample cells across the whole template (each row counts the keys it sets, and at least one, summed over every 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 32 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, `@uuid` on UUID (a new random id per row), 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` / `@uuid` 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). `defaultOnCreate: true` makes every create start the column at its `defaultValue` (or empty without one) whatever the client sends, while an update may change it through the row's normal access, so a creator cannot file a row already approved; it protects only a table whose filers cannot edit their row afterwards, so no `grantCreatorPermissions` there (a required column needs a non-empty default; not on a paymentStatus, latestVia or copyOf column). `paymentStatus: true` makes a STRING or BOOL column the table's payment status (at most one per table; not required, encrypted, immutable or defaulting to paid): the table also needs an `orderTotal` column; a settled `requestPayment({ order: { table_id, record_id } })` for one of its rows writes it (`PAID`, or `true` on a BOOL; `REFUNDED` / `false` after a full refund), and every client value for it is ignored, so a buyer cannot mark their own order paid. `orderTotal: { lines: \"<lines table suffix>\", via: \"<its relation to this table>\" }` makes a NUMBER column the order's total, which a charge for the order bills: integer MINOR units (339 kr is 33900) in the workspace's charge currency, no currency stored. A table with a paymentStatus column REQUIRES exactly one (and it is valid only beside one), and it must be `immutable: true` (not encrypted, latestVia or copyOf). The SERVER prices it when the charge opens and ignores any client value: Σ over the order's lines of `lineQuantity` × the `unitPrice` of the row the line's `pricedItem` names, plus the order table's own `pricedItem` once (a shipping option). `via` is a write-once ONE_TO_MANY relation on the lines table pointing at this table. A bare `orderTotal: true` is accepted only on an orders table that has its own `pricedItem`; publishing any other unpriced order total is refused (an already published template still installs, and its order charges are refused with ORDER_NOT_PAYABLE). `unitPrice: true` makes a NUMBER column a product's price in minor units (one per table). `pricedItem: true` makes a write-once single RELATION (one per table) to a table with a unitPrice column the item a line or an order is priced by. `lineQuantity: true` makes a write-once NUMBER column (one per table) a line's quantity, a whole number from 1 to 999 (empty is 1). `stockQuantity: true` makes a NUMBER column (one per table, in a table with a unitPrice column, not immutable) how many of a product are left, a whole number of 0 or more (empty is not counted): a charge takes its order's quantities when it opens, refusing with OUT_OF_STOCK when one cannot be covered, and gives them back exactly once if it fails, is cancelled or stays unpaid past 15 minutes; a paid order keeps them and a refund does not restock (the seller restocks in the Studio). Read it to show a product sold out at 0; a widget never writes it. A payer who may edit or create rows in a priced table is refused, and once an order holds its total no line is added or removed (ORDER_LOCKED). `buyerEmail: true` makes a STRING column the buyer's email address, at most one per table, only in a table with a paymentStatus column, and it must be `immutable: true` (not encrypted, latestVia or copyOf): when a charge marks the order paid the platform emails the buyer an order confirmation (a guest at this address, a signed-in buyer at their account's address), and a refund notice after a full refund, so a widget never sends its own. A guest charge (`requestGuestPayment`) for an order whose table has no buyerEmail column, or whose address is empty or invalid, is refused. 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. A table whose rows people join and leave through per-record grants (conversations) may declare `deleteWhenLastMemberLeaves: true`: when a signed-in member giving up their own grant leaves a row with no grant and no table-wide grant lets anyone read it, the row and every row a CASCADE relation ties to it (including rows deleted earlier) are deleted for good. A row that never had a grant (a seeded sample row) is never deleted this way, and a revoke made in the Studio never deletes. An upgrade that declares it turns it on for the existing table. A ONE_TO_ONE / ONE_TO_MANY RELATION may declare `latestVia: \"<relation column on its target that points back>\"` (onDelete left at SET_NULL; that relation must have inheritAcl and be immutable): the server keeps it at the newest row of the target table that points back at this row. A column may declare `copyOf: { via, column }`: the server keeps it equal to `column` on the row the latest-row column `via` points at (same type, or text into text, cut to 140 characters in a STRING column; a copy of an encrypted column must be encrypted, and a copy cannot inheritAcl). Both are written only by the server, in the same write as the related row; a client value is ignored. A table may declare `constraints`, checked on every write for every client and refused as CONSTRAINT_VIOLATION: `unique` ({ columns, partitionColumns?, unlessRelated?: { relation, column } } — waived for rows whose related row has that yes/no column set), `no-overlap` ({ startColumn, endColumn, partitionColumns? }), `related-open` ({ relation, closedColumn } — no row is added, changed or removed while the related row's column is filled) and `related-index` ({ column, relation, listColumn } — the number must be a position in the related row's list). An upgrade adds a declared constraint to an existing table without judging the rows already in it.",
|
|
4448
|
+
"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: 100 tables, 200 columns per table, 100 sample rows per table and 20000 sample cells across the whole template (each row counts the keys it sets, and at least one, summed over every 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 32 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, `@uuid` on UUID (a new random id per row), 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` / `@uuid` 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). `defaultOnCreate: true` makes every create start the column at its `defaultValue` (or empty without one) whatever the client sends, while an update may change it through the row's normal access, so a creator cannot file a row already approved; it protects only a table whose filers cannot edit their row afterwards, so no `grantCreatorPermissions` there (a required column needs a non-empty default; not on a paymentStatus, latestVia or copyOf column). `paymentStatus: true` makes a STRING or BOOL column the table's payment status (at most one per table; not required, encrypted, immutable or defaulting to paid): the table also needs an `orderTotal` column; a settled `requestPayment({ order: { table_id, record_id } })` for one of its rows writes it (`PAID`, or `true` on a BOOL; `REFUNDED` / `false` after a full refund), and every client value for it is ignored, so a buyer cannot mark their own order paid. `orderTotal: { lines: \"<lines table suffix>\", via: \"<its relation to this table>\" }` makes a NUMBER column the order's total, which a charge for the order bills: integer MINOR units (339 kr is 33900) in the workspace's charge currency, no currency stored. A table with a paymentStatus column REQUIRES exactly one (and it is valid only beside one), and it must be `immutable: true` (not encrypted, latestVia or copyOf). The SERVER prices it when the charge opens and ignores any client value: Σ over the order's lines of `lineQuantity` × the `unitPrice` of the row the line's `pricedItem` names, plus the order table's own `pricedItem` once (a shipping option). `via` is a write-once ONE_TO_MANY relation on the lines table pointing at this table. A bare `orderTotal: true` is accepted only on an orders table that has its own `pricedItem`; publishing any other unpriced order total is refused (an already published template still installs, and its order charges are refused with ORDER_NOT_PAYABLE). `unitPrice: true` makes a NUMBER column a product's price in minor units (one per table). `pricedItem: true` makes a write-once single RELATION (one per table) to a table with a unitPrice column the item a line or an order is priced by. `lineQuantity: true` makes a write-once NUMBER column (one per table) a line's quantity, a whole number from 1 to 999 (empty is 1). `stockQuantity: true` makes a NUMBER column (one per table, in a table with a unitPrice column, not immutable) how many of a product are left, a whole number of 0 or more (empty is not counted): a charge takes its order's quantities when it opens, refusing with OUT_OF_STOCK when one cannot be covered, and gives them back exactly once if it fails, is cancelled or stays unpaid past 15 minutes; a paid order keeps them and a refund does not restock (the seller restocks in the Studio). Read it to show a product sold out at 0; a widget never writes it. `rentalStart: true` and `rentalEnd: true` make two write-once DATE columns (one each per table, declared together, in a table with a `pricedItem` and no `lineQuantity`) a rental's first and last day: the server charges that priced item once per inclusive day between them (1–3 Dec is 3) instead of a quantity, refusing with ORDER_LINES_INVALID when a date is missing, the end is before the start or the rental is over 999 days; the rented items' table cannot count stock. For a per-night stay, `rentalByNight: true` beside `rentalEnd: true` makes the end date the check-out day: the server then charges the nights (1–3 Dec is 2) and refuses a same-day stay. Never compute the price in the widget. A payer who may edit or create rows in a priced table is refused, and once an order holds its total no line is added or removed (ORDER_LOCKED). `buyerEmail: true` makes a STRING column the buyer's email address, at most one per table, only in a table with a paymentStatus column, and it must be `immutable: true` (not encrypted, latestVia or copyOf): when a charge marks the order paid the platform emails the buyer an order confirmation (a guest at this address, a signed-in buyer at their account's address), and a refund notice after a full refund, so a widget never sends its own. A guest charge (`requestGuestPayment`) for an order whose table has no buyerEmail column, or whose address is empty or invalid, is refused. 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. A table whose rows people join and leave through per-record grants (conversations) may declare `deleteWhenLastMemberLeaves: true`: when a signed-in member giving up their own grant leaves a row with no grant and no table-wide grant lets anyone read it, the row and every row a CASCADE relation ties to it (including rows deleted earlier) are deleted for good. A row that never had a grant (a seeded sample row) is never deleted this way, and a revoke made in the Studio never deletes. An upgrade that declares it turns it on for the existing table. A ONE_TO_ONE / ONE_TO_MANY RELATION may declare `latestVia: \"<relation column on its target that points back>\"` (onDelete left at SET_NULL; that relation must have inheritAcl and be immutable): the server keeps it at the newest row of the target table that points back at this row. A column may declare `copyOf: { via, column }`: the server keeps it equal to `column` on the row the latest-row column `via` points at (same type, or text into text, cut to 140 characters in a STRING column; a copy of an encrypted column must be encrypted, and a copy cannot inheritAcl). Both are written only by the server, in the same write as the related row; a client value is ignored. A table may declare `constraints`, checked on every write for every client and refused as CONSTRAINT_VIOLATION: `unique` ({ columns, partitionColumns?, unlessRelated?: { relation, column } } — waived for rows whose related row has that yes/no column set), `no-overlap` ({ startColumn, endColumn, partitionColumns? }), `related-open` ({ relation, closedColumn } — no row is added, changed or removed while the related row's column is filled) and `related-index` ({ column, relation, listColumn } — the number must be a position in the related row's list). An upgrade adds a declared constraint to an existing table without judging the rows already in it.",
|
|
4448
4449
|
},
|
|
4449
4450
|
translations: {
|
|
4450
4451
|
type: "object",
|
|
@@ -7273,7 +7274,13 @@ const CONTRACT = deepFreeze({
|
|
|
7273
7274
|
// `connectors.accounts` host client + the `connectors.accounts:*` scope +
|
|
7274
7275
|
// `use: "accounts"` on a `connectorRef` property. An app user connects
|
|
7275
7276
|
// their own account at a connector's provider.
|
|
7276
|
-
|
|
7277
|
+
// 1.296.0: additive (sc-18707) — a template column may declare
|
|
7278
|
+
// `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
|
|
7279
|
+
// server prices a rental by its days or nights.
|
|
7280
|
+
// 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
|
|
7281
|
+
// to the first free column of its `dataType`; a name that matches no
|
|
7282
|
+
// column is `missing`, as the Studio and preview binders already showed.
|
|
7283
|
+
version: "1.297.0",
|
|
7277
7284
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7278
7285
|
hooks: HOOKS,
|
|
7279
7286
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -2164,9 +2164,10 @@ const HOOKS = [
|
|
|
2164
2164
|
description:
|
|
2165
2165
|
"sc-5206 — resolve author-bound column NAMES from a widget's own props, built on useDatastoreSchema. shape is " +
|
|
2166
2166
|
"{ [propKey]: { dataType?, optional? } }; props is the widget's own props carrying author-bound column names (e.g. props.titleField === " +
|
|
2167
|
-
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match,
|
|
2168
|
-
"
|
|
2169
|
-
"
|
|
2167
|
+
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, each skipping a column an " +
|
|
2168
|
+
"EARLIER key in this call already claimed, (3) unresolved. A dataType match alone never binds: dataType states the column type the key " +
|
|
2169
|
+
"expects. Unresolved NEVER throws — the key reads undefined and is named in missing, so a stale or unset binding degrades visibly instead " +
|
|
2170
|
+
"of crashing the widget or showing another column. Returns { columns, resolved, " +
|
|
2170
2171
|
"missing, loading, error }: columns holds the resolved column NAME — a drop-in replacement for record[props.titleField] -> " +
|
|
2171
2172
|
"record[columns.titleField]; resolved holds the full Column object (snake_case verbatim, as useDatastoreSchema returns it) so a caller can " +
|
|
2172
2173
|
"inspect resolved.<key>.data_type; missing lists every key whose spec is not optional:true and did not resolve. Falsy tableId collapses to " +
|
|
@@ -4439,7 +4440,7 @@ const MANIFEST_SCHEMA = {
|
|
|
4439
4440
|
type: "object",
|
|
4440
4441
|
required: false,
|
|
4441
4442
|
description:
|
|
4442
|
-
"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: 100 tables, 200 columns per table, 100 sample rows per table and 20000 sample cells across the whole template (each row counts the keys it sets, and at least one, summed over every 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 32 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, `@uuid` on UUID (a new random id per row), 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` / `@uuid` 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). `defaultOnCreate: true` makes every create start the column at its `defaultValue` (or empty without one) whatever the client sends, while an update may change it through the row's normal access, so a creator cannot file a row already approved; it protects only a table whose filers cannot edit their row afterwards, so no `grantCreatorPermissions` there (a required column needs a non-empty default; not on a paymentStatus, latestVia or copyOf column). `paymentStatus: true` makes a STRING or BOOL column the table's payment status (at most one per table; not required, encrypted, immutable or defaulting to paid): the table also needs an `orderTotal` column; a settled `requestPayment({ order: { table_id, record_id } })` for one of its rows writes it (`PAID`, or `true` on a BOOL; `REFUNDED` / `false` after a full refund), and every client value for it is ignored, so a buyer cannot mark their own order paid. `orderTotal: { lines: \"<lines table suffix>\", via: \"<its relation to this table>\" }` makes a NUMBER column the order's total, which a charge for the order bills: integer MINOR units (339 kr is 33900) in the workspace's charge currency, no currency stored. A table with a paymentStatus column REQUIRES exactly one (and it is valid only beside one), and it must be `immutable: true` (not encrypted, latestVia or copyOf). The SERVER prices it when the charge opens and ignores any client value: Σ over the order's lines of `lineQuantity` × the `unitPrice` of the row the line's `pricedItem` names, plus the order table's own `pricedItem` once (a shipping option). `via` is a write-once ONE_TO_MANY relation on the lines table pointing at this table. A bare `orderTotal: true` is accepted only on an orders table that has its own `pricedItem`; publishing any other unpriced order total is refused (an already published template still installs, and its order charges are refused with ORDER_NOT_PAYABLE). `unitPrice: true` makes a NUMBER column a product's price in minor units (one per table). `pricedItem: true` makes a write-once single RELATION (one per table) to a table with a unitPrice column the item a line or an order is priced by. `lineQuantity: true` makes a write-once NUMBER column (one per table) a line's quantity, a whole number from 1 to 999 (empty is 1). `stockQuantity: true` makes a NUMBER column (one per table, in a table with a unitPrice column, not immutable) how many of a product are left, a whole number of 0 or more (empty is not counted): a charge takes its order's quantities when it opens, refusing with OUT_OF_STOCK when one cannot be covered, and gives them back exactly once if it fails, is cancelled or stays unpaid past 15 minutes; a paid order keeps them and a refund does not restock (the seller restocks in the Studio). Read it to show a product sold out at 0; a widget never writes it. A payer who may edit or create rows in a priced table is refused, and once an order holds its total no line is added or removed (ORDER_LOCKED). `buyerEmail: true` makes a STRING column the buyer's email address, at most one per table, only in a table with a paymentStatus column, and it must be `immutable: true` (not encrypted, latestVia or copyOf): when a charge marks the order paid the platform emails the buyer an order confirmation (a guest at this address, a signed-in buyer at their account's address), and a refund notice after a full refund, so a widget never sends its own. A guest charge (`requestGuestPayment`) for an order whose table has no buyerEmail column, or whose address is empty or invalid, is refused. 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. A table whose rows people join and leave through per-record grants (conversations) may declare `deleteWhenLastMemberLeaves: true`: when a signed-in member giving up their own grant leaves a row with no grant and no table-wide grant lets anyone read it, the row and every row a CASCADE relation ties to it (including rows deleted earlier) are deleted for good. A row that never had a grant (a seeded sample row) is never deleted this way, and a revoke made in the Studio never deletes. An upgrade that declares it turns it on for the existing table. A ONE_TO_ONE / ONE_TO_MANY RELATION may declare `latestVia: \"<relation column on its target that points back>\"` (onDelete left at SET_NULL; that relation must have inheritAcl and be immutable): the server keeps it at the newest row of the target table that points back at this row. A column may declare `copyOf: { via, column }`: the server keeps it equal to `column` on the row the latest-row column `via` points at (same type, or text into text, cut to 140 characters in a STRING column; a copy of an encrypted column must be encrypted, and a copy cannot inheritAcl). Both are written only by the server, in the same write as the related row; a client value is ignored. A table may declare `constraints`, checked on every write for every client and refused as CONSTRAINT_VIOLATION: `unique` ({ columns, partitionColumns?, unlessRelated?: { relation, column } } — waived for rows whose related row has that yes/no column set), `no-overlap` ({ startColumn, endColumn, partitionColumns? }), `related-open` ({ relation, closedColumn } — no row is added, changed or removed while the related row's column is filled) and `related-index` ({ column, relation, listColumn } — the number must be a position in the related row's list). An upgrade adds a declared constraint to an existing table without judging the rows already in it.",
|
|
4443
|
+
"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: 100 tables, 200 columns per table, 100 sample rows per table and 20000 sample cells across the whole template (each row counts the keys it sets, and at least one, summed over every 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 32 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, `@uuid` on UUID (a new random id per row), 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` / `@uuid` 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). `defaultOnCreate: true` makes every create start the column at its `defaultValue` (or empty without one) whatever the client sends, while an update may change it through the row's normal access, so a creator cannot file a row already approved; it protects only a table whose filers cannot edit their row afterwards, so no `grantCreatorPermissions` there (a required column needs a non-empty default; not on a paymentStatus, latestVia or copyOf column). `paymentStatus: true` makes a STRING or BOOL column the table's payment status (at most one per table; not required, encrypted, immutable or defaulting to paid): the table also needs an `orderTotal` column; a settled `requestPayment({ order: { table_id, record_id } })` for one of its rows writes it (`PAID`, or `true` on a BOOL; `REFUNDED` / `false` after a full refund), and every client value for it is ignored, so a buyer cannot mark their own order paid. `orderTotal: { lines: \"<lines table suffix>\", via: \"<its relation to this table>\" }` makes a NUMBER column the order's total, which a charge for the order bills: integer MINOR units (339 kr is 33900) in the workspace's charge currency, no currency stored. A table with a paymentStatus column REQUIRES exactly one (and it is valid only beside one), and it must be `immutable: true` (not encrypted, latestVia or copyOf). The SERVER prices it when the charge opens and ignores any client value: Σ over the order's lines of `lineQuantity` × the `unitPrice` of the row the line's `pricedItem` names, plus the order table's own `pricedItem` once (a shipping option). `via` is a write-once ONE_TO_MANY relation on the lines table pointing at this table. A bare `orderTotal: true` is accepted only on an orders table that has its own `pricedItem`; publishing any other unpriced order total is refused (an already published template still installs, and its order charges are refused with ORDER_NOT_PAYABLE). `unitPrice: true` makes a NUMBER column a product's price in minor units (one per table). `pricedItem: true` makes a write-once single RELATION (one per table) to a table with a unitPrice column the item a line or an order is priced by. `lineQuantity: true` makes a write-once NUMBER column (one per table) a line's quantity, a whole number from 1 to 999 (empty is 1). `stockQuantity: true` makes a NUMBER column (one per table, in a table with a unitPrice column, not immutable) how many of a product are left, a whole number of 0 or more (empty is not counted): a charge takes its order's quantities when it opens, refusing with OUT_OF_STOCK when one cannot be covered, and gives them back exactly once if it fails, is cancelled or stays unpaid past 15 minutes; a paid order keeps them and a refund does not restock (the seller restocks in the Studio). Read it to show a product sold out at 0; a widget never writes it. `rentalStart: true` and `rentalEnd: true` make two write-once DATE columns (one each per table, declared together, in a table with a `pricedItem` and no `lineQuantity`) a rental's first and last day: the server charges that priced item once per inclusive day between them (1–3 Dec is 3) instead of a quantity, refusing with ORDER_LINES_INVALID when a date is missing, the end is before the start or the rental is over 999 days; the rented items' table cannot count stock. For a per-night stay, `rentalByNight: true` beside `rentalEnd: true` makes the end date the check-out day: the server then charges the nights (1–3 Dec is 2) and refuses a same-day stay. Never compute the price in the widget. A payer who may edit or create rows in a priced table is refused, and once an order holds its total no line is added or removed (ORDER_LOCKED). `buyerEmail: true` makes a STRING column the buyer's email address, at most one per table, only in a table with a paymentStatus column, and it must be `immutable: true` (not encrypted, latestVia or copyOf): when a charge marks the order paid the platform emails the buyer an order confirmation (a guest at this address, a signed-in buyer at their account's address), and a refund notice after a full refund, so a widget never sends its own. A guest charge (`requestGuestPayment`) for an order whose table has no buyerEmail column, or whose address is empty or invalid, is refused. 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. A table whose rows people join and leave through per-record grants (conversations) may declare `deleteWhenLastMemberLeaves: true`: when a signed-in member giving up their own grant leaves a row with no grant and no table-wide grant lets anyone read it, the row and every row a CASCADE relation ties to it (including rows deleted earlier) are deleted for good. A row that never had a grant (a seeded sample row) is never deleted this way, and a revoke made in the Studio never deletes. An upgrade that declares it turns it on for the existing table. A ONE_TO_ONE / ONE_TO_MANY RELATION may declare `latestVia: \"<relation column on its target that points back>\"` (onDelete left at SET_NULL; that relation must have inheritAcl and be immutable): the server keeps it at the newest row of the target table that points back at this row. A column may declare `copyOf: { via, column }`: the server keeps it equal to `column` on the row the latest-row column `via` points at (same type, or text into text, cut to 140 characters in a STRING column; a copy of an encrypted column must be encrypted, and a copy cannot inheritAcl). Both are written only by the server, in the same write as the related row; a client value is ignored. A table may declare `constraints`, checked on every write for every client and refused as CONSTRAINT_VIOLATION: `unique` ({ columns, partitionColumns?, unlessRelated?: { relation, column } } — waived for rows whose related row has that yes/no column set), `no-overlap` ({ startColumn, endColumn, partitionColumns? }), `related-open` ({ relation, closedColumn } — no row is added, changed or removed while the related row's column is filled) and `related-index` ({ column, relation, listColumn } — the number must be a position in the related row's list). An upgrade adds a declared constraint to an existing table without judging the rows already in it.",
|
|
4443
4444
|
},
|
|
4444
4445
|
translations: {
|
|
4445
4446
|
type: "object",
|
|
@@ -7268,7 +7269,13 @@ const CONTRACT = deepFreeze({
|
|
|
7268
7269
|
// `connectors.accounts` host client + the `connectors.accounts:*` scope +
|
|
7269
7270
|
// `use: "accounts"` on a `connectorRef` property. An app user connects
|
|
7270
7271
|
// their own account at a connector's provider.
|
|
7271
|
-
|
|
7272
|
+
// 1.296.0: additive (sc-18707) — a template column may declare
|
|
7273
|
+
// `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
|
|
7274
|
+
// server prices a rental by its days or nights.
|
|
7275
|
+
// 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
|
|
7276
|
+
// to the first free column of its `dataType`; a name that matches no
|
|
7277
|
+
// column is `missing`, as the Studio and preview binders already showed.
|
|
7278
|
+
version: "1.297.0",
|
|
7272
7279
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7273
7280
|
hooks: HOOKS,
|
|
7274
7281
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -3393,13 +3393,6 @@ export function useDatastoreSchema(tableId) {
|
|
|
3393
3393
|
return { schema, loading, error, refetch };
|
|
3394
3394
|
}
|
|
3395
3395
|
|
|
3396
|
-
// Columns reach widgets as wire `data_type`; manifest-derived ones carry
|
|
3397
|
-
// `dataType`. The shipped widgets already read both — keep one reading here.
|
|
3398
|
-
function columnType(column) {
|
|
3399
|
-
if (!column) return undefined;
|
|
3400
|
-
return column.data_type ?? column.dataType;
|
|
3401
|
-
}
|
|
3402
|
-
|
|
3403
3396
|
// Identity for the claimed-set. Falls back to the name so an id-less column
|
|
3404
3397
|
// can't claim `undefined` and starve every later key.
|
|
3405
3398
|
function columnKey(column) {
|
|
@@ -3415,12 +3408,14 @@ function columnKey(column) {
|
|
|
3415
3408
|
* (e.g. `props.titleField === "Title"`).
|
|
3416
3409
|
*
|
|
3417
3410
|
* Resolution order per key: (1) an exact `name` match on `props[key]`,
|
|
3418
|
-
* (2) a case-insensitive name match,
|
|
3419
|
-
*
|
|
3420
|
-
*
|
|
3421
|
-
*
|
|
3422
|
-
*
|
|
3423
|
-
*
|
|
3411
|
+
* (2) a case-insensitive name match, each skipping a column an EARLIER key in
|
|
3412
|
+
* this same call already claimed, (3) unresolved. A `dataType` match alone
|
|
3413
|
+
* never binds (sc-16663): it showed the wrong column with no warning, and the
|
|
3414
|
+
* Studio and preview binders never guess without a `ui.autoFill` hint.
|
|
3415
|
+
* `dataType` states the column type the key expects. Unresolved never
|
|
3416
|
+
* throws — the key reads `undefined` and is named in `missing` — so a
|
|
3417
|
+
* column an author renamed after install, or never bound, degrades visibly
|
|
3418
|
+
* instead of crashing.
|
|
3424
3419
|
*
|
|
3425
3420
|
* Returns `{ columns, resolved, missing, loading, error }`. `columns` holds
|
|
3426
3421
|
* the resolved column NAME — a drop-in replacement for
|
|
@@ -3523,24 +3518,9 @@ export function useBoundColumns(tableId, shape, props) {
|
|
|
3523
3518
|
});
|
|
3524
3519
|
|
|
3525
3520
|
for (const key of stillUnresolved) {
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
const types = spec.dataType
|
|
3530
|
-
? Array.isArray(spec.dataType)
|
|
3531
|
-
? spec.dataType
|
|
3532
|
-
: [spec.dataType]
|
|
3533
|
-
: null;
|
|
3534
|
-
const match =
|
|
3535
|
-
types &&
|
|
3536
|
-
schemaColumns.find((c) => free(c) && types.includes(columnType(c)));
|
|
3537
|
-
if (match) {
|
|
3538
|
-
take(key, match);
|
|
3539
|
-
} else {
|
|
3540
|
-
columns[key] = undefined;
|
|
3541
|
-
resolved[key] = undefined;
|
|
3542
|
-
if (spec.optional !== true) missing.push(key);
|
|
3543
|
-
}
|
|
3521
|
+
columns[key] = undefined;
|
|
3522
|
+
resolved[key] = undefined;
|
|
3523
|
+
if ((shape[key] || {}).optional !== true) missing.push(key);
|
|
3544
3524
|
}
|
|
3545
3525
|
return { columns, resolved, missing, loading, error };
|
|
3546
3526
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
package/dist/index.d.ts
CHANGED
|
@@ -324,6 +324,20 @@ export interface WidgetDatastoreTemplateColumn {
|
|
|
324
324
|
* checkouts in progress are already taken off. Read it to show a product as sold out; never write it.
|
|
325
325
|
*/
|
|
326
326
|
stockQuantity?: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* DATE only, `immutable: true`, one per table, declared with `rentalEnd` in
|
|
329
|
+
* a table with a `pricedItem` and no `lineQuantity`: a rental's first day.
|
|
330
|
+
* The server charges that priced item once per inclusive day from
|
|
331
|
+
* `rentalStart` to `rentalEnd` (1–3 Dec is 3), so a widget never computes it.
|
|
332
|
+
*/
|
|
333
|
+
rentalStart?: boolean;
|
|
334
|
+
/** DATE only, `immutable: true`: a rental's last day, under `rentalStart`'s rules. */
|
|
335
|
+
rentalEnd?: boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Only beside `rentalEnd: true`: the end date is the check-out day, so the
|
|
338
|
+
* server charges per night (1–3 Dec is 2) and refuses a same-day stay.
|
|
339
|
+
*/
|
|
340
|
+
rentalByNight?: boolean;
|
|
327
341
|
/**
|
|
328
342
|
* STRING only, at most one per table, in a table with a `paymentStatus`
|
|
329
343
|
* column, and it must be `immutable: true` (not encrypted, `latestVia` or
|
|
@@ -2120,6 +2134,7 @@ export function useDatastoreSchema(
|
|
|
2120
2134
|
|
|
2121
2135
|
/** sc-5206 — one prop key `useBoundColumns` resolves to a schema column. */
|
|
2122
2136
|
export interface BoundColumnSpec {
|
|
2137
|
+
/** The column type the key expects. Never picks a column on its own. */
|
|
2123
2138
|
dataType?: string | string[];
|
|
2124
2139
|
/** When true, an unresolved key is omitted from `missing`. */
|
|
2125
2140
|
optional?: boolean;
|
|
@@ -2140,11 +2155,10 @@ export interface BoundColumnsResult {
|
|
|
2140
2155
|
|
|
2141
2156
|
/**
|
|
2142
2157
|
* sc-5206 — resolve author-bound column NAMES from a widget's own props,
|
|
2143
|
-
* built on `useDatastoreSchema`.
|
|
2144
|
-
*
|
|
2145
|
-
*
|
|
2146
|
-
*
|
|
2147
|
-
* in `missing`. Falsy `tableId` collapses to `{ columns: {}, resolved: {},
|
|
2158
|
+
* built on `useDatastoreSchema`. Matches the bound name exactly, then
|
|
2159
|
+
* case-insensitively; a `dataType` match alone never binds. Never throws for a
|
|
2160
|
+
* missing column — an unresolved key reads `undefined` and, when not
|
|
2161
|
+
* `optional: true`, is named in `missing`. Falsy `tableId` collapses to `{ columns: {}, resolved: {},
|
|
2148
2162
|
* missing: Object.keys(shape), loading: false, error: null }`.
|
|
2149
2163
|
*/
|
|
2150
2164
|
export function useBoundColumns<TProps = Record<string, unknown>>(
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -2164,9 +2164,10 @@ const HOOKS = [
|
|
|
2164
2164
|
description:
|
|
2165
2165
|
"sc-5206 — resolve author-bound column NAMES from a widget's own props, built on useDatastoreSchema. shape is " +
|
|
2166
2166
|
"{ [propKey]: { dataType?, optional? } }; props is the widget's own props carrying author-bound column names (e.g. props.titleField === " +
|
|
2167
|
-
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match,
|
|
2168
|
-
"
|
|
2169
|
-
"
|
|
2167
|
+
"'Title'). Resolution order per key: (1) an exact name match on props[key], (2) a case-insensitive name match, each skipping a column an " +
|
|
2168
|
+
"EARLIER key in this call already claimed, (3) unresolved. A dataType match alone never binds: dataType states the column type the key " +
|
|
2169
|
+
"expects. Unresolved NEVER throws — the key reads undefined and is named in missing, so a stale or unset binding degrades visibly instead " +
|
|
2170
|
+
"of crashing the widget or showing another column. Returns { columns, resolved, " +
|
|
2170
2171
|
"missing, loading, error }: columns holds the resolved column NAME — a drop-in replacement for record[props.titleField] -> " +
|
|
2171
2172
|
"record[columns.titleField]; resolved holds the full Column object (snake_case verbatim, as useDatastoreSchema returns it) so a caller can " +
|
|
2172
2173
|
"inspect resolved.<key>.data_type; missing lists every key whose spec is not optional:true and did not resolve. Falsy tableId collapses to " +
|
|
@@ -4439,7 +4440,7 @@ const MANIFEST_SCHEMA = {
|
|
|
4439
4440
|
type: "object",
|
|
4440
4441
|
required: false,
|
|
4441
4442
|
description:
|
|
4442
|
-
"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: 100 tables, 200 columns per table, 100 sample rows per table and 20000 sample cells across the whole template (each row counts the keys it sets, and at least one, summed over every 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 32 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, `@uuid` on UUID (a new random id per row), 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` / `@uuid` 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). `defaultOnCreate: true` makes every create start the column at its `defaultValue` (or empty without one) whatever the client sends, while an update may change it through the row's normal access, so a creator cannot file a row already approved; it protects only a table whose filers cannot edit their row afterwards, so no `grantCreatorPermissions` there (a required column needs a non-empty default; not on a paymentStatus, latestVia or copyOf column). `paymentStatus: true` makes a STRING or BOOL column the table's payment status (at most one per table; not required, encrypted, immutable or defaulting to paid): the table also needs an `orderTotal` column; a settled `requestPayment({ order: { table_id, record_id } })` for one of its rows writes it (`PAID`, or `true` on a BOOL; `REFUNDED` / `false` after a full refund), and every client value for it is ignored, so a buyer cannot mark their own order paid. `orderTotal: { lines: \"<lines table suffix>\", via: \"<its relation to this table>\" }` makes a NUMBER column the order's total, which a charge for the order bills: integer MINOR units (339 kr is 33900) in the workspace's charge currency, no currency stored. A table with a paymentStatus column REQUIRES exactly one (and it is valid only beside one), and it must be `immutable: true` (not encrypted, latestVia or copyOf). The SERVER prices it when the charge opens and ignores any client value: Σ over the order's lines of `lineQuantity` × the `unitPrice` of the row the line's `pricedItem` names, plus the order table's own `pricedItem` once (a shipping option). `via` is a write-once ONE_TO_MANY relation on the lines table pointing at this table. A bare `orderTotal: true` is accepted only on an orders table that has its own `pricedItem`; publishing any other unpriced order total is refused (an already published template still installs, and its order charges are refused with ORDER_NOT_PAYABLE). `unitPrice: true` makes a NUMBER column a product's price in minor units (one per table). `pricedItem: true` makes a write-once single RELATION (one per table) to a table with a unitPrice column the item a line or an order is priced by. `lineQuantity: true` makes a write-once NUMBER column (one per table) a line's quantity, a whole number from 1 to 999 (empty is 1). `stockQuantity: true` makes a NUMBER column (one per table, in a table with a unitPrice column, not immutable) how many of a product are left, a whole number of 0 or more (empty is not counted): a charge takes its order's quantities when it opens, refusing with OUT_OF_STOCK when one cannot be covered, and gives them back exactly once if it fails, is cancelled or stays unpaid past 15 minutes; a paid order keeps them and a refund does not restock (the seller restocks in the Studio). Read it to show a product sold out at 0; a widget never writes it. A payer who may edit or create rows in a priced table is refused, and once an order holds its total no line is added or removed (ORDER_LOCKED). `buyerEmail: true` makes a STRING column the buyer's email address, at most one per table, only in a table with a paymentStatus column, and it must be `immutable: true` (not encrypted, latestVia or copyOf): when a charge marks the order paid the platform emails the buyer an order confirmation (a guest at this address, a signed-in buyer at their account's address), and a refund notice after a full refund, so a widget never sends its own. A guest charge (`requestGuestPayment`) for an order whose table has no buyerEmail column, or whose address is empty or invalid, is refused. 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. A table whose rows people join and leave through per-record grants (conversations) may declare `deleteWhenLastMemberLeaves: true`: when a signed-in member giving up their own grant leaves a row with no grant and no table-wide grant lets anyone read it, the row and every row a CASCADE relation ties to it (including rows deleted earlier) are deleted for good. A row that never had a grant (a seeded sample row) is never deleted this way, and a revoke made in the Studio never deletes. An upgrade that declares it turns it on for the existing table. A ONE_TO_ONE / ONE_TO_MANY RELATION may declare `latestVia: \"<relation column on its target that points back>\"` (onDelete left at SET_NULL; that relation must have inheritAcl and be immutable): the server keeps it at the newest row of the target table that points back at this row. A column may declare `copyOf: { via, column }`: the server keeps it equal to `column` on the row the latest-row column `via` points at (same type, or text into text, cut to 140 characters in a STRING column; a copy of an encrypted column must be encrypted, and a copy cannot inheritAcl). Both are written only by the server, in the same write as the related row; a client value is ignored. A table may declare `constraints`, checked on every write for every client and refused as CONSTRAINT_VIOLATION: `unique` ({ columns, partitionColumns?, unlessRelated?: { relation, column } } — waived for rows whose related row has that yes/no column set), `no-overlap` ({ startColumn, endColumn, partitionColumns? }), `related-open` ({ relation, closedColumn } — no row is added, changed or removed while the related row's column is filled) and `related-index` ({ column, relation, listColumn } — the number must be a position in the related row's list). An upgrade adds a declared constraint to an existing table without judging the rows already in it.",
|
|
4443
|
+
"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: 100 tables, 200 columns per table, 100 sample rows per table and 20000 sample cells across the whole template (each row counts the keys it sets, and at least one, summed over every 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 32 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, `@uuid` on UUID (a new random id per row), 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` / `@uuid` 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). `defaultOnCreate: true` makes every create start the column at its `defaultValue` (or empty without one) whatever the client sends, while an update may change it through the row's normal access, so a creator cannot file a row already approved; it protects only a table whose filers cannot edit their row afterwards, so no `grantCreatorPermissions` there (a required column needs a non-empty default; not on a paymentStatus, latestVia or copyOf column). `paymentStatus: true` makes a STRING or BOOL column the table's payment status (at most one per table; not required, encrypted, immutable or defaulting to paid): the table also needs an `orderTotal` column; a settled `requestPayment({ order: { table_id, record_id } })` for one of its rows writes it (`PAID`, or `true` on a BOOL; `REFUNDED` / `false` after a full refund), and every client value for it is ignored, so a buyer cannot mark their own order paid. `orderTotal: { lines: \"<lines table suffix>\", via: \"<its relation to this table>\" }` makes a NUMBER column the order's total, which a charge for the order bills: integer MINOR units (339 kr is 33900) in the workspace's charge currency, no currency stored. A table with a paymentStatus column REQUIRES exactly one (and it is valid only beside one), and it must be `immutable: true` (not encrypted, latestVia or copyOf). The SERVER prices it when the charge opens and ignores any client value: Σ over the order's lines of `lineQuantity` × the `unitPrice` of the row the line's `pricedItem` names, plus the order table's own `pricedItem` once (a shipping option). `via` is a write-once ONE_TO_MANY relation on the lines table pointing at this table. A bare `orderTotal: true` is accepted only on an orders table that has its own `pricedItem`; publishing any other unpriced order total is refused (an already published template still installs, and its order charges are refused with ORDER_NOT_PAYABLE). `unitPrice: true` makes a NUMBER column a product's price in minor units (one per table). `pricedItem: true` makes a write-once single RELATION (one per table) to a table with a unitPrice column the item a line or an order is priced by. `lineQuantity: true` makes a write-once NUMBER column (one per table) a line's quantity, a whole number from 1 to 999 (empty is 1). `stockQuantity: true` makes a NUMBER column (one per table, in a table with a unitPrice column, not immutable) how many of a product are left, a whole number of 0 or more (empty is not counted): a charge takes its order's quantities when it opens, refusing with OUT_OF_STOCK when one cannot be covered, and gives them back exactly once if it fails, is cancelled or stays unpaid past 15 minutes; a paid order keeps them and a refund does not restock (the seller restocks in the Studio). Read it to show a product sold out at 0; a widget never writes it. `rentalStart: true` and `rentalEnd: true` make two write-once DATE columns (one each per table, declared together, in a table with a `pricedItem` and no `lineQuantity`) a rental's first and last day: the server charges that priced item once per inclusive day between them (1–3 Dec is 3) instead of a quantity, refusing with ORDER_LINES_INVALID when a date is missing, the end is before the start or the rental is over 999 days; the rented items' table cannot count stock. For a per-night stay, `rentalByNight: true` beside `rentalEnd: true` makes the end date the check-out day: the server then charges the nights (1–3 Dec is 2) and refuses a same-day stay. Never compute the price in the widget. A payer who may edit or create rows in a priced table is refused, and once an order holds its total no line is added or removed (ORDER_LOCKED). `buyerEmail: true` makes a STRING column the buyer's email address, at most one per table, only in a table with a paymentStatus column, and it must be `immutable: true` (not encrypted, latestVia or copyOf): when a charge marks the order paid the platform emails the buyer an order confirmation (a guest at this address, a signed-in buyer at their account's address), and a refund notice after a full refund, so a widget never sends its own. A guest charge (`requestGuestPayment`) for an order whose table has no buyerEmail column, or whose address is empty or invalid, is refused. 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. A table whose rows people join and leave through per-record grants (conversations) may declare `deleteWhenLastMemberLeaves: true`: when a signed-in member giving up their own grant leaves a row with no grant and no table-wide grant lets anyone read it, the row and every row a CASCADE relation ties to it (including rows deleted earlier) are deleted for good. A row that never had a grant (a seeded sample row) is never deleted this way, and a revoke made in the Studio never deletes. An upgrade that declares it turns it on for the existing table. A ONE_TO_ONE / ONE_TO_MANY RELATION may declare `latestVia: \"<relation column on its target that points back>\"` (onDelete left at SET_NULL; that relation must have inheritAcl and be immutable): the server keeps it at the newest row of the target table that points back at this row. A column may declare `copyOf: { via, column }`: the server keeps it equal to `column` on the row the latest-row column `via` points at (same type, or text into text, cut to 140 characters in a STRING column; a copy of an encrypted column must be encrypted, and a copy cannot inheritAcl). Both are written only by the server, in the same write as the related row; a client value is ignored. A table may declare `constraints`, checked on every write for every client and refused as CONSTRAINT_VIOLATION: `unique` ({ columns, partitionColumns?, unlessRelated?: { relation, column } } — waived for rows whose related row has that yes/no column set), `no-overlap` ({ startColumn, endColumn, partitionColumns? }), `related-open` ({ relation, closedColumn } — no row is added, changed or removed while the related row's column is filled) and `related-index` ({ column, relation, listColumn } — the number must be a position in the related row's list). An upgrade adds a declared constraint to an existing table without judging the rows already in it.",
|
|
4443
4444
|
},
|
|
4444
4445
|
translations: {
|
|
4445
4446
|
type: "object",
|
|
@@ -7268,7 +7269,13 @@ const CONTRACT = deepFreeze({
|
|
|
7268
7269
|
// `connectors.accounts` host client + the `connectors.accounts:*` scope +
|
|
7269
7270
|
// `use: "accounts"` on a `connectorRef` property. An app user connects
|
|
7270
7271
|
// their own account at a connector's provider.
|
|
7271
|
-
|
|
7272
|
+
// 1.296.0: additive (sc-18707) — a template column may declare
|
|
7273
|
+
// `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
|
|
7274
|
+
// server prices a rental by its days or nights.
|
|
7275
|
+
// 1.297.0: behaviour (sc-16663) — `useBoundColumns` no longer binds a key
|
|
7276
|
+
// to the first free column of its `dataType`; a name that matches no
|
|
7277
|
+
// column is `missing`, as the Studio and preview binders already showed.
|
|
7278
|
+
version: "1.297.0",
|
|
7272
7279
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7273
7280
|
hooks: HOOKS,
|
|
7274
7281
|
primitives: PRIMITIVES,
|