@colixsystems/widget-sdk 0.358.0 → 0.360.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 +29 -1
- package/dist/contract.cjs +70 -5
- package/dist/contract.js +70 -5
- package/dist/hooks.js +207 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +1 -0
- package/dist/index.native.js +1 -0
- package/dist/linter.cjs +10 -0
- package/dist/linter.js +10 -0
- package/dist/property-schema.js +11 -0
- package/package.json +1 -1
- package/src/contract.js +70 -5
package/README.md
CHANGED
|
@@ -60,6 +60,8 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
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`. |
|
|
63
|
+
| **CONNECTORS** | `useConnector(connectorRef)` | `{ available, call, calling, error }` | `ctx.connectors` — `connectors.call:*`. Call one operation the workspace listed on an app-callable REST connector and use the answer. Errors are `ConnectorError` with a stable `code`. |
|
|
64
|
+
| **CONNECTORS** | `useConnectorAccount(connectorRef)` | `{ supported, name, mode, canConnect, unavailableReason, accounts, loading, finishing, pending, error, result, connect, disconnect, refresh }` | `ctx.connectors.accounts` — `connectors.accounts:*`. A signed-in app user connects, lists and disconnects their own accounts at the connector's provider; the host runs the sign-in. Call `connect` from a press only and read its outcome from `result`. Errors are `ConnectorError`. |
|
|
63
65
|
| **DATASTORE** | `useDatastoreMutation(table)` | `{ create, update, delete }` | `records(table).{ create, update (PATCH), delete }` — `datastore.write:*`. A successful write re-reads every query, record, figure and aggregate on that table in every widget on the screen (a run of writes at most once a second, always once more after the last), so never refetch after it, and never write from an effect that re-runs on the data it reads unless a ref or Set marks what it already wrote. **To CLEAR a cell, pass it empty** — `update(id, { when: null })` (also `""` or `[]`) empties that cell and it reads back as `null` (`[]` on an array column). There is no separate clear call, so never write a sentinel such as `0` or a placeholder date to mean "no value". `false` and `0` are values, not clears, and a REQUIRED column cannot be cleared. The result has only create, update and delete; the checker refuses a call to any other key (`datastore-method-unknown`). |
|
|
64
66
|
| **DATASTORE** | `useDatastoreSubscription(table, handlers, options)` (optional: options) | `{ status }` — `"connecting" \| "live" \| "reconnecting" \| "fallback"` | `records(table).subscribe` — `datastore.read:<table>`. To keep a list, record or figure current, pass `live: true` to its read hook instead (*Live lists*); this hook is for acting on each change. Live `onCreated` / `onUpdated` / `onDeleted` off the realtime socket; never throws, resolving to `{ status: "fallback" }` so the widget polls instead. A whole-table subscribe is gated on read-EVERY-row, because one envelope reaches every subscriber of the table — so for a table governed by per-record grants pass `options.scope`: `{ kind: "record", record_id }` for one row, or `{ kind: "parent", relation_column, record_id }` for the rows whose RELATION column points at that parent (the column must carry `inheritAcl`, else the subscribe reports `"fallback"`). For a live list of the signed-in user's own rows pass `{ kind: "granted" }`: every row they read through a grant to them or one of their groups, plus `onAccessGained(record)` / `onAccessLost({ id })` as rows enter and leave that set. Re-subscribes on the scope's VALUES, so a fresh object literal each render is fine. |
|
|
65
67
|
| **DATASTORE** | `useTyping(tableId, recordId)` | `{ typingUserIds, setTyping, status }` — status `"connecting" \| "live" \| "unavailable"` | `records(table).typing` — `datastore.read:<table>`. Who else is typing in one record, over the same socket as `useDatastoreSubscription`. Call `setTyping(true)` on every keystroke (throttled to one signal per 3 s; `false` is sent after 5 s idle) and `setTyping(false)` on send, clear or blur. `typingUserIds` lists the OTHER users' ids; each drops out 6 s after their last signal. Needs a signed-in user who can read the record. Never throws: an anonymous visitor, a refused subscription or a host whose client lacks `typing` reads `{ typingUserIds: [], status: "unavailable" }`. Re-subscribes when either id changes. |
|
|
@@ -91,7 +93,33 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
93
|
|
|
92
94
|
## Status
|
|
93
95
|
|
|
94
|
-
`v0.
|
|
96
|
+
`v0.360.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.360.0 (contract 1.296.0)
|
|
99
|
+
|
|
100
|
+
**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.
|
|
101
|
+
|
|
102
|
+
### What's new in 0.359.0 (contract 1.295.0)
|
|
103
|
+
|
|
104
|
+
**New `useConnectorAccount(connectorRef)` hook: an app user connects their own account at an outside service.** The workspace's REST connector signs in with OAuth and allows app users' accounts; the hook lists them, opens the provider's sign-in through the host and disconnects them. Bind it with a `connectorRef` property carrying `use: "accounts"`, which offers the connectors whose app users may add accounts, and declare `connectors.accounts:*` (the linter refuses the hook without it: `scope-required-for-useConnectorAccount`). The hook never calls the outside API; `useConnector` does.
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
propertySchema: { connectorId: { type: "connectorRef", use: "accounts", label: "Connector" } },
|
|
108
|
+
requestedScopes: ["connectors.accounts:*"],
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
const { name, mode, canConnect, unavailableReason, accounts, loading, pending, error, result, connect, disconnect, refresh } =
|
|
113
|
+
useConnectorAccount(connectorId);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
- `mode` is `"personal"` (one account each, id `"me"`), `"shared"` (members of one group add named accounts with `connect(label)`) or `"off"`.
|
|
117
|
+
- `connect()` opens a sign-in, so call it from a press only. On the web the tab leaves and the promise settles only as `CONNECT_CANCELLED`, when the user goes Back: the page that loads on the way back confirms it (`finishing`) and reports it on `result`. On native it resolves, or rejects `CONNECT_CANCELLED` when dismissed. Read `result` and it works on both.
|
|
118
|
+
- `unavailableReason` is `UNBOUND`, `UNSUPPORTED_HOST`, `SIGN_IN_REQUIRED`, `OFF`, `NOT_IN_GROUP` or `CONNECTOR_NOT_FOUND`, and `null` when connecting works. `error` is a list that could not be read: offer `refresh()`.
|
|
119
|
+
- Each account is `{ id, label, personal, own, canDisconnect, status, connectedAt }`. Offer Disconnect only where `canDisconnect`; `expired` and `error` need a reconnect (`connect` with the same label), `pending` and `awaiting_confirmation` were not finished, `revoked` is not connected.
|
|
120
|
+
- `connect` and `disconnect` reject with a `ConnectorError`. Branch on its `code`: `CONNECT_CANCELLED`, `LABEL_IN_USE`, `TOO_MANY_CONNECTIONS`, `ACCOUNT_IN_USE`, `INVALID_CONNECTION`, `CONNECTION_NOT_FOUND`, `TICKET_USED`, `CONNECTOR_NOT_CONFIGURED`, `NOT_IN_GROUP`, `NOT_AUTHORISED`, `RATE_LIMITED`, `CONNECT_FAILED`, `UNAVAILABLE`.
|
|
121
|
+
|
|
122
|
+
Additive.
|
|
95
123
|
|
|
96
124
|
### What's new in 0.358.0 (contract 1.294.0)
|
|
97
125
|
|
package/dist/contract.cjs
CHANGED
|
@@ -2439,6 +2439,59 @@ const HOOKS = [
|
|
|
2439
2439
|
requiredContextSlice: ["connectors.call"],
|
|
2440
2440
|
scopes: ["connectors.call:*"],
|
|
2441
2441
|
},
|
|
2442
|
+
{
|
|
2443
|
+
name: "useConnectorAccount",
|
|
2444
|
+
signature: "useConnectorAccount(connectorRef)",
|
|
2445
|
+
description:
|
|
2446
|
+
"Let a signed-in app user connect their own account at the provider " +
|
|
2447
|
+
"behind one of the workspace's REST connectors, so the workspace's " +
|
|
2448
|
+
"Actions can use it. It only manages accounts and never calls the " +
|
|
2449
|
+
"outside API (useConnector does, with the workspace's own credential). " +
|
|
2450
|
+
"Bind it with a `connectorRef` property carrying `use: 'accounts'`. " +
|
|
2451
|
+
"`mode` is the maker's choice: 'personal' (each person has one account, " +
|
|
2452
|
+
"id 'me', used by Actions they start) or 'shared' (members of one group " +
|
|
2453
|
+
"add named accounts every Action can use; connect(label) takes the name: " +
|
|
2454
|
+
"lowercase letters, numbers, - and _, never 'me' or 'default'). " +
|
|
2455
|
+
"connect() opens the provider's sign-in, so call it ONLY from a press, " +
|
|
2456
|
+
"never on mount. On the web the tab leaves and connect() settles only as CONNECT_CANCELLED, when the user goes Back: " +
|
|
2457
|
+
"the page that loads on the way back confirms it (`finishing`) and puts " +
|
|
2458
|
+
"the outcome on `result`. On native it resolves once the account is " +
|
|
2459
|
+
"connected, or rejects CONNECT_CANCELLED when dismissed. So read the " +
|
|
2460
|
+
"outcome from `result`, never from the promise. `accounts` " +
|
|
2461
|
+
"holds the caller's own accounts plus, for a group member in shared " +
|
|
2462
|
+
"mode, everyone's shared ones; show a 'revoked' one as not connected, " +
|
|
2463
|
+
"'pending' and 'awaiting_confirmation' as unfinished, 'expired' and " +
|
|
2464
|
+
"'error' as needing a reconnect (connect again, with the same label), and " +
|
|
2465
|
+
"offer Disconnect only where `canDisconnect`. `unavailableReason` says " +
|
|
2466
|
+
"why connecting is off: UNBOUND, UNSUPPORTED_HOST (the app is older than " +
|
|
2467
|
+
"this hook), SIGN_IN_REQUIRED, OFF, NOT_IN_GROUP or CONNECTOR_NOT_FOUND; " +
|
|
2468
|
+
"render a visible state for each, NEVER a blank box, and keep listing the " +
|
|
2469
|
+
"accounts under OFF and NOT_IN_GROUP. `error` is a failed list: offer " +
|
|
2470
|
+
"refresh(). ConnectorError.code of connect/disconnect/result: " +
|
|
2471
|
+
"CONNECT_CANCELLED, LABEL_IN_USE, TOO_MANY_CONNECTIONS, ACCOUNT_IN_USE, " +
|
|
2472
|
+
"INVALID_CONNECTION (the name), CONNECTION_NOT_FOUND and TICKET_USED (the " +
|
|
2473
|
+
"sign-in expired: try again), CONNECTOR_NOT_CONFIGURED (the app's " +
|
|
2474
|
+
"administrator must fix it), NOT_IN_GROUP, NOT_AUTHORISED, RATE_LIMITED, " +
|
|
2475
|
+
"CONNECT_FAILED. NEVER show an app user a raw error. Reads ctx.connectors.",
|
|
2476
|
+
returnShape: {
|
|
2477
|
+
supported: "boolean // false when this host cannot run the sign-in",
|
|
2478
|
+
name: "string // the connector's name; '' until listed",
|
|
2479
|
+
mode: "'personal' | 'shared' | 'off' | null // null until listed",
|
|
2480
|
+
canConnect: "boolean // false until listed and whenever unavailableReason is set",
|
|
2481
|
+
unavailableReason: "null | 'UNBOUND' | 'UNSUPPORTED_HOST' | 'SIGN_IN_REQUIRED' | 'OFF' | 'NOT_IN_GROUP' | 'CONNECTOR_NOT_FOUND'",
|
|
2482
|
+
accounts: "Array<{ id, label, personal, own, canDisconnect, status, connectedAt }> // status: 'pending' | 'awaiting_confirmation' | 'connected' | 'expired' | 'revoked' | 'error'",
|
|
2483
|
+
loading: "boolean // true while the list is read",
|
|
2484
|
+
finishing: "boolean // true while a web sign-in this page came back from is confirmed",
|
|
2485
|
+
pending: "boolean // true while connect, disconnect or finishing runs; disable the buttons",
|
|
2486
|
+
error: "ConnectorError | null // the list could not be read",
|
|
2487
|
+
result: "null | { error: ConnectorError | null } // the last connect, including a web return",
|
|
2488
|
+
connect: "(label?) => Promise<void> // from a press only; on the web only Back settles it; rejects with ConnectorError",
|
|
2489
|
+
disconnect: "(id) => Promise<void> // rejects with ConnectorError",
|
|
2490
|
+
refresh: "() => Promise<void> // never rejects",
|
|
2491
|
+
},
|
|
2492
|
+
requiredContextSlice: ["connectors.accounts"],
|
|
2493
|
+
scopes: ["connectors.accounts:*"],
|
|
2494
|
+
},
|
|
2442
2495
|
{
|
|
2443
2496
|
name: "useDatastoreMutation",
|
|
2444
2497
|
signature: "useDatastoreMutation(tableId)",
|
|
@@ -4391,7 +4444,7 @@ const MANIFEST_SCHEMA = {
|
|
|
4391
4444
|
type: "object",
|
|
4392
4445
|
required: false,
|
|
4393
4446
|
description:
|
|
4394
|
-
"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.",
|
|
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. `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.",
|
|
4395
4448
|
},
|
|
4396
4449
|
translations: {
|
|
4397
4450
|
type: "object",
|
|
@@ -4581,11 +4634,15 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4581
4634
|
"sc-15659 — injected connectors client from @colixsystems/actions-client. " +
|
|
4582
4635
|
"{ call(connectorId, operation, { params, query, body }) -> Promise<{ status, content_type, body }> }. " +
|
|
4583
4636
|
"Backs useConnector(). Calls one operation the workspace listed on an app-callable " +
|
|
4584
|
-
"connector, as the signed-in caller; the credential is added server-side.
|
|
4637
|
+
"connector, as the signed-in caller; the credential is added server-side. " +
|
|
4638
|
+
"accounts(connectorId) -> { list(), disconnect(label) } " +
|
|
4639
|
+
"and, where the host runs the sign-in, connect(label) and resumeConnect() -> Promise<null | { error }>, " +
|
|
4640
|
+
"backs useConnectorAccount(). Errors carry " +
|
|
4585
4641
|
"the server's `code` and `status`. Absent on a host that brokers none, where " +
|
|
4586
|
-
"useConnector() degrades to available: false
|
|
4642
|
+
"useConnector() degrades to available: false and useConnectorAccount() to " +
|
|
4643
|
+
"UNSUPPORTED_HOST rather than throwing.",
|
|
4587
4644
|
required: false,
|
|
4588
|
-
fields: { call: "function" },
|
|
4645
|
+
fields: { call: "function", accounts: "function" },
|
|
4589
4646
|
},
|
|
4590
4647
|
linkPreviews: {
|
|
4591
4648
|
description:
|
|
@@ -5382,6 +5439,7 @@ const FIXED_SCOPES = Object.freeze([
|
|
|
5382
5439
|
"ai.invoke:*",
|
|
5383
5440
|
"actions.run:*",
|
|
5384
5441
|
"connectors.call:*",
|
|
5442
|
+
"connectors.accounts:*",
|
|
5385
5443
|
"users.read:*",
|
|
5386
5444
|
"users.write:*",
|
|
5387
5445
|
"users.delete:*",
|
|
@@ -7211,7 +7269,14 @@ const CONTRACT = deepFreeze({
|
|
|
7211
7269
|
// wire input or the bag.
|
|
7212
7270
|
// 1.294.0 (sc-18646): additive — a `create_record` activity entry may carry
|
|
7213
7271
|
// `count`, how many rows one step added.
|
|
7214
|
-
|
|
7272
|
+
// 1.295.0: additive (sc-15764) — `useConnectorAccount(connectorRef)` + the
|
|
7273
|
+
// `connectors.accounts` host client + the `connectors.accounts:*` scope +
|
|
7274
|
+
// `use: "accounts"` on a `connectorRef` property. An app user connects
|
|
7275
|
+
// their own account at a connector's provider.
|
|
7276
|
+
// 1.296.0: additive (sc-18707) — a template column may declare
|
|
7277
|
+
// `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
|
|
7278
|
+
// server prices a rental by its days or nights.
|
|
7279
|
+
version: "1.296.0",
|
|
7215
7280
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7216
7281
|
hooks: HOOKS,
|
|
7217
7282
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -2434,6 +2434,59 @@ const HOOKS = [
|
|
|
2434
2434
|
requiredContextSlice: ["connectors.call"],
|
|
2435
2435
|
scopes: ["connectors.call:*"],
|
|
2436
2436
|
},
|
|
2437
|
+
{
|
|
2438
|
+
name: "useConnectorAccount",
|
|
2439
|
+
signature: "useConnectorAccount(connectorRef)",
|
|
2440
|
+
description:
|
|
2441
|
+
"Let a signed-in app user connect their own account at the provider " +
|
|
2442
|
+
"behind one of the workspace's REST connectors, so the workspace's " +
|
|
2443
|
+
"Actions can use it. It only manages accounts and never calls the " +
|
|
2444
|
+
"outside API (useConnector does, with the workspace's own credential). " +
|
|
2445
|
+
"Bind it with a `connectorRef` property carrying `use: 'accounts'`. " +
|
|
2446
|
+
"`mode` is the maker's choice: 'personal' (each person has one account, " +
|
|
2447
|
+
"id 'me', used by Actions they start) or 'shared' (members of one group " +
|
|
2448
|
+
"add named accounts every Action can use; connect(label) takes the name: " +
|
|
2449
|
+
"lowercase letters, numbers, - and _, never 'me' or 'default'). " +
|
|
2450
|
+
"connect() opens the provider's sign-in, so call it ONLY from a press, " +
|
|
2451
|
+
"never on mount. On the web the tab leaves and connect() settles only as CONNECT_CANCELLED, when the user goes Back: " +
|
|
2452
|
+
"the page that loads on the way back confirms it (`finishing`) and puts " +
|
|
2453
|
+
"the outcome on `result`. On native it resolves once the account is " +
|
|
2454
|
+
"connected, or rejects CONNECT_CANCELLED when dismissed. So read the " +
|
|
2455
|
+
"outcome from `result`, never from the promise. `accounts` " +
|
|
2456
|
+
"holds the caller's own accounts plus, for a group member in shared " +
|
|
2457
|
+
"mode, everyone's shared ones; show a 'revoked' one as not connected, " +
|
|
2458
|
+
"'pending' and 'awaiting_confirmation' as unfinished, 'expired' and " +
|
|
2459
|
+
"'error' as needing a reconnect (connect again, with the same label), and " +
|
|
2460
|
+
"offer Disconnect only where `canDisconnect`. `unavailableReason` says " +
|
|
2461
|
+
"why connecting is off: UNBOUND, UNSUPPORTED_HOST (the app is older than " +
|
|
2462
|
+
"this hook), SIGN_IN_REQUIRED, OFF, NOT_IN_GROUP or CONNECTOR_NOT_FOUND; " +
|
|
2463
|
+
"render a visible state for each, NEVER a blank box, and keep listing the " +
|
|
2464
|
+
"accounts under OFF and NOT_IN_GROUP. `error` is a failed list: offer " +
|
|
2465
|
+
"refresh(). ConnectorError.code of connect/disconnect/result: " +
|
|
2466
|
+
"CONNECT_CANCELLED, LABEL_IN_USE, TOO_MANY_CONNECTIONS, ACCOUNT_IN_USE, " +
|
|
2467
|
+
"INVALID_CONNECTION (the name), CONNECTION_NOT_FOUND and TICKET_USED (the " +
|
|
2468
|
+
"sign-in expired: try again), CONNECTOR_NOT_CONFIGURED (the app's " +
|
|
2469
|
+
"administrator must fix it), NOT_IN_GROUP, NOT_AUTHORISED, RATE_LIMITED, " +
|
|
2470
|
+
"CONNECT_FAILED. NEVER show an app user a raw error. Reads ctx.connectors.",
|
|
2471
|
+
returnShape: {
|
|
2472
|
+
supported: "boolean // false when this host cannot run the sign-in",
|
|
2473
|
+
name: "string // the connector's name; '' until listed",
|
|
2474
|
+
mode: "'personal' | 'shared' | 'off' | null // null until listed",
|
|
2475
|
+
canConnect: "boolean // false until listed and whenever unavailableReason is set",
|
|
2476
|
+
unavailableReason: "null | 'UNBOUND' | 'UNSUPPORTED_HOST' | 'SIGN_IN_REQUIRED' | 'OFF' | 'NOT_IN_GROUP' | 'CONNECTOR_NOT_FOUND'",
|
|
2477
|
+
accounts: "Array<{ id, label, personal, own, canDisconnect, status, connectedAt }> // status: 'pending' | 'awaiting_confirmation' | 'connected' | 'expired' | 'revoked' | 'error'",
|
|
2478
|
+
loading: "boolean // true while the list is read",
|
|
2479
|
+
finishing: "boolean // true while a web sign-in this page came back from is confirmed",
|
|
2480
|
+
pending: "boolean // true while connect, disconnect or finishing runs; disable the buttons",
|
|
2481
|
+
error: "ConnectorError | null // the list could not be read",
|
|
2482
|
+
result: "null | { error: ConnectorError | null } // the last connect, including a web return",
|
|
2483
|
+
connect: "(label?) => Promise<void> // from a press only; on the web only Back settles it; rejects with ConnectorError",
|
|
2484
|
+
disconnect: "(id) => Promise<void> // rejects with ConnectorError",
|
|
2485
|
+
refresh: "() => Promise<void> // never rejects",
|
|
2486
|
+
},
|
|
2487
|
+
requiredContextSlice: ["connectors.accounts"],
|
|
2488
|
+
scopes: ["connectors.accounts:*"],
|
|
2489
|
+
},
|
|
2437
2490
|
{
|
|
2438
2491
|
name: "useDatastoreMutation",
|
|
2439
2492
|
signature: "useDatastoreMutation(tableId)",
|
|
@@ -4386,7 +4439,7 @@ const MANIFEST_SCHEMA = {
|
|
|
4386
4439
|
type: "object",
|
|
4387
4440
|
required: false,
|
|
4388
4441
|
description:
|
|
4389
|
-
"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.",
|
|
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. `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.",
|
|
4390
4443
|
},
|
|
4391
4444
|
translations: {
|
|
4392
4445
|
type: "object",
|
|
@@ -4576,11 +4629,15 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4576
4629
|
"sc-15659 — injected connectors client from @colixsystems/actions-client. " +
|
|
4577
4630
|
"{ call(connectorId, operation, { params, query, body }) -> Promise<{ status, content_type, body }> }. " +
|
|
4578
4631
|
"Backs useConnector(). Calls one operation the workspace listed on an app-callable " +
|
|
4579
|
-
"connector, as the signed-in caller; the credential is added server-side.
|
|
4632
|
+
"connector, as the signed-in caller; the credential is added server-side. " +
|
|
4633
|
+
"accounts(connectorId) -> { list(), disconnect(label) } " +
|
|
4634
|
+
"and, where the host runs the sign-in, connect(label) and resumeConnect() -> Promise<null | { error }>, " +
|
|
4635
|
+
"backs useConnectorAccount(). Errors carry " +
|
|
4580
4636
|
"the server's `code` and `status`. Absent on a host that brokers none, where " +
|
|
4581
|
-
"useConnector() degrades to available: false
|
|
4637
|
+
"useConnector() degrades to available: false and useConnectorAccount() to " +
|
|
4638
|
+
"UNSUPPORTED_HOST rather than throwing.",
|
|
4582
4639
|
required: false,
|
|
4583
|
-
fields: { call: "function" },
|
|
4640
|
+
fields: { call: "function", accounts: "function" },
|
|
4584
4641
|
},
|
|
4585
4642
|
linkPreviews: {
|
|
4586
4643
|
description:
|
|
@@ -5377,6 +5434,7 @@ const FIXED_SCOPES = Object.freeze([
|
|
|
5377
5434
|
"ai.invoke:*",
|
|
5378
5435
|
"actions.run:*",
|
|
5379
5436
|
"connectors.call:*",
|
|
5437
|
+
"connectors.accounts:*",
|
|
5380
5438
|
"users.read:*",
|
|
5381
5439
|
"users.write:*",
|
|
5382
5440
|
"users.delete:*",
|
|
@@ -7206,7 +7264,14 @@ const CONTRACT = deepFreeze({
|
|
|
7206
7264
|
// wire input or the bag.
|
|
7207
7265
|
// 1.294.0 (sc-18646): additive — a `create_record` activity entry may carry
|
|
7208
7266
|
// `count`, how many rows one step added.
|
|
7209
|
-
|
|
7267
|
+
// 1.295.0: additive (sc-15764) — `useConnectorAccount(connectorRef)` + the
|
|
7268
|
+
// `connectors.accounts` host client + the `connectors.accounts:*` scope +
|
|
7269
|
+
// `use: "accounts"` on a `connectorRef` property. An app user connects
|
|
7270
|
+
// their own account at a connector's provider.
|
|
7271
|
+
// 1.296.0: additive (sc-18707) — a template column may declare
|
|
7272
|
+
// `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
|
|
7273
|
+
// server prices a rental by its days or nights.
|
|
7274
|
+
version: "1.296.0",
|
|
7210
7275
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7211
7276
|
hooks: HOOKS,
|
|
7212
7277
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -4715,6 +4715,213 @@ export function useConnector(connectorRef) {
|
|
|
4715
4715
|
};
|
|
4716
4716
|
}
|
|
4717
4717
|
|
|
4718
|
+
const CONNECTOR_ACCOUNT_MODES = ["personal", "shared", "off"];
|
|
4719
|
+
const CONNECTOR_ACCOUNT_REASONS = { off: "OFF", not_in_group: "NOT_IN_GROUP" };
|
|
4720
|
+
const NO_CONNECTOR_ACCOUNTS = {
|
|
4721
|
+
key: null,
|
|
4722
|
+
listed: null,
|
|
4723
|
+
refused: null,
|
|
4724
|
+
loading: false,
|
|
4725
|
+
finishing: false,
|
|
4726
|
+
changing: 0,
|
|
4727
|
+
error: null,
|
|
4728
|
+
result: null,
|
|
4729
|
+
};
|
|
4730
|
+
|
|
4731
|
+
function toConnectorAccountError(err) {
|
|
4732
|
+
if (err instanceof ConnectorError) return err;
|
|
4733
|
+
const code = err && typeof err.code === "string" && err.code ? err.code : "CONNECT_FAILED";
|
|
4734
|
+
const message = (err && err.message) || "The account request failed";
|
|
4735
|
+
return new ConnectorError(code, message, { cause: err });
|
|
4736
|
+
}
|
|
4737
|
+
|
|
4738
|
+
// A refusal the widget shows as a state of its own rather than a load error.
|
|
4739
|
+
function connectorAccountsRefusal(err) {
|
|
4740
|
+
if (err.status === 401 || err.code === "APP_USER_SESSION_REQUIRED") return "SIGN_IN_REQUIRED";
|
|
4741
|
+
return err.code === "CONNECTOR_NOT_FOUND" ? "CONNECTOR_NOT_FOUND" : null;
|
|
4742
|
+
}
|
|
4743
|
+
|
|
4744
|
+
function connectorAccountFromRow(row) {
|
|
4745
|
+
return {
|
|
4746
|
+
id: row.label,
|
|
4747
|
+
label: row.label,
|
|
4748
|
+
personal: row.personal === true,
|
|
4749
|
+
own: row.own === true,
|
|
4750
|
+
canDisconnect: row.can_disconnect === true,
|
|
4751
|
+
status: row.status,
|
|
4752
|
+
connectedAt: row.connected_at || null,
|
|
4753
|
+
};
|
|
4754
|
+
}
|
|
4755
|
+
|
|
4756
|
+
/**
|
|
4757
|
+
* sc-15764 — the accounts an app user connects at a REST connector's provider.
|
|
4758
|
+
* In "personal" mode each person has one account of their own (id "me"); in
|
|
4759
|
+
* "shared" mode members of one group add named accounts everyone uses.
|
|
4760
|
+
*
|
|
4761
|
+
* connect(label?) → Promise; opens the provider's sign-in through the host.
|
|
4762
|
+
* On web the tab leaves and only Back settles it: the page
|
|
4763
|
+
* loaded on the way back reports it in `result`.
|
|
4764
|
+
* disconnect(id) → Promise; removes one account
|
|
4765
|
+
* refresh() → Promise; reads the list again, never rejects
|
|
4766
|
+
*
|
|
4767
|
+
* `error` is a failed list; `result` is the last connect's outcome, null before
|
|
4768
|
+
* one and `{ error: null }` after a success. Never throws at render.
|
|
4769
|
+
* ConnectorError.code here is one of: UNAVAILABLE, AUTH_REQUIRED,
|
|
4770
|
+
* APP_USER_SESSION_REQUIRED, CONNECTOR_NOT_FOUND, CONNECTOR_NOT_CONFIGURED,
|
|
4771
|
+
* NOT_IN_GROUP, NOT_AUTHORISED, INVALID_CONNECTION, LABEL_IN_USE,
|
|
4772
|
+
* ACCOUNT_IN_USE, TOO_MANY_CONNECTIONS, INVALID_RETURN_URL,
|
|
4773
|
+
* CONNECTION_NOT_FOUND, TICKET_USED, CONNECT_CANCELLED, CONNECT_FAILED,
|
|
4774
|
+
* RATE_LIMITED; any other server code passes through.
|
|
4775
|
+
*
|
|
4776
|
+
* Routes through `ctx.connectors.accounts`, where the host runs the sign-in
|
|
4777
|
+
* round trip, so the Player and the Expo export behave identically.
|
|
4778
|
+
*/
|
|
4779
|
+
export function useConnectorAccount(connectorRef) {
|
|
4780
|
+
const ctx = useWidgetContextOrThrow("useConnectorAccount");
|
|
4781
|
+
const bound = typeof connectorRef === "string" && connectorRef.trim() !== "";
|
|
4782
|
+
const brokered = Boolean(ctx.connectors) && typeof ctx.connectors.accounts === "function";
|
|
4783
|
+
// An older baked host lists accounts but cannot run the sign-in.
|
|
4784
|
+
let supported = brokered;
|
|
4785
|
+
if (bound && brokered) {
|
|
4786
|
+
try {
|
|
4787
|
+
supported = typeof ctx.connectors.accounts(connectorRef).connect === "function";
|
|
4788
|
+
} catch {
|
|
4789
|
+
supported = false;
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4792
|
+
const usable = bound && supported;
|
|
4793
|
+
// A sign-in or a late session restore asks again.
|
|
4794
|
+
const key = usable ? `${connectorRef}|${(ctx.user && ctx.user.id) || ""}` : null;
|
|
4795
|
+
|
|
4796
|
+
const clientRef = useRef(null);
|
|
4797
|
+
clientRef.current = usable ? ctx.connectors : null;
|
|
4798
|
+
// One object per binding, so an A→B→A rebind never takes A's late answer.
|
|
4799
|
+
const bindingRef = useRef(null);
|
|
4800
|
+
const [state, setState] = useState(NO_CONNECTOR_ACCOUNTS);
|
|
4801
|
+
|
|
4802
|
+
const patch = useCallback((binding, change) => {
|
|
4803
|
+
if (bindingRef.current !== binding) return;
|
|
4804
|
+
setState((prior) => ({ ...prior, ...change(prior) }));
|
|
4805
|
+
}, []);
|
|
4806
|
+
|
|
4807
|
+
const load = useCallback(
|
|
4808
|
+
async (binding) => {
|
|
4809
|
+
const turn = ++binding.turn;
|
|
4810
|
+
const latest = () => binding.turn === turn;
|
|
4811
|
+
patch(binding, () => ({ loading: true, error: null }));
|
|
4812
|
+
// A sign-in this page came back from is finished before the list, so
|
|
4813
|
+
// the list already shows it; the host answers it once per page load.
|
|
4814
|
+
if (!binding.resume) {
|
|
4815
|
+
binding.resume = (async () => {
|
|
4816
|
+
let landed = null;
|
|
4817
|
+
try {
|
|
4818
|
+
const api = clientRef.current.accounts(binding.connectorId);
|
|
4819
|
+
if (typeof api.resumeConnect !== "function") return;
|
|
4820
|
+
patch(binding, () => ({ finishing: true }));
|
|
4821
|
+
landed = await api.resumeConnect();
|
|
4822
|
+
} catch (error) {
|
|
4823
|
+
landed = { error };
|
|
4824
|
+
}
|
|
4825
|
+
patch(binding, (prior) => ({
|
|
4826
|
+
finishing: false,
|
|
4827
|
+
result: landed ? { error: landed.error ? toConnectorAccountError(landed.error) : null } : prior.result,
|
|
4828
|
+
}));
|
|
4829
|
+
})();
|
|
4830
|
+
}
|
|
4831
|
+
await binding.resume;
|
|
4832
|
+
if (bindingRef.current !== binding || !latest()) return;
|
|
4833
|
+
try {
|
|
4834
|
+
const listed = await clientRef.current.accounts(binding.connectorId).list();
|
|
4835
|
+
if (latest()) patch(binding, () => ({ listed: listed || {}, refused: null, loading: false }));
|
|
4836
|
+
} catch (err) {
|
|
4837
|
+
if (!latest()) return;
|
|
4838
|
+
const refused = connectorAccountsRefusal(err || {});
|
|
4839
|
+
// A blip keeps what was already shown.
|
|
4840
|
+
patch(binding, (prior) => ({
|
|
4841
|
+
listed: refused ? null : prior.listed,
|
|
4842
|
+
refused: refused || prior.refused,
|
|
4843
|
+
loading: false,
|
|
4844
|
+
error: refused ? null : toConnectorAccountError(err),
|
|
4845
|
+
}));
|
|
4846
|
+
}
|
|
4847
|
+
},
|
|
4848
|
+
[patch],
|
|
4849
|
+
);
|
|
4850
|
+
|
|
4851
|
+
useEffect(() => {
|
|
4852
|
+
if (!key) return undefined;
|
|
4853
|
+
const binding = { connectorId: connectorRef, turn: 0, resume: null };
|
|
4854
|
+
bindingRef.current = binding;
|
|
4855
|
+
setState({ ...NO_CONNECTOR_ACCOUNTS, key, loading: true });
|
|
4856
|
+
load(binding);
|
|
4857
|
+
return () => {
|
|
4858
|
+
bindingRef.current = null;
|
|
4859
|
+
};
|
|
4860
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4861
|
+
}, [key, load]);
|
|
4862
|
+
|
|
4863
|
+
const refresh = useCallback(async () => {
|
|
4864
|
+
const binding = bindingRef.current;
|
|
4865
|
+
if (binding) await load(binding);
|
|
4866
|
+
}, [load]);
|
|
4867
|
+
|
|
4868
|
+
const change = useCallback(
|
|
4869
|
+
async (run, { reports }) => {
|
|
4870
|
+
const binding = bindingRef.current;
|
|
4871
|
+
const client = clientRef.current;
|
|
4872
|
+
if (!binding || !client) {
|
|
4873
|
+
throw new ConnectorError("UNAVAILABLE", "Connecting accounts is not available here");
|
|
4874
|
+
}
|
|
4875
|
+
patch(binding, (prior) => ({
|
|
4876
|
+
changing: prior.changing + 1,
|
|
4877
|
+
result: reports ? null : prior.result,
|
|
4878
|
+
}));
|
|
4879
|
+
let failure = null;
|
|
4880
|
+
try {
|
|
4881
|
+
await run(client.accounts(binding.connectorId));
|
|
4882
|
+
} catch (err) {
|
|
4883
|
+
failure = toConnectorAccountError(err);
|
|
4884
|
+
}
|
|
4885
|
+
if (reports) patch(binding, () => ({ result: { error: failure } }));
|
|
4886
|
+
const listing = bindingRef.current === binding ? load(binding) : null;
|
|
4887
|
+
// A success resolves once the list shows it.
|
|
4888
|
+
if (!failure) await listing;
|
|
4889
|
+
patch(binding, (prior) => ({ changing: prior.changing - 1 }));
|
|
4890
|
+
if (failure) throw failure;
|
|
4891
|
+
},
|
|
4892
|
+
[load, patch],
|
|
4893
|
+
);
|
|
4894
|
+
|
|
4895
|
+
const connect = useCallback((label) => change((api) => api.connect(label), { reports: true }), [change]);
|
|
4896
|
+
const disconnect = useCallback((id) => change((api) => api.disconnect(id), { reports: false }), [change]);
|
|
4897
|
+
|
|
4898
|
+
// The first render after a rebind precedes its effect.
|
|
4899
|
+
const current = key && state.key === key ? state : { ...NO_CONNECTOR_ACCOUNTS, loading: usable };
|
|
4900
|
+
const { listed } = current;
|
|
4901
|
+
let unavailableReason = current.refused;
|
|
4902
|
+
if (!bound) unavailableReason = "UNBOUND";
|
|
4903
|
+
else if (!supported) unavailableReason = "UNSUPPORTED_HOST";
|
|
4904
|
+
else if (listed && listed.can_connect !== true) {
|
|
4905
|
+
unavailableReason = CONNECTOR_ACCOUNT_REASONS[listed.unavailable_reason] || "OFF";
|
|
4906
|
+
}
|
|
4907
|
+
return {
|
|
4908
|
+
supported,
|
|
4909
|
+
name: (listed && listed.name) || "",
|
|
4910
|
+
mode: listed && CONNECTOR_ACCOUNT_MODES.includes(listed.app_user_accounts) ? listed.app_user_accounts : null,
|
|
4911
|
+
canConnect: Boolean(listed) && unavailableReason === null,
|
|
4912
|
+
unavailableReason,
|
|
4913
|
+
accounts: listed && Array.isArray(listed.connections) ? listed.connections.map(connectorAccountFromRow) : [],
|
|
4914
|
+
loading: current.loading,
|
|
4915
|
+
finishing: current.finishing,
|
|
4916
|
+
pending: current.finishing || current.changing > 0,
|
|
4917
|
+
error: current.error,
|
|
4918
|
+
result: current.result,
|
|
4919
|
+
connect,
|
|
4920
|
+
disconnect,
|
|
4921
|
+
refresh,
|
|
4922
|
+
};
|
|
4923
|
+
}
|
|
4924
|
+
|
|
4718
4925
|
/**
|
|
4719
4926
|
* Datastore mutation hook. Returns { create, update, delete }, each method
|
|
4720
4927
|
* returning a Promise. Routes through the injected
|
package/dist/index.d.ts
CHANGED
|
@@ -126,6 +126,12 @@ export interface WidgetPropertyDef {
|
|
|
126
126
|
* Placing the widget binds the property to the connector its install created.
|
|
127
127
|
*/
|
|
128
128
|
template?: string;
|
|
129
|
+
/**
|
|
130
|
+
* `connectorRef` only: what the widget does with the connector. "call" (the
|
|
131
|
+
* default) lists those callable from the app, for useConnector(); "accounts"
|
|
132
|
+
* those whose app users add their own accounts, for useConnectorAccount().
|
|
133
|
+
*/
|
|
134
|
+
use?: "call" | "accounts";
|
|
129
135
|
ui?: {
|
|
130
136
|
widget?: "textarea" | "slider" | "code";
|
|
131
137
|
group?: string;
|
|
@@ -318,6 +324,20 @@ export interface WidgetDatastoreTemplateColumn {
|
|
|
318
324
|
* checkouts in progress are already taken off. Read it to show a product as sold out; never write it.
|
|
319
325
|
*/
|
|
320
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;
|
|
321
341
|
/**
|
|
322
342
|
* STRING only, at most one per table, in a table with a `paymentStatus`
|
|
323
343
|
* column, and it must be `immutable: true` (not encrypted, `latestVia` or
|
|
@@ -1019,6 +1039,8 @@ export interface WidgetContext<TProps = unknown> {
|
|
|
1019
1039
|
/** sc-15659 — injected @colixsystems/actions-client backing useConnector(). */
|
|
1020
1040
|
connectors?: {
|
|
1021
1041
|
call(connectorId: string, operation: string, args?: ConnectorCallArgs): Promise<ConnectorCallResult>;
|
|
1042
|
+
/** sc-15764 — backs useConnectorAccount(); optional on older hosts. */
|
|
1043
|
+
accounts?(connectorId: string): unknown;
|
|
1022
1044
|
};
|
|
1023
1045
|
/** Injected @colixsystems/link-preview-client backing useLinkPreview(). */
|
|
1024
1046
|
linkPreviews?: { get(url: string): Promise<LinkPreview> };
|
|
@@ -2433,6 +2455,63 @@ export interface ConnectorApi {
|
|
|
2433
2455
|
*/
|
|
2434
2456
|
export function useConnector(connectorRef: string | null | undefined): ConnectorApi;
|
|
2435
2457
|
|
|
2458
|
+
export interface ConnectorAccount {
|
|
2459
|
+
/** The label; "me" for the caller's personal account. */
|
|
2460
|
+
id: string;
|
|
2461
|
+
label: string;
|
|
2462
|
+
/** Belongs to one app user, rather than shared by everyone. */
|
|
2463
|
+
personal: boolean;
|
|
2464
|
+
/** The caller connected it. */
|
|
2465
|
+
own: boolean;
|
|
2466
|
+
canDisconnect: boolean;
|
|
2467
|
+
status: "pending" | "awaiting_confirmation" | "connected" | "expired" | "revoked" | "error";
|
|
2468
|
+
connectedAt: string | null;
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
export interface ConnectorAccountApi {
|
|
2472
|
+
/** False when this host cannot run the sign-in. */
|
|
2473
|
+
supported: boolean;
|
|
2474
|
+
/** The connector's name; "" until listed. */
|
|
2475
|
+
name: string;
|
|
2476
|
+
/** The maker's choice; null until listed. */
|
|
2477
|
+
mode: "personal" | "shared" | "off" | null;
|
|
2478
|
+
/** False until listed and whenever `unavailableReason` is set. */
|
|
2479
|
+
canConnect: boolean;
|
|
2480
|
+
unavailableReason:
|
|
2481
|
+
| null
|
|
2482
|
+
| "UNBOUND"
|
|
2483
|
+
| "UNSUPPORTED_HOST"
|
|
2484
|
+
| "SIGN_IN_REQUIRED"
|
|
2485
|
+
| "OFF"
|
|
2486
|
+
| "NOT_IN_GROUP"
|
|
2487
|
+
| "CONNECTOR_NOT_FOUND";
|
|
2488
|
+
accounts: ConnectorAccount[];
|
|
2489
|
+
loading: boolean;
|
|
2490
|
+
/** True while a web sign-in this page came back from is confirmed. */
|
|
2491
|
+
finishing: boolean;
|
|
2492
|
+
/** True while connect, disconnect or finishing runs. */
|
|
2493
|
+
pending: boolean;
|
|
2494
|
+
/** The list could not be read. */
|
|
2495
|
+
error: ConnectorError | null;
|
|
2496
|
+
/** The last connect's outcome, including a web return; null before one. */
|
|
2497
|
+
result: { error: ConnectorError | null } | null;
|
|
2498
|
+
/**
|
|
2499
|
+
* Open the provider's sign-in, from a press only. `label` names a shared
|
|
2500
|
+
* account. On the web the tab leaves and only Back settles this; read `result`.
|
|
2501
|
+
*/
|
|
2502
|
+
connect(label?: string): Promise<void>;
|
|
2503
|
+
disconnect(id: string): Promise<void>;
|
|
2504
|
+
/** Read the list again; never rejects. */
|
|
2505
|
+
refresh(): Promise<void>;
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
/**
|
|
2509
|
+
* sc-15764 — let a signed-in app user connect their own account at the
|
|
2510
|
+
* provider behind a REST connector. The widget needs `connectors.accounts:*`
|
|
2511
|
+
* in `requestedScopes`.
|
|
2512
|
+
*/
|
|
2513
|
+
export function useConnectorAccount(connectorRef: string | null | undefined): ConnectorAccountApi;
|
|
2514
|
+
|
|
2436
2515
|
// REQ-RT-07 realtime subscription transport state.
|
|
2437
2516
|
export type DatastoreSubscriptionStatus =
|
|
2438
2517
|
| "connecting"
|
|
@@ -3855,6 +3934,8 @@ export class AgentError extends Error {
|
|
|
3855
3934
|
* sc-15659 — structured error thrown by `useConnector().call`. Branch on
|
|
3856
3935
|
* `code`: `OPERATION_NOT_ALLOWED`, `CONNECTOR_NOT_FOUND` and
|
|
3857
3936
|
* `CONNECTOR_SETUP_INCOMPLETE` will not clear on a retry, `RATE_LIMITED` will.
|
|
3937
|
+
* sc-15764 — `useConnectorAccount()` rejects and reports with it too, under
|
|
3938
|
+
* the codes from `APP_USER_SESSION_REQUIRED` to `CONNECT_FAILED`.
|
|
3858
3939
|
* Never show an app user the raw message.
|
|
3859
3940
|
*/
|
|
3860
3941
|
export class ConnectorError extends Error {
|
|
@@ -3871,6 +3952,19 @@ export class ConnectorError extends Error {
|
|
|
3871
3952
|
| "UPSTREAM_ERROR"
|
|
3872
3953
|
| "UPSTREAM_TIMEOUT"
|
|
3873
3954
|
| "CONNECTOR_FAILED"
|
|
3955
|
+
| "APP_USER_SESSION_REQUIRED"
|
|
3956
|
+
| "CONNECTOR_NOT_CONFIGURED"
|
|
3957
|
+
| "NOT_IN_GROUP"
|
|
3958
|
+
| "NOT_AUTHORISED"
|
|
3959
|
+
| "INVALID_CONNECTION"
|
|
3960
|
+
| "LABEL_IN_USE"
|
|
3961
|
+
| "ACCOUNT_IN_USE"
|
|
3962
|
+
| "TOO_MANY_CONNECTIONS"
|
|
3963
|
+
| "INVALID_RETURN_URL"
|
|
3964
|
+
| "CONNECTION_NOT_FOUND"
|
|
3965
|
+
| "TICKET_USED"
|
|
3966
|
+
| "CONNECT_CANCELLED"
|
|
3967
|
+
| "CONNECT_FAILED"
|
|
3874
3968
|
| (string & {});
|
|
3875
3969
|
constructor(code: string, message: string, opts?: { cause?: unknown });
|
|
3876
3970
|
}
|
package/dist/index.js
CHANGED
package/dist/index.native.js
CHANGED
package/dist/linter.cjs
CHANGED
|
@@ -873,6 +873,16 @@ function _scopeRules(source, manifest) {
|
|
|
873
873
|
snippet: "",
|
|
874
874
|
});
|
|
875
875
|
}
|
|
876
|
+
// sc-15764 — DISCLOSURE, as above: the server gate is the app-user JWT plus
|
|
877
|
+
// the connector's own app-user accounts mode.
|
|
878
|
+
if (/\buseConnectorAccount\s*\(/.test(source) && !declared.has("connectors.accounts:*")) {
|
|
879
|
+
findings.push({
|
|
880
|
+
rule: "scope-required-for-useConnectorAccount",
|
|
881
|
+
label: "useConnectorAccount() requires `connectors.accounts:*` in manifest.requestedScopes",
|
|
882
|
+
line: 0,
|
|
883
|
+
snippet: "",
|
|
884
|
+
});
|
|
885
|
+
}
|
|
876
886
|
const lines = source.split(/\r?\n/);
|
|
877
887
|
let firedUsersWrite = false;
|
|
878
888
|
let firedUsersDelete = false;
|
package/dist/linter.js
CHANGED
|
@@ -868,6 +868,16 @@ function _scopeRules(source, manifest) {
|
|
|
868
868
|
snippet: "",
|
|
869
869
|
});
|
|
870
870
|
}
|
|
871
|
+
// sc-15764 — DISCLOSURE, as above: the server gate is the app-user JWT plus
|
|
872
|
+
// the connector's own app-user accounts mode.
|
|
873
|
+
if (/\buseConnectorAccount\s*\(/.test(source) && !declared.has("connectors.accounts:*")) {
|
|
874
|
+
findings.push({
|
|
875
|
+
rule: "scope-required-for-useConnectorAccount",
|
|
876
|
+
label: "useConnectorAccount() requires `connectors.accounts:*` in manifest.requestedScopes",
|
|
877
|
+
line: 0,
|
|
878
|
+
snippet: "",
|
|
879
|
+
});
|
|
880
|
+
}
|
|
871
881
|
const lines = source.split(/\r?\n/);
|
|
872
882
|
let firedUsersWrite = false;
|
|
873
883
|
let firedUsersDelete = false;
|
package/dist/property-schema.js
CHANGED
|
@@ -36,6 +36,7 @@ const VALID_TYPES = new Set([
|
|
|
36
36
|
"actionRef",
|
|
37
37
|
// sc-15659: `connectorRef` picks one of the workspace's app-callable REST
|
|
38
38
|
// connectors, a bare id a widget passes to `useConnector`. Remapped likewise.
|
|
39
|
+
// sc-15764: `use: "accounts"` picks one whose app users add accounts instead.
|
|
39
40
|
"connectorRef",
|
|
40
41
|
// REQ-WDG-PAGEREF: `pageRef` is a page picker that emits a bare AppPage
|
|
41
42
|
// UUID into the page JSON. Renders a page `<select>` in the Studio
|
|
@@ -90,6 +91,9 @@ const VALID_TYPES = new Set([
|
|
|
90
91
|
/** The propertySchema field types, for documentation generated from this list. */
|
|
91
92
|
export const PROPERTY_TYPES = Object.freeze([...VALID_TYPES]);
|
|
92
93
|
|
|
94
|
+
/** What a `connectorRef` property picks a connector for; "call" when unset. */
|
|
95
|
+
const CONNECTOR_REF_USES = ["call", "accounts"];
|
|
96
|
+
|
|
93
97
|
function validateDef(def, path, errors) {
|
|
94
98
|
if (!isPlainObject(def)) {
|
|
95
99
|
errors.push(`${path}: must be an object`);
|
|
@@ -104,6 +108,13 @@ function validateDef(def, path, errors) {
|
|
|
104
108
|
if (def.description !== undefined && typeof def.description !== "string") {
|
|
105
109
|
errors.push(`${path}.description: must be a string when present`);
|
|
106
110
|
}
|
|
111
|
+
if (def.use !== undefined) {
|
|
112
|
+
if (def.type !== "connectorRef") {
|
|
113
|
+
errors.push(`${path}.use: only a connectorRef property takes it`);
|
|
114
|
+
} else if (!CONNECTOR_REF_USES.includes(def.use)) {
|
|
115
|
+
errors.push(`${path}.use: must be one of ${CONNECTOR_REF_USES.join(", ")}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
107
118
|
if (def.enum !== undefined) {
|
|
108
119
|
if (!Array.isArray(def.enum)) {
|
|
109
120
|
errors.push(`${path}.enum: must be an array`);
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -2434,6 +2434,59 @@ const HOOKS = [
|
|
|
2434
2434
|
requiredContextSlice: ["connectors.call"],
|
|
2435
2435
|
scopes: ["connectors.call:*"],
|
|
2436
2436
|
},
|
|
2437
|
+
{
|
|
2438
|
+
name: "useConnectorAccount",
|
|
2439
|
+
signature: "useConnectorAccount(connectorRef)",
|
|
2440
|
+
description:
|
|
2441
|
+
"Let a signed-in app user connect their own account at the provider " +
|
|
2442
|
+
"behind one of the workspace's REST connectors, so the workspace's " +
|
|
2443
|
+
"Actions can use it. It only manages accounts and never calls the " +
|
|
2444
|
+
"outside API (useConnector does, with the workspace's own credential). " +
|
|
2445
|
+
"Bind it with a `connectorRef` property carrying `use: 'accounts'`. " +
|
|
2446
|
+
"`mode` is the maker's choice: 'personal' (each person has one account, " +
|
|
2447
|
+
"id 'me', used by Actions they start) or 'shared' (members of one group " +
|
|
2448
|
+
"add named accounts every Action can use; connect(label) takes the name: " +
|
|
2449
|
+
"lowercase letters, numbers, - and _, never 'me' or 'default'). " +
|
|
2450
|
+
"connect() opens the provider's sign-in, so call it ONLY from a press, " +
|
|
2451
|
+
"never on mount. On the web the tab leaves and connect() settles only as CONNECT_CANCELLED, when the user goes Back: " +
|
|
2452
|
+
"the page that loads on the way back confirms it (`finishing`) and puts " +
|
|
2453
|
+
"the outcome on `result`. On native it resolves once the account is " +
|
|
2454
|
+
"connected, or rejects CONNECT_CANCELLED when dismissed. So read the " +
|
|
2455
|
+
"outcome from `result`, never from the promise. `accounts` " +
|
|
2456
|
+
"holds the caller's own accounts plus, for a group member in shared " +
|
|
2457
|
+
"mode, everyone's shared ones; show a 'revoked' one as not connected, " +
|
|
2458
|
+
"'pending' and 'awaiting_confirmation' as unfinished, 'expired' and " +
|
|
2459
|
+
"'error' as needing a reconnect (connect again, with the same label), and " +
|
|
2460
|
+
"offer Disconnect only where `canDisconnect`. `unavailableReason` says " +
|
|
2461
|
+
"why connecting is off: UNBOUND, UNSUPPORTED_HOST (the app is older than " +
|
|
2462
|
+
"this hook), SIGN_IN_REQUIRED, OFF, NOT_IN_GROUP or CONNECTOR_NOT_FOUND; " +
|
|
2463
|
+
"render a visible state for each, NEVER a blank box, and keep listing the " +
|
|
2464
|
+
"accounts under OFF and NOT_IN_GROUP. `error` is a failed list: offer " +
|
|
2465
|
+
"refresh(). ConnectorError.code of connect/disconnect/result: " +
|
|
2466
|
+
"CONNECT_CANCELLED, LABEL_IN_USE, TOO_MANY_CONNECTIONS, ACCOUNT_IN_USE, " +
|
|
2467
|
+
"INVALID_CONNECTION (the name), CONNECTION_NOT_FOUND and TICKET_USED (the " +
|
|
2468
|
+
"sign-in expired: try again), CONNECTOR_NOT_CONFIGURED (the app's " +
|
|
2469
|
+
"administrator must fix it), NOT_IN_GROUP, NOT_AUTHORISED, RATE_LIMITED, " +
|
|
2470
|
+
"CONNECT_FAILED. NEVER show an app user a raw error. Reads ctx.connectors.",
|
|
2471
|
+
returnShape: {
|
|
2472
|
+
supported: "boolean // false when this host cannot run the sign-in",
|
|
2473
|
+
name: "string // the connector's name; '' until listed",
|
|
2474
|
+
mode: "'personal' | 'shared' | 'off' | null // null until listed",
|
|
2475
|
+
canConnect: "boolean // false until listed and whenever unavailableReason is set",
|
|
2476
|
+
unavailableReason: "null | 'UNBOUND' | 'UNSUPPORTED_HOST' | 'SIGN_IN_REQUIRED' | 'OFF' | 'NOT_IN_GROUP' | 'CONNECTOR_NOT_FOUND'",
|
|
2477
|
+
accounts: "Array<{ id, label, personal, own, canDisconnect, status, connectedAt }> // status: 'pending' | 'awaiting_confirmation' | 'connected' | 'expired' | 'revoked' | 'error'",
|
|
2478
|
+
loading: "boolean // true while the list is read",
|
|
2479
|
+
finishing: "boolean // true while a web sign-in this page came back from is confirmed",
|
|
2480
|
+
pending: "boolean // true while connect, disconnect or finishing runs; disable the buttons",
|
|
2481
|
+
error: "ConnectorError | null // the list could not be read",
|
|
2482
|
+
result: "null | { error: ConnectorError | null } // the last connect, including a web return",
|
|
2483
|
+
connect: "(label?) => Promise<void> // from a press only; on the web only Back settles it; rejects with ConnectorError",
|
|
2484
|
+
disconnect: "(id) => Promise<void> // rejects with ConnectorError",
|
|
2485
|
+
refresh: "() => Promise<void> // never rejects",
|
|
2486
|
+
},
|
|
2487
|
+
requiredContextSlice: ["connectors.accounts"],
|
|
2488
|
+
scopes: ["connectors.accounts:*"],
|
|
2489
|
+
},
|
|
2437
2490
|
{
|
|
2438
2491
|
name: "useDatastoreMutation",
|
|
2439
2492
|
signature: "useDatastoreMutation(tableId)",
|
|
@@ -4386,7 +4439,7 @@ const MANIFEST_SCHEMA = {
|
|
|
4386
4439
|
type: "object",
|
|
4387
4440
|
required: false,
|
|
4388
4441
|
description:
|
|
4389
|
-
"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.",
|
|
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. `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.",
|
|
4390
4443
|
},
|
|
4391
4444
|
translations: {
|
|
4392
4445
|
type: "object",
|
|
@@ -4576,11 +4629,15 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4576
4629
|
"sc-15659 — injected connectors client from @colixsystems/actions-client. " +
|
|
4577
4630
|
"{ call(connectorId, operation, { params, query, body }) -> Promise<{ status, content_type, body }> }. " +
|
|
4578
4631
|
"Backs useConnector(). Calls one operation the workspace listed on an app-callable " +
|
|
4579
|
-
"connector, as the signed-in caller; the credential is added server-side.
|
|
4632
|
+
"connector, as the signed-in caller; the credential is added server-side. " +
|
|
4633
|
+
"accounts(connectorId) -> { list(), disconnect(label) } " +
|
|
4634
|
+
"and, where the host runs the sign-in, connect(label) and resumeConnect() -> Promise<null | { error }>, " +
|
|
4635
|
+
"backs useConnectorAccount(). Errors carry " +
|
|
4580
4636
|
"the server's `code` and `status`. Absent on a host that brokers none, where " +
|
|
4581
|
-
"useConnector() degrades to available: false
|
|
4637
|
+
"useConnector() degrades to available: false and useConnectorAccount() to " +
|
|
4638
|
+
"UNSUPPORTED_HOST rather than throwing.",
|
|
4582
4639
|
required: false,
|
|
4583
|
-
fields: { call: "function" },
|
|
4640
|
+
fields: { call: "function", accounts: "function" },
|
|
4584
4641
|
},
|
|
4585
4642
|
linkPreviews: {
|
|
4586
4643
|
description:
|
|
@@ -5377,6 +5434,7 @@ const FIXED_SCOPES = Object.freeze([
|
|
|
5377
5434
|
"ai.invoke:*",
|
|
5378
5435
|
"actions.run:*",
|
|
5379
5436
|
"connectors.call:*",
|
|
5437
|
+
"connectors.accounts:*",
|
|
5380
5438
|
"users.read:*",
|
|
5381
5439
|
"users.write:*",
|
|
5382
5440
|
"users.delete:*",
|
|
@@ -7206,7 +7264,14 @@ const CONTRACT = deepFreeze({
|
|
|
7206
7264
|
// wire input or the bag.
|
|
7207
7265
|
// 1.294.0 (sc-18646): additive — a `create_record` activity entry may carry
|
|
7208
7266
|
// `count`, how many rows one step added.
|
|
7209
|
-
|
|
7267
|
+
// 1.295.0: additive (sc-15764) — `useConnectorAccount(connectorRef)` + the
|
|
7268
|
+
// `connectors.accounts` host client + the `connectors.accounts:*` scope +
|
|
7269
|
+
// `use: "accounts"` on a `connectorRef` property. An app user connects
|
|
7270
|
+
// their own account at a connector's provider.
|
|
7271
|
+
// 1.296.0: additive (sc-18707) — a template column may declare
|
|
7272
|
+
// `rentalStart` / `rentalEnd` (and `rentalByNight` on the end); the
|
|
7273
|
+
// server prices a rental by its days or nights.
|
|
7274
|
+
version: "1.296.0",
|
|
7210
7275
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7211
7276
|
hooks: HOOKS,
|
|
7212
7277
|
primitives: PRIMITIVES,
|