@colixsystems/widget-sdk 0.346.0 → 0.348.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/dist/contract.cjs +12 -4
- package/dist/contract.js +12 -4
- package/dist/hooks.js +9 -0
- package/dist/index.d.ts +42 -3
- package/dist/linter.cjs +60 -11
- package/dist/linter.js +60 -11
- package/package.json +1 -1
- package/src/contract.js +12 -4
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
77
77
|
| **FILESTORE** (`ctx.filestore`) | `usePdfExport({ spaceType, folderId })` (optional: spaceType, folderId) | `{ openPdf, opening, canOpenPdf, exportToPdf, exporting, error, lastExported }` | `ctx.filestore.files.renderPdf` + `ctx.device.pdfViewer`, `ctx.filestore.files.exportPdf` — `files.write:*`. `openPdf(html, { fileName? })` renders the HTML to a PDF server-side and OPENS it (web: PDF tab; native: print / share sheet) without saving. `exportToPdf(html, { fileName?, folderId? })` renders it and saves it as a file (`application/pdf`). Same server-side renderer on web + native. |
|
|
78
78
|
| **PAYMENTS** (`ctx.payments`) | `useAccessPlans()` | `{ plans, loading, error, purchaseAvailable, purchase, cancel, refresh }` | `ctx.payments.{listAccessPlans,purchaseAccessPlan,cancelAccessPlan}` — `payments.charge:appUser`. Plans selling access to restricted pages; `purchase(planId)` names only the plan, the server sets price and group. A held plan's `member_since` is when the user became a member (first paid charge, else when access was granted). `purchaseAvailable` is `false` in an iOS / Android build (digital goods need store billing): show a visible not-available state. |
|
|
79
79
|
| **PAYMENTS** (`ctx.payments`) | `useAppSubscription()` | `{ subscription, loading, error, cancel, refresh }` | `ctx.payments.{getAppSubscription,cancelAppSubscription}` — `payments.charge:appUser`. The signed-in user's subscription to a paid app (`{ active, renews, access_ends_at, member_since }`); `cancel()` stops it renewing, and access runs to `access_ends_at`. `member_since` is when they became a subscriber. |
|
|
80
|
-
| **PAYMENTS** (`ctx.payments`) | `usePayments()` | `{ requestPayment, getPayment, requestGuestPayment, getGuestPayment }` | `ctx.payments.*` — `payments.charge:appUser`; guest checkout (`requestGuestPayment`, a visitor with no account buying physical goods for an order they created) also `payments.charge:guest`. `requestPayment` requires `kind` (`"physical"` \| `"service"` \| `"digital"`): what is sold. A call without it is a publish-blocking `payment-kind-required` finding. A `"digital"` charge is refused in an iOS or Android build (`DIGITAL_SALE_NEEDS_STORE_BILLING`). Selling an order (goods, a booking, a ticket)? Create
|
|
80
|
+
| **PAYMENTS** (`ctx.payments`) | `usePayments()` | `{ requestPayment, getPayment, requestGuestPayment, getGuestPayment }` | `ctx.payments.*` — `payments.charge:appUser`; guest checkout (`requestGuestPayment`, a visitor with no account buying physical goods for an order they created) also `payments.charge:guest`. `requestPayment` requires `kind` (`"physical"` \| `"service"` \| `"digital"`): what is sold. A call without it is a publish-blocking `payment-kind-required` finding. A `"digital"` charge is refused in an iOS or Android build (`DIGITAL_SALE_NEEDS_STORE_BILLING`). Selling an order (goods, a booking, a ticket)? The orders table needs a payment-status column AND an order-total column (a write-once NUMBER holding the total in minor units). Create the row with its total, then pass `order: { table_id, record_id }` and omit `amount_cents` (or send the same value): the server charges the stored total, and only the payment marks the order paid, so never write a paid status yourself (a `payment-status-written` finding). The server refuses an order it cannot settle with `ORDER_NOT_FOUND`, `ORDER_NOT_PAYABLE` (also: no order-total column), `ORDER_ALREADY_PAID`, `ORDER_TOTAL_INVALID` or `ORDER_AMOUNT_MISMATCH`, none retryable. Give the table a `buyerEmail` column too: the platform emails the buyer's order confirmation and refund notice, and a guest charge needs a valid address there (`BUYER_EMAIL_INVALID`). Rejects with `PaymentError { code, message, retryable }`; when `retryable` is `false` show `message` and drop the retry. Charges are accepted ONLY in the currency the workspace sells in — omit `currency` and the platform applies it (a disagreeing literal is a publish-blocking `payment-currency` finding). |
|
|
81
81
|
| **NOTIFICATIONS** (`ctx.notifications`) | `useSendNotification()` | `{ send, sending, error }` | `ctx.notifications.send` — `notifications.send:appUser`. `send({ recipient_user_id, title, body, link?, payload? })` notifies one app user in the same workspace; call from an event handler (never render); rejects with `NotificationError`. |
|
|
82
82
|
| **NOTIFICATIONS** (`ctx.notifications`) | `useRecordMutes(tableId)` | `{ isMuted, loading, error, refetch }` | `ctx.notifications.mutes` — no scope. Which records of one table the signed-in user has muted, in one request for a whole list; `isMuted(recordId)` turns false when a timed mute lapses, and a `useRecordMute` write shows at once. |
|
|
83
83
|
| **NOTIFICATIONS** (`ctx.notifications`) | `useRecordMute(tableId, recordId)` | `{ muted, mutedUntil, loading, error, mute, unmute, refetch }` | `ctx.notifications.mutes` — no scope. Mutes one record's notifications for the signed-in user, `mute(until)` with an ISO time, a `Date`, or `null` for until unmuted. Needs read access to the record (`RECORD_NOT_FOUND` otherwise). |
|
|
@@ -91,7 +91,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.
|
|
94
|
+
`v0.348.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**.
|
|
95
|
+
|
|
96
|
+
### What's new in 0.348.0 (contract 1.285.0)
|
|
97
|
+
|
|
98
|
+
**The platform emails the buyer's order confirmation.** A guest buyer has no account, so nothing a shop built could reach them after they paid. An orders table with a payment-status column can now have one buyer-email column: a STRING column, write-once (`immutable: true`), declared with `buyerEmail: true` in a `datastoreTemplate`. Write the buyer's address into it when creating the order. When a charge marks the order paid, the platform emails the buyer an order confirmation (the shop and the business behind it, a short order reference, the amount and the date paid) through the workspace's own email provider when one is connected; a full refund sends a refund notice the same way. A guest's mail goes to the buyer-email cell, a signed-in buyer's to their account's address. Each is sent once, however often the payment is reported. `requestGuestPayment` for an order whose table has no buyer-email column answers `ORDER_NOT_PAYABLE`, and one whose address is empty or invalid answers the new non-retryable `BUYER_EMAIL_INVALID`. Do not build a confirmation email of your own.
|
|
99
|
+
|
|
100
|
+
### What's new in 0.347.0 (contract 1.284.0)
|
|
101
|
+
|
|
102
|
+
**A charge for an order bills the order's own total.** A widget sent `amount_cents` beside `order`, so the amount charged was whatever the request said, unrelated to the order. An orders table with a payment-status column now REQUIRES one order-total column: a NUMBER column, write-once (`immutable: true`), holding the total in whole minor units of the workspace's charge currency (339 kr is `33900`; the column stores no currency). Create the order row with its total, then call `requestPayment({ description, kind, order: { table_id, record_id } })` (or `requestGuestPayment`) without `amount_cents`: the server reads the stored total and charges that. `amount_cents` is now optional when `order` is given; if you send it, it must equal the total. The total cannot change once the order is placed, and the order reads paid only when the full total settled. The total is still whatever the order's creator wrote, so compute it from prices the buyer cannot change where you can; server-side pricing is coming. A charge for an order in a table without an order-total column is refused with `ORDER_NOT_PAYABLE`, and a `datastoreTemplate` that declares `paymentStatus: true` without an `orderTotal: true` column (beside `immutable: true`) is refused when the widget is published (a template already published still installs). Two new non-retryable `PaymentError` codes: `ORDER_TOTAL_INVALID` (the order's total is empty, zero, negative or not a whole number) and `ORDER_AMOUNT_MISMATCH` (`amount_cents` differs from the total). An update to the total is ignored, so the new `order-total-updated` lint warning flags a charging widget whose `update` sets a total-looking key (`total`, `orderTotal`, `order_total`, …). A charge without `order` behaves as before.
|
|
95
103
|
|
|
96
104
|
### What's new in 0.346.0 (contract 1.283.0)
|
|
97
105
|
|
package/dist/contract.cjs
CHANGED
|
@@ -2504,11 +2504,11 @@ const HOOKS = [
|
|
|
2504
2504
|
signature: "usePayments()",
|
|
2505
2505
|
returnShape: {
|
|
2506
2506
|
requestPayment:
|
|
2507
|
-
"({ amount_cents
|
|
2507
|
+
"({ amount_cents?, currency?, description, kind, return_path?, order? }) => Promise<{ id, status, order }> // kind is REQUIRED: \"physical\" | \"service\" | \"digital\" — what is sold; a digital charge is refused in an iOS/Android build (DIGITAL_SALE_NEEDS_STORE_BILLING); amount_cents (minor units) is REQUIRED without order; order: { table_id, record_id } — the order row this pays for, in a table with a payment-status column; the SERVER marks it paid when the payment settles, so never write \"paid\" yourself (refused: ORDER_NOT_FOUND, ORDER_NOT_PAYABLE, ORDER_ALREADY_PAID; ORDER_PAYMENT_IN_PROGRESS is retryable while another checkout for the order is open). The orders table also REQUIRES an order-total column (orderTotal; without one: ORDER_NOT_PAYABLE) and the server charges the total stored on the order: create the order with its total, then pass order and omit amount_cents (if sent it must equal the total; refused, not retryable: ORDER_TOTAL_INVALID when the total is empty, zero, negative or not whole, ORDER_AMOUNT_MISMATCH when amount_cents differs). The total is write-once but written by the order's creator, so compute it from prices the buyer cannot change; host opens hosted Checkout; rejects with PaymentError { code, message, retryable } — render the message when retryable is false, never \"try again\"",
|
|
2508
2508
|
getPayment:
|
|
2509
2509
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // order: { table_id, record_id } | null — read it after returning from Checkout",
|
|
2510
2510
|
requestGuestPayment:
|
|
2511
|
-
"({ amount_cents
|
|
2511
|
+
"({ amount_cents?, currency?, description, return_path?, order }) => Promise<{ id, status, order }> // a visitor who is NOT signed in buys physical goods (no kind). The orders table needs a payment-status AND an order-total column, as for requestPayment: create the order with its total and omit amount_cents (if sent it must equal the total). order is REQUIRED: create the order row first with useDatastoreMutation().create (the maker lets everyone add rows to the orders table and nobody read them; collect the shipping address and contact there), then pay for it within 15 minutes — only the visitor who created it can. Needs the payments.charge:guest scope too. The orders table needs a buyerEmail column the order is created with: the platform emails the order confirmation there, and an order without a valid address is refused with BUYER_EMAIL_INVALID (not retryable). The host runs a security check and opens hosted Checkout. Refused: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable), CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), NOT_FOUND where the shop does not offer guest checkout, plus the requestPayment refusals",
|
|
2512
2512
|
getGuestPayment:
|
|
2513
2513
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // a guest's status read; the host holds the guest's one-time credential, so pass only the id",
|
|
2514
2514
|
},
|
|
@@ -4375,7 +4375,7 @@ const MANIFEST_SCHEMA = {
|
|
|
4375
4375
|
type: "object",
|
|
4376
4376
|
required: false,
|
|
4377
4377
|
description:
|
|
4378
|
-
"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): 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. 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.",
|
|
4378
|
+
"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: true` 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 order's creator writes it on create and a later update is ignored; `requestPayment({ order })` then charges that stored total, so omit `amount_cents`. It fixes the total, not the price: compute it from prices the buyer cannot change. `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.",
|
|
4379
4379
|
},
|
|
4380
4380
|
translations: {
|
|
4381
4381
|
type: "object",
|
|
@@ -7159,7 +7159,15 @@ const CONTRACT = deepFreeze({
|
|
|
7159
7159
|
// 1.283.0: additive (sc-17852) — `<Popover onDismiss>` and the children's
|
|
7160
7160
|
// `close(then)` run once the closed popover has left the screen, so a
|
|
7161
7161
|
// dialog it opens presents on iOS.
|
|
7162
|
-
|
|
7162
|
+
// 1.284.0 (sc-15916): a `paymentStatus` table requires an `orderTotal: true`
|
|
7163
|
+
// column (an immutable NUMBER in minor units); a charge with `order` bills
|
|
7164
|
+
// that total, so `amount_cents` is optional with `order`. Breaking for an
|
|
7165
|
+
// order charge on a table without one (ORDER_NOT_PAYABLE). Two new
|
|
7166
|
+
// PaymentError codes and the `order-total-updated` warning.
|
|
7167
|
+
// 1.285.0: additive (sc-18008) — a `datastoreTemplate` column may declare
|
|
7168
|
+
// `buyerEmail: true` (an immutable STRING); the platform emails the order
|
|
7169
|
+
// confirmation there. New PaymentError code BUYER_EMAIL_INVALID.
|
|
7170
|
+
version: "1.285.0",
|
|
7163
7171
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7164
7172
|
hooks: HOOKS,
|
|
7165
7173
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -2499,11 +2499,11 @@ const HOOKS = [
|
|
|
2499
2499
|
signature: "usePayments()",
|
|
2500
2500
|
returnShape: {
|
|
2501
2501
|
requestPayment:
|
|
2502
|
-
"({ amount_cents
|
|
2502
|
+
"({ amount_cents?, currency?, description, kind, return_path?, order? }) => Promise<{ id, status, order }> // kind is REQUIRED: \"physical\" | \"service\" | \"digital\" — what is sold; a digital charge is refused in an iOS/Android build (DIGITAL_SALE_NEEDS_STORE_BILLING); amount_cents (minor units) is REQUIRED without order; order: { table_id, record_id } — the order row this pays for, in a table with a payment-status column; the SERVER marks it paid when the payment settles, so never write \"paid\" yourself (refused: ORDER_NOT_FOUND, ORDER_NOT_PAYABLE, ORDER_ALREADY_PAID; ORDER_PAYMENT_IN_PROGRESS is retryable while another checkout for the order is open). The orders table also REQUIRES an order-total column (orderTotal; without one: ORDER_NOT_PAYABLE) and the server charges the total stored on the order: create the order with its total, then pass order and omit amount_cents (if sent it must equal the total; refused, not retryable: ORDER_TOTAL_INVALID when the total is empty, zero, negative or not whole, ORDER_AMOUNT_MISMATCH when amount_cents differs). The total is write-once but written by the order's creator, so compute it from prices the buyer cannot change; host opens hosted Checkout; rejects with PaymentError { code, message, retryable } — render the message when retryable is false, never \"try again\"",
|
|
2503
2503
|
getPayment:
|
|
2504
2504
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // order: { table_id, record_id } | null — read it after returning from Checkout",
|
|
2505
2505
|
requestGuestPayment:
|
|
2506
|
-
"({ amount_cents
|
|
2506
|
+
"({ amount_cents?, currency?, description, return_path?, order }) => Promise<{ id, status, order }> // a visitor who is NOT signed in buys physical goods (no kind). The orders table needs a payment-status AND an order-total column, as for requestPayment: create the order with its total and omit amount_cents (if sent it must equal the total). order is REQUIRED: create the order row first with useDatastoreMutation().create (the maker lets everyone add rows to the orders table and nobody read them; collect the shipping address and contact there), then pay for it within 15 minutes — only the visitor who created it can. Needs the payments.charge:guest scope too. The orders table needs a buyerEmail column the order is created with: the platform emails the order confirmation there, and an order without a valid address is refused with BUYER_EMAIL_INVALID (not retryable). The host runs a security check and opens hosted Checkout. Refused: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable), CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), NOT_FOUND where the shop does not offer guest checkout, plus the requestPayment refusals",
|
|
2507
2507
|
getGuestPayment:
|
|
2508
2508
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // a guest's status read; the host holds the guest's one-time credential, so pass only the id",
|
|
2509
2509
|
},
|
|
@@ -4370,7 +4370,7 @@ const MANIFEST_SCHEMA = {
|
|
|
4370
4370
|
type: "object",
|
|
4371
4371
|
required: false,
|
|
4372
4372
|
description:
|
|
4373
|
-
"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): 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. 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.",
|
|
4373
|
+
"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: true` 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 order's creator writes it on create and a later update is ignored; `requestPayment({ order })` then charges that stored total, so omit `amount_cents`. It fixes the total, not the price: compute it from prices the buyer cannot change. `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.",
|
|
4374
4374
|
},
|
|
4375
4375
|
translations: {
|
|
4376
4376
|
type: "object",
|
|
@@ -7154,7 +7154,15 @@ const CONTRACT = deepFreeze({
|
|
|
7154
7154
|
// 1.283.0: additive (sc-17852) — `<Popover onDismiss>` and the children's
|
|
7155
7155
|
// `close(then)` run once the closed popover has left the screen, so a
|
|
7156
7156
|
// dialog it opens presents on iOS.
|
|
7157
|
-
|
|
7157
|
+
// 1.284.0 (sc-15916): a `paymentStatus` table requires an `orderTotal: true`
|
|
7158
|
+
// column (an immutable NUMBER in minor units); a charge with `order` bills
|
|
7159
|
+
// that total, so `amount_cents` is optional with `order`. Breaking for an
|
|
7160
|
+
// order charge on a table without one (ORDER_NOT_PAYABLE). Two new
|
|
7161
|
+
// PaymentError codes and the `order-total-updated` warning.
|
|
7162
|
+
// 1.285.0: additive (sc-18008) — a `datastoreTemplate` column may declare
|
|
7163
|
+
// `buyerEmail: true` (an immutable STRING); the platform emails the order
|
|
7164
|
+
// confirmation there. New PaymentError code BUYER_EMAIL_INVALID.
|
|
7165
|
+
version: "1.285.0",
|
|
7158
7166
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7159
7167
|
hooks: HOOKS,
|
|
7160
7168
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -7293,6 +7293,7 @@ const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
|
7293
7293
|
"AUTH_REQUIRED",
|
|
7294
7294
|
"AMOUNT_TOO_LARGE",
|
|
7295
7295
|
"BUSINESS_IDENTITY_REQUIRED",
|
|
7296
|
+
"BUYER_EMAIL_INVALID",
|
|
7296
7297
|
"CHARGE_KIND_NOT_ENABLED",
|
|
7297
7298
|
"CHARGE_KIND_REQUIRED",
|
|
7298
7299
|
"CONNECT_NOT_READY",
|
|
@@ -7302,7 +7303,9 @@ const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
|
7302
7303
|
"NOT_FOUND",
|
|
7303
7304
|
"ORDER_ALREADY_PAID",
|
|
7304
7305
|
"ORDER_NOT_FOUND",
|
|
7306
|
+
"ORDER_AMOUNT_MISMATCH",
|
|
7305
7307
|
"ORDER_NOT_PAYABLE",
|
|
7308
|
+
"ORDER_TOTAL_INVALID",
|
|
7306
7309
|
"PAYMENTS_DISABLED",
|
|
7307
7310
|
"PAYMENTS_SCOPE_NOT_GRANTED",
|
|
7308
7311
|
"PAYMENTS_UNAVAILABLE",
|
|
@@ -7334,6 +7337,12 @@ const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
|
7334
7337
|
* build: store policy requires store billing
|
|
7335
7338
|
* - "ORDER_NOT_FOUND" / "ORDER_NOT_PAYABLE" / "ORDER_ALREADY_PAID" — the
|
|
7336
7339
|
* `order` is not one this user can pay for
|
|
7340
|
+
* - "ORDER_TOTAL_INVALID" — the order's total is empty, zero, negative
|
|
7341
|
+
* or not a whole number of minor units
|
|
7342
|
+
* - "ORDER_AMOUNT_MISMATCH" — `amount_cents` was sent and differs from
|
|
7343
|
+
* the order's total; omit it
|
|
7344
|
+
* - "BUYER_EMAIL_INVALID" — a guest's order has no valid email in
|
|
7345
|
+
* its buyer-email column; the receipt needs one
|
|
7337
7346
|
* - "ORDER_PAYMENT_IN_PROGRESS" — another checkout for the order is open
|
|
7338
7347
|
* (retryable: it clears when that one ends)
|
|
7339
7348
|
* - "ALREADY_OWNED" — `useAccessPlans().purchase` for a plan the
|
package/dist/index.d.ts
CHANGED
|
@@ -281,6 +281,31 @@ export interface WidgetDatastoreTemplateColumn {
|
|
|
281
281
|
* `MANY_TO_MANY` relation, whose links live outside the row.
|
|
282
282
|
*/
|
|
283
283
|
immutable?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* STRING or BOOL only, at most one per table: the order's payment status.
|
|
286
|
+
* The table also needs an `orderTotal` column. A settled
|
|
287
|
+
* `requestPayment({ order })` writes it; every client value for it is
|
|
288
|
+
* ignored, so a buyer cannot mark their own order paid.
|
|
289
|
+
*/
|
|
290
|
+
paymentStatus?: boolean;
|
|
291
|
+
/**
|
|
292
|
+
* NUMBER only, required once in every table with a `paymentStatus` column
|
|
293
|
+
* (and only there), and it must be `immutable: true` (not encrypted,
|
|
294
|
+
* `latestVia` or `copyOf`). The order's total in integer minor units (339 kr
|
|
295
|
+
* is 33900) of the workspace's charge currency. The order's creator sets it
|
|
296
|
+
* on create, and `requestPayment({ order })` charges it, so omit
|
|
297
|
+
* `amount_cents`. Compute it from prices the buyer cannot change.
|
|
298
|
+
*/
|
|
299
|
+
orderTotal?: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* STRING only, at most one per table, in a table with a `paymentStatus`
|
|
302
|
+
* column, and it must be `immutable: true` (not encrypted, `latestVia` or
|
|
303
|
+
* `copyOf`). The buyer's email address: when a charge marks the order paid
|
|
304
|
+
* the platform emails an order confirmation there (a signed-in buyer gets it
|
|
305
|
+
* at their account's address), and a refund notice after a full refund. A
|
|
306
|
+
* guest charge needs a valid address in it.
|
|
307
|
+
*/
|
|
308
|
+
buyerEmail?: boolean;
|
|
284
309
|
/**
|
|
285
310
|
* ONE_TO_ONE / ONE_TO_MANY RELATION only, with `onDelete` left at
|
|
286
311
|
* `SET_NULL`: the server keeps this column pointing at the newest row of its
|
|
@@ -1614,7 +1639,12 @@ export function useWidgetInput(inputName: string): unknown;
|
|
|
1614
1639
|
* currency's minor unit; the app user confirms it in hosted Checkout.
|
|
1615
1640
|
*/
|
|
1616
1641
|
export interface PaymentRequest {
|
|
1617
|
-
|
|
1642
|
+
/**
|
|
1643
|
+
* Required without `order`. With `order` the server charges the order's
|
|
1644
|
+
* stored total: omit this, or send the same value (a different one is
|
|
1645
|
+
* refused with ORDER_AMOUNT_MISMATCH).
|
|
1646
|
+
*/
|
|
1647
|
+
amount_cents?: number;
|
|
1618
1648
|
currency?: string;
|
|
1619
1649
|
description: string;
|
|
1620
1650
|
/**
|
|
@@ -1636,6 +1666,10 @@ export interface PaymentRequest {
|
|
|
1636
1666
|
* column, so never write "paid" yourself; the platform ignores it anyway.
|
|
1637
1667
|
* Refused with ORDER_NOT_FOUND, ORDER_NOT_PAYABLE or ORDER_ALREADY_PAID, and
|
|
1638
1668
|
* with the retryable ORDER_PAYMENT_IN_PROGRESS while another checkout is open.
|
|
1669
|
+
* The table also needs an order-total column (ORDER_NOT_PAYABLE without
|
|
1670
|
+
* one), and the charge is the order's stored total: ORDER_TOTAL_INVALID when
|
|
1671
|
+
* it is empty, zero, negative or not whole, and ORDER_AMOUNT_MISMATCH when
|
|
1672
|
+
* `amount_cents` differs from it.
|
|
1639
1673
|
*/
|
|
1640
1674
|
order?: PaymentOrder;
|
|
1641
1675
|
}
|
|
@@ -1659,10 +1693,12 @@ export interface PaymentResult {
|
|
|
1659
1693
|
|
|
1660
1694
|
/**
|
|
1661
1695
|
* A visitor who is not signed in paying for physical goods. There is no
|
|
1662
|
-
* `kind`: guest checkout sells physical goods only.
|
|
1696
|
+
* `kind`: guest checkout sells physical goods only. The order's table needs a
|
|
1697
|
+
* `buyerEmail` column holding a valid address (BUYER_EMAIL_INVALID otherwise).
|
|
1663
1698
|
*/
|
|
1664
1699
|
export interface GuestPaymentRequest {
|
|
1665
|
-
|
|
1700
|
+
/** Optional: the server charges the order's stored total, as for `requestPayment`. */
|
|
1701
|
+
amount_cents?: number;
|
|
1666
1702
|
currency?: string;
|
|
1667
1703
|
description: string;
|
|
1668
1704
|
return_path?: string;
|
|
@@ -1807,6 +1843,9 @@ export class PaymentError extends Error {
|
|
|
1807
1843
|
| "ORDER_NOT_FOUND"
|
|
1808
1844
|
| "ORDER_NOT_PAYABLE"
|
|
1809
1845
|
| "ORDER_ALREADY_PAID"
|
|
1846
|
+
| "ORDER_TOTAL_INVALID"
|
|
1847
|
+
| "ORDER_AMOUNT_MISMATCH"
|
|
1848
|
+
| "BUYER_EMAIL_INVALID"
|
|
1810
1849
|
| "ORDER_PAYMENT_IN_PROGRESS"
|
|
1811
1850
|
| "ALREADY_OWNED"
|
|
1812
1851
|
| "PURCHASE_IN_PROGRESS"
|
package/dist/linter.cjs
CHANGED
|
@@ -1678,8 +1678,8 @@ const _PAID_WRITE_RES = [
|
|
|
1678
1678
|
/:\s*(['"`])paid\1/gi,
|
|
1679
1679
|
];
|
|
1680
1680
|
|
|
1681
|
-
/** Local names the widget's
|
|
1682
|
-
function _writeCallees(code) {
|
|
1681
|
+
/** Local names the widget's `methods` calls go through, and named mutation objects. */
|
|
1682
|
+
function _writeCallees(code, methods) {
|
|
1683
1683
|
const verbs = [];
|
|
1684
1684
|
const objects = [];
|
|
1685
1685
|
for (const call of _mutationHookCalls(code)) {
|
|
@@ -1689,12 +1689,25 @@ function _writeCallees(code) {
|
|
|
1689
1689
|
}
|
|
1690
1690
|
for (const entry of call.destructured.split(",")) {
|
|
1691
1691
|
const [key, local] = entry.split(":").map((part) => part.trim());
|
|
1692
|
-
if (
|
|
1692
|
+
if (methods.has(key)) verbs.push(local || key);
|
|
1693
1693
|
}
|
|
1694
1694
|
}
|
|
1695
1695
|
return { verbs, objects };
|
|
1696
1696
|
}
|
|
1697
1697
|
|
|
1698
|
+
/** Matches the widget's own mutation calls of `methods` up to their `(`, or null when it makes none. */
|
|
1699
|
+
function _mutationCallRe(masked, methods) {
|
|
1700
|
+
const { verbs, objects } = _writeCallees(masked, methods);
|
|
1701
|
+
const escape = (name) => name.replace(/\$/g, "\\$");
|
|
1702
|
+
const methodAlt = [...methods].join("|");
|
|
1703
|
+
const callees = [
|
|
1704
|
+
...verbs.map((v) => `(?<![\\w$.])${escape(v)}`),
|
|
1705
|
+
...objects.map((o) => `(?<![\\w$])${escape(o)}\\s*\\.\\s*(?:${methodAlt})`),
|
|
1706
|
+
];
|
|
1707
|
+
if (callees.length === 0) return null;
|
|
1708
|
+
return new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g");
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1698
1711
|
/** Index of the parenthesis closing the one opening at `open`, or -1. */
|
|
1699
1712
|
function _closingParen(masked, open) {
|
|
1700
1713
|
let depth = 0;
|
|
@@ -1710,19 +1723,14 @@ function _closingParen(masked, open) {
|
|
|
1710
1723
|
function _paymentStatusWrittenRules(source) {
|
|
1711
1724
|
const masked = _stripNonCode(source);
|
|
1712
1725
|
if (!PAYMENT_CHARGE_CALL_RE.test(masked)) return [];
|
|
1713
|
-
const
|
|
1714
|
-
|
|
1715
|
-
const callees = [
|
|
1716
|
-
...verbs.map((v) => `(?<![\\w$.])${escape(v)}`),
|
|
1717
|
-
...objects.map((o) => `(?<![\\w$])${escape(o)}\\s*\\.\\s*(?:create|update)`),
|
|
1718
|
-
];
|
|
1719
|
-
if (callees.length === 0) return [];
|
|
1726
|
+
const writeCall = _mutationCallRe(masked, _WRITE_VERBS);
|
|
1727
|
+
if (!writeCall) return [];
|
|
1720
1728
|
const kept = _stripNonCode(source, { keepStrings: true });
|
|
1721
1729
|
const sourceLines = source.split(/\r?\n/);
|
|
1722
1730
|
const lineAt = _lineCounter(masked);
|
|
1723
1731
|
const findings = [];
|
|
1724
1732
|
const reported = new Set();
|
|
1725
|
-
for (const call of masked.matchAll(
|
|
1733
|
+
for (const call of masked.matchAll(writeCall)) {
|
|
1726
1734
|
const open = call.index + call[0].length - 1;
|
|
1727
1735
|
const close = _closingParen(masked, open);
|
|
1728
1736
|
if (close === -1) continue;
|
|
@@ -1749,6 +1757,46 @@ function _paymentStatusWrittenRules(source) {
|
|
|
1749
1757
|
return findings;
|
|
1750
1758
|
}
|
|
1751
1759
|
|
|
1760
|
+
// sc-15916 — order-total-updated.
|
|
1761
|
+
//
|
|
1762
|
+
// An order-total column is write-once and a charge with `order` bills the
|
|
1763
|
+
// total stored on the order. An update setting it is silently ignored, so the
|
|
1764
|
+
// widget believes it changed the price and the buyer is charged the old one.
|
|
1765
|
+
// A warning: the scan matches the key's name, not the workspace's column.
|
|
1766
|
+
const _UPDATE_VERB = new Set(["update"]);
|
|
1767
|
+
const _ORDER_TOTAL_KEY_RE = /(?<![\w$])(['"]?)(?:order_?)?total(?:_?(?:cents|minor))?\1\s*:/i;
|
|
1768
|
+
|
|
1769
|
+
function _orderTotalUpdatedRules(source) {
|
|
1770
|
+
const masked = _stripNonCode(source);
|
|
1771
|
+
if (!PAYMENT_CHARGE_CALL_RE.test(masked)) return [];
|
|
1772
|
+
const updateCall = _mutationCallRe(masked, _UPDATE_VERB);
|
|
1773
|
+
if (!updateCall) return [];
|
|
1774
|
+
const kept = _stripNonCode(source, { keepStrings: true });
|
|
1775
|
+
const sourceLines = source.split(/\r?\n/);
|
|
1776
|
+
const lineAt = _lineCounter(masked);
|
|
1777
|
+
const findings = [];
|
|
1778
|
+
for (const call of masked.matchAll(updateCall)) {
|
|
1779
|
+
const open = call.index + call[0].length - 1;
|
|
1780
|
+
const close = _closingParen(masked, open);
|
|
1781
|
+
if (close === -1) continue;
|
|
1782
|
+
const hit = _ORDER_TOTAL_KEY_RE.exec(kept.slice(open, close));
|
|
1783
|
+
if (!hit) continue;
|
|
1784
|
+
const line = lineAt(open + hit.index);
|
|
1785
|
+
findings.push({
|
|
1786
|
+
rule: "order-total-updated",
|
|
1787
|
+
severity: "warning",
|
|
1788
|
+
label:
|
|
1789
|
+
`the order total is write-once, so this update is ignored and the ` +
|
|
1790
|
+
`charge bills the stored total. Set the total when you create the ` +
|
|
1791
|
+
`order, then pass order: { table_id, record_id } to requestPayment ` +
|
|
1792
|
+
`and omit amount_cents.`,
|
|
1793
|
+
line,
|
|
1794
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
return findings;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1752
1800
|
// sc-4686 — no-hardcoded-currency-label.
|
|
1753
1801
|
//
|
|
1754
1802
|
// The charge is safe once `currency` is omitted, but the DISPLAY is not: a "kr"
|
|
@@ -4779,6 +4827,7 @@ function lintSource(source, options) {
|
|
|
4779
4827
|
findings.push(..._paymentCurrencyRules(source));
|
|
4780
4828
|
findings.push(..._paymentKindRules(source));
|
|
4781
4829
|
findings.push(..._paymentStatusWrittenRules(source));
|
|
4830
|
+
findings.push(..._orderTotalUpdatedRules(source));
|
|
4782
4831
|
findings.push(..._hardcodedCurrencyLabelRules(source));
|
|
4783
4832
|
findings.push(..._fixedDateFormatRules(source));
|
|
4784
4833
|
findings.push(..._paymentErrorHandlingRules(source));
|
package/dist/linter.js
CHANGED
|
@@ -1673,8 +1673,8 @@ const _PAID_WRITE_RES = [
|
|
|
1673
1673
|
/:\s*(['"`])paid\1/gi,
|
|
1674
1674
|
];
|
|
1675
1675
|
|
|
1676
|
-
/** Local names the widget's
|
|
1677
|
-
function _writeCallees(code) {
|
|
1676
|
+
/** Local names the widget's `methods` calls go through, and named mutation objects. */
|
|
1677
|
+
function _writeCallees(code, methods) {
|
|
1678
1678
|
const verbs = [];
|
|
1679
1679
|
const objects = [];
|
|
1680
1680
|
for (const call of _mutationHookCalls(code)) {
|
|
@@ -1684,12 +1684,25 @@ function _writeCallees(code) {
|
|
|
1684
1684
|
}
|
|
1685
1685
|
for (const entry of call.destructured.split(",")) {
|
|
1686
1686
|
const [key, local] = entry.split(":").map((part) => part.trim());
|
|
1687
|
-
if (
|
|
1687
|
+
if (methods.has(key)) verbs.push(local || key);
|
|
1688
1688
|
}
|
|
1689
1689
|
}
|
|
1690
1690
|
return { verbs, objects };
|
|
1691
1691
|
}
|
|
1692
1692
|
|
|
1693
|
+
/** Matches the widget's own mutation calls of `methods` up to their `(`, or null when it makes none. */
|
|
1694
|
+
function _mutationCallRe(masked, methods) {
|
|
1695
|
+
const { verbs, objects } = _writeCallees(masked, methods);
|
|
1696
|
+
const escape = (name) => name.replace(/\$/g, "\\$");
|
|
1697
|
+
const methodAlt = [...methods].join("|");
|
|
1698
|
+
const callees = [
|
|
1699
|
+
...verbs.map((v) => `(?<![\\w$.])${escape(v)}`),
|
|
1700
|
+
...objects.map((o) => `(?<![\\w$])${escape(o)}\\s*\\.\\s*(?:${methodAlt})`),
|
|
1701
|
+
];
|
|
1702
|
+
if (callees.length === 0) return null;
|
|
1703
|
+
return new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g");
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1693
1706
|
/** Index of the parenthesis closing the one opening at `open`, or -1. */
|
|
1694
1707
|
function _closingParen(masked, open) {
|
|
1695
1708
|
let depth = 0;
|
|
@@ -1705,19 +1718,14 @@ function _closingParen(masked, open) {
|
|
|
1705
1718
|
function _paymentStatusWrittenRules(source) {
|
|
1706
1719
|
const masked = _stripNonCode(source);
|
|
1707
1720
|
if (!PAYMENT_CHARGE_CALL_RE.test(masked)) return [];
|
|
1708
|
-
const
|
|
1709
|
-
|
|
1710
|
-
const callees = [
|
|
1711
|
-
...verbs.map((v) => `(?<![\\w$.])${escape(v)}`),
|
|
1712
|
-
...objects.map((o) => `(?<![\\w$])${escape(o)}\\s*\\.\\s*(?:create|update)`),
|
|
1713
|
-
];
|
|
1714
|
-
if (callees.length === 0) return [];
|
|
1721
|
+
const writeCall = _mutationCallRe(masked, _WRITE_VERBS);
|
|
1722
|
+
if (!writeCall) return [];
|
|
1715
1723
|
const kept = _stripNonCode(source, { keepStrings: true });
|
|
1716
1724
|
const sourceLines = source.split(/\r?\n/);
|
|
1717
1725
|
const lineAt = _lineCounter(masked);
|
|
1718
1726
|
const findings = [];
|
|
1719
1727
|
const reported = new Set();
|
|
1720
|
-
for (const call of masked.matchAll(
|
|
1728
|
+
for (const call of masked.matchAll(writeCall)) {
|
|
1721
1729
|
const open = call.index + call[0].length - 1;
|
|
1722
1730
|
const close = _closingParen(masked, open);
|
|
1723
1731
|
if (close === -1) continue;
|
|
@@ -1744,6 +1752,46 @@ function _paymentStatusWrittenRules(source) {
|
|
|
1744
1752
|
return findings;
|
|
1745
1753
|
}
|
|
1746
1754
|
|
|
1755
|
+
// sc-15916 — order-total-updated.
|
|
1756
|
+
//
|
|
1757
|
+
// An order-total column is write-once and a charge with `order` bills the
|
|
1758
|
+
// total stored on the order. An update setting it is silently ignored, so the
|
|
1759
|
+
// widget believes it changed the price and the buyer is charged the old one.
|
|
1760
|
+
// A warning: the scan matches the key's name, not the workspace's column.
|
|
1761
|
+
const _UPDATE_VERB = new Set(["update"]);
|
|
1762
|
+
const _ORDER_TOTAL_KEY_RE = /(?<![\w$])(['"]?)(?:order_?)?total(?:_?(?:cents|minor))?\1\s*:/i;
|
|
1763
|
+
|
|
1764
|
+
function _orderTotalUpdatedRules(source) {
|
|
1765
|
+
const masked = _stripNonCode(source);
|
|
1766
|
+
if (!PAYMENT_CHARGE_CALL_RE.test(masked)) return [];
|
|
1767
|
+
const updateCall = _mutationCallRe(masked, _UPDATE_VERB);
|
|
1768
|
+
if (!updateCall) return [];
|
|
1769
|
+
const kept = _stripNonCode(source, { keepStrings: true });
|
|
1770
|
+
const sourceLines = source.split(/\r?\n/);
|
|
1771
|
+
const lineAt = _lineCounter(masked);
|
|
1772
|
+
const findings = [];
|
|
1773
|
+
for (const call of masked.matchAll(updateCall)) {
|
|
1774
|
+
const open = call.index + call[0].length - 1;
|
|
1775
|
+
const close = _closingParen(masked, open);
|
|
1776
|
+
if (close === -1) continue;
|
|
1777
|
+
const hit = _ORDER_TOTAL_KEY_RE.exec(kept.slice(open, close));
|
|
1778
|
+
if (!hit) continue;
|
|
1779
|
+
const line = lineAt(open + hit.index);
|
|
1780
|
+
findings.push({
|
|
1781
|
+
rule: "order-total-updated",
|
|
1782
|
+
severity: "warning",
|
|
1783
|
+
label:
|
|
1784
|
+
`the order total is write-once, so this update is ignored and the ` +
|
|
1785
|
+
`charge bills the stored total. Set the total when you create the ` +
|
|
1786
|
+
`order, then pass order: { table_id, record_id } to requestPayment ` +
|
|
1787
|
+
`and omit amount_cents.`,
|
|
1788
|
+
line,
|
|
1789
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
return findings;
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1747
1795
|
// sc-4686 — no-hardcoded-currency-label.
|
|
1748
1796
|
//
|
|
1749
1797
|
// The charge is safe once `currency` is omitted, but the DISPLAY is not: a "kr"
|
|
@@ -4774,6 +4822,7 @@ export function lintSource(source, options) {
|
|
|
4774
4822
|
findings.push(..._paymentCurrencyRules(source));
|
|
4775
4823
|
findings.push(..._paymentKindRules(source));
|
|
4776
4824
|
findings.push(..._paymentStatusWrittenRules(source));
|
|
4825
|
+
findings.push(..._orderTotalUpdatedRules(source));
|
|
4777
4826
|
findings.push(..._hardcodedCurrencyLabelRules(source));
|
|
4778
4827
|
findings.push(..._fixedDateFormatRules(source));
|
|
4779
4828
|
findings.push(..._paymentErrorHandlingRules(source));
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -2499,11 +2499,11 @@ const HOOKS = [
|
|
|
2499
2499
|
signature: "usePayments()",
|
|
2500
2500
|
returnShape: {
|
|
2501
2501
|
requestPayment:
|
|
2502
|
-
"({ amount_cents
|
|
2502
|
+
"({ amount_cents?, currency?, description, kind, return_path?, order? }) => Promise<{ id, status, order }> // kind is REQUIRED: \"physical\" | \"service\" | \"digital\" — what is sold; a digital charge is refused in an iOS/Android build (DIGITAL_SALE_NEEDS_STORE_BILLING); amount_cents (minor units) is REQUIRED without order; order: { table_id, record_id } — the order row this pays for, in a table with a payment-status column; the SERVER marks it paid when the payment settles, so never write \"paid\" yourself (refused: ORDER_NOT_FOUND, ORDER_NOT_PAYABLE, ORDER_ALREADY_PAID; ORDER_PAYMENT_IN_PROGRESS is retryable while another checkout for the order is open). The orders table also REQUIRES an order-total column (orderTotal; without one: ORDER_NOT_PAYABLE) and the server charges the total stored on the order: create the order with its total, then pass order and omit amount_cents (if sent it must equal the total; refused, not retryable: ORDER_TOTAL_INVALID when the total is empty, zero, negative or not whole, ORDER_AMOUNT_MISMATCH when amount_cents differs). The total is write-once but written by the order's creator, so compute it from prices the buyer cannot change; host opens hosted Checkout; rejects with PaymentError { code, message, retryable } — render the message when retryable is false, never \"try again\"",
|
|
2503
2503
|
getPayment:
|
|
2504
2504
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // order: { table_id, record_id } | null — read it after returning from Checkout",
|
|
2505
2505
|
requestGuestPayment:
|
|
2506
|
-
"({ amount_cents
|
|
2506
|
+
"({ amount_cents?, currency?, description, return_path?, order }) => Promise<{ id, status, order }> // a visitor who is NOT signed in buys physical goods (no kind). The orders table needs a payment-status AND an order-total column, as for requestPayment: create the order with its total and omit amount_cents (if sent it must equal the total). order is REQUIRED: create the order row first with useDatastoreMutation().create (the maker lets everyone add rows to the orders table and nobody read them; collect the shipping address and contact there), then pay for it within 15 minutes — only the visitor who created it can. Needs the payments.charge:guest scope too. The orders table needs a buyerEmail column the order is created with: the platform emails the order confirmation there, and an order without a valid address is refused with BUYER_EMAIL_INVALID (not retryable). The host runs a security check and opens hosted Checkout. Refused: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable), CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), NOT_FOUND where the shop does not offer guest checkout, plus the requestPayment refusals",
|
|
2507
2507
|
getGuestPayment:
|
|
2508
2508
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // a guest's status read; the host holds the guest's one-time credential, so pass only the id",
|
|
2509
2509
|
},
|
|
@@ -4370,7 +4370,7 @@ const MANIFEST_SCHEMA = {
|
|
|
4370
4370
|
type: "object",
|
|
4371
4371
|
required: false,
|
|
4372
4372
|
description:
|
|
4373
|
-
"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): 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. 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.",
|
|
4373
|
+
"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: true` 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 order's creator writes it on create and a later update is ignored; `requestPayment({ order })` then charges that stored total, so omit `amount_cents`. It fixes the total, not the price: compute it from prices the buyer cannot change. `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.",
|
|
4374
4374
|
},
|
|
4375
4375
|
translations: {
|
|
4376
4376
|
type: "object",
|
|
@@ -7154,7 +7154,15 @@ const CONTRACT = deepFreeze({
|
|
|
7154
7154
|
// 1.283.0: additive (sc-17852) — `<Popover onDismiss>` and the children's
|
|
7155
7155
|
// `close(then)` run once the closed popover has left the screen, so a
|
|
7156
7156
|
// dialog it opens presents on iOS.
|
|
7157
|
-
|
|
7157
|
+
// 1.284.0 (sc-15916): a `paymentStatus` table requires an `orderTotal: true`
|
|
7158
|
+
// column (an immutable NUMBER in minor units); a charge with `order` bills
|
|
7159
|
+
// that total, so `amount_cents` is optional with `order`. Breaking for an
|
|
7160
|
+
// order charge on a table without one (ORDER_NOT_PAYABLE). Two new
|
|
7161
|
+
// PaymentError codes and the `order-total-updated` warning.
|
|
7162
|
+
// 1.285.0: additive (sc-18008) — a `datastoreTemplate` column may declare
|
|
7163
|
+
// `buyerEmail: true` (an immutable STRING); the platform emails the order
|
|
7164
|
+
// confirmation there. New PaymentError code BUYER_EMAIL_INVALID.
|
|
7165
|
+
version: "1.285.0",
|
|
7158
7166
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7159
7167
|
hooks: HOOKS,
|
|
7160
7168
|
primitives: PRIMITIVES,
|